Problem 059

XOR decryption: sum of ASCII values of the original text. Key is three lowercase letters; plaintext contains " the ".

Answer129448
Output129448
StatusPASS
Native helperno
Runtime0 ms
Peak memory1120 KB
Time complexityO(n^4) (estimated)
Space complexityO(1) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^4)O(n * k)
Space complexityO(1)O(n)
ApproachFlow solutionKey search and XOR decryption
VerdictUnknown

Flow source

# Project Euler 059
# XOR decryption: sum of ASCII values of the original text.
# Key is three lowercase letters; plaintext contains " the ".

extern {
    function fopen(path: string, mode: string) -> ptr<void>
    function fgetc(f: ptr<void>) -> i32
    function fclose(f: ptr<void>) -> i32
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

function main() -> i32 {
    let f: ptr<void> = fopen("data/p059.txt", "r")
    if f == null {
        printf("failed to read data/p059.txt\n")
        return 1
    }
    let data: ptr<i32> = calloc(2000, 4)
    let plain: ptr<i32> = calloc(2000, 4)
    if data == null || plain == null { return 1 }

    let mut n: i32 = 0
    let mut c: i32 = fgetc(f)
    while c >= 0 {
        while c >= 0 && (c < 48 || c > 57) {
            c = fgetc(f)
        }
        if c < 0 { break }
        let mut v: i32 = 0
        while c >= 48 && c <= 57 {
            v = v * 10 + (c - 48)
            c = fgetc(f)
        }
        data[n] = v
        n = n + 1
    }
    fclose(f)

    let mut best_sum: i64 = 0
    let mut found: bool = false
    let mut k0: i32 = 97
    while k0 <= 122 {
        let mut k1: i32 = 97
        while k1 <= 122 {
            let mut k2: i32 = 97
            while k2 <= 122 {
                let mut ok: bool = true
                let mut sum: i64 = 0
                let mut i: i32 = 0
                while i < n {
                    let mut key: i32 = k0
                    if i % 3 == 1 { key = k1 }
                    if i % 3 == 2 { key = k2 }
                    let ch: i32 = data[i] ^ key
                    if ch < 32 || ch > 126 {
                        ok = false
                        break
                    }
                    plain[i] = ch
                    sum = sum + (ch as i64)
                    i = i + 1
                }
                if ok {
                    # search for " the "
                    let mut has_the: bool = false
                    i = 0
                    while i + 4 < n {
                        if plain[i] == 32 && plain[i + 1] == 116 && plain[i + 2] == 104 && plain[i + 3] == 101 && plain[i + 4] == 32 {
                            has_the = true
                            break
                        }
                        i = i + 1
                    }
                    if has_the {
                        best_sum = sum
                        found = true
                        # take first/match; should be unique
                        k2 = 123
                        k1 = 123
                        k0 = 123
                        break
                    }
                }
                k2 = k2 + 1
            }
            k1 = k1 + 1
        }
        k0 = k0 + 1
    }
    if !found {
        printf("0\n")
    } else {
        printf("%lld\n", best_sum)
    }
    free(plain)
    free(data)
    return 0
}

Generated C

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Flow runtime helpers */
typedef struct flow_temp_node { struct flow_temp_node* next; } flow_temp_node;
static flow_temp_node* flow_temp_head = NULL;
static int flow_temp_atexit_set = 0;
__attribute__((unused)) static void flow_temp_free_all(void) {
    while (flow_temp_head) {
        flow_temp_node* n = flow_temp_head;
        flow_temp_head = n->next;
        free(n);
    }
}
__attribute__((unused)) static void* flow_temp_alloc(size_t nbytes) {
    flow_temp_node* node = (flow_temp_node*)malloc(sizeof(flow_temp_node) + nbytes);
    if (!node) return NULL;
    node->next = flow_temp_head;
    flow_temp_head = node;
    if (!flow_temp_atexit_set) {
        flow_temp_atexit_set = 1;
        atexit(flow_temp_free_all);
    }
    return (void*)(node + 1);
}
#ifndef FLOW_DIAG
#define FLOW_DIAG(msg) fprintf(stderr, "%s", (msg))
#endif
#ifndef FLOW_LOG
#define FLOW_LOG(fmt, ...) printf(fmt, __VA_ARGS__)
#endif
#ifndef FLOW_LOG_EMPTY
#define FLOW_LOG_EMPTY(fmt) printf(fmt)
#endif
static char* flow_strcat(const char* a, const char* b) {
    size_t la = strlen(a ? a : ""), lb = strlen(b ? b : "");
    char* r = (char*)flow_temp_alloc(la + lb + 1);
    if (!r) return NULL;
    if (la) memcpy(r, a, la);
    if (lb) memcpy(r + la, b, lb);
    r[la + lb] = '\0';
    return r;
}

#define __flow_in_arr(arr, val) __extension__ ({ \
    int _found = 0; \
    size_t _n = sizeof(arr)/sizeof((arr)[0]); \
    for (size_t _i = 0; _i < _n; _i++) { \
        if ((arr)[_i] == (val)) { _found = 1; break; } \
    } _found; })

/* Unified fault handler (MISRA #279) — override with -DFLOW_FAULT_HANDLER=fn */
#ifndef FLOW_FAULT_HANDLER
__attribute__((unused)) static inline void flow_fault_handler(const char* msg) {
    fprintf(stderr, "flow: %s\n", msg ? msg : "fault");
    abort();
#if defined(__GNUC__) || defined(__clang__)
    __builtin_unreachable();
#endif
}
#else
#define flow_fault_handler FLOW_FAULT_HANDLER
#endif
#define flow_div_by_zero_handler() flow_fault_handler("division by zero")
#define flow_shift_ub_handler() flow_fault_handler("invalid shift (amount out of range or left-shift of negative)")

#ifndef FLOW_CHECKED_DIV
#define FLOW_CHECKED_DIV(L, R) (((R) != 0) ? ((L) / (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_MOD
#define FLOW_CHECKED_MOD(L, R) (((R) != 0) ? ((L) % (R)) : (flow_div_by_zero_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHL
#define FLOW_CHECKED_SHL(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull)) && ((L) >= 0)) ? ((L) << (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif
#ifndef FLOW_CHECKED_SHR
#define FLOW_CHECKED_SHR(L, R) ((((R) >= 0) && ((unsigned long long)(R) < (sizeof(L) * 8ull))) ? ((L) >> (R)) : (flow_shift_ub_handler(), (L) * 0))
#endif

#include <math.h>

void* _ui_state = NULL;

static inline float i32_to_f32(int32_t v) { return (float)v; }

/* Host stub for @gpu kernels (device codegen replaces this). */
static inline int32_t gpu_thread_id(void) { return 0; }

int32_t main(void);






int32_t main(void) {
    void* f = (void*)(fopen("data/p059.txt", "r"));
    if (f == NULL) {
        printf("failed to read data/p059.txt\n");
        return 1;
    }
    int32_t* data = (int32_t*)(calloc(2000, 4));
    int32_t* plain = (int32_t*)(calloc(2000, 4));
    if ((data == NULL || plain == NULL)) {
        return 1;
    }
    int32_t n = 0;
    int32_t c = fgetc(f);
    while (c >= 0) {
        while ((c >= 0 && (c < 48 || c > 57))) {
            c = fgetc(f);
        }
        if (c < 0) {
            break;
        }
        int32_t v = 0;
        while ((c >= 48 && c <= 57)) {
            v = ((v * 10) + (c - 48));
            c = fgetc(f);
        }
        data[n] = v;
        n = (n + 1);
    }
    fclose(f);
    int64_t best_sum = 0;
    bool found = 0;
    int32_t k0 = 97;
    while (k0 <= 122) {
        int32_t k1 = 97;
        while (k1 <= 122) {
            int32_t k2 = 97;
            while (k2 <= 122) {
                bool ok = 1;
                int64_t sum = 0;
                int32_t i = 0;
                while (i < n) {
                    int32_t key = k0;
                    if (FLOW_CHECKED_MOD((i), (3)) == 1) {
                        key = k1;
                    }
                    if (FLOW_CHECKED_MOD((i), (3)) == 2) {
                        key = k2;
                    }
                    int32_t ch = (data[i] ^ key);
                    if ((ch < 32 || ch > 126)) {
                        ok = 0;
                        break;
                    }
                    plain[i] = ch;
                    sum = (sum + ((int64_t)(ch)));
                    i = (i + 1);
                }
                if (ok) {
                    bool has_the = 0;
                    i = 0;
                    while ((i + 4) < n) {
                        if (((((plain[i] == 32 && plain[(i + 1)] == 116) && plain[(i + 2)] == 104) && plain[(i + 3)] == 101) && plain[(i + 4)] == 32)) {
                            has_the = 1;
                            break;
                        }
                        i = (i + 1);
                    }
                    if (has_the) {
                        best_sum = sum;
                        found = 1;
                        k2 = 123;
                        k1 = 123;
                        k0 = 123;
                        break;
                    }
                }
                k2 = (k2 + 1);
            }
            k1 = (k1 + 1);
        }
        k0 = (k0 + 1);
    }
    if ((!(found))) {
        printf("0\n");
    } else {
        printf("%lld\n", best_sum);
    }
    free(plain);
    free(data);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("data/p059.txt\00") {addr_space = 0 : i32} : !llvm.array<14 x i8>
  llvm.mlir.global internal constant @str_1("r\00") {addr_space = 0 : i32} : !llvm.array<2 x i8>
  llvm.mlir.global internal constant @str_2("failed to read data/p059.txt\n\00") {addr_space = 0 : i32} : !llvm.array<30 x i8>
  llvm.mlir.global internal constant @str_3("0\n\00") {addr_space = 0 : i32} : !llvm.array<3 x i8>
  llvm.mlir.global internal constant @str_4("%lld\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @fopen(!llvm.ptr, !llvm.ptr) -> !llvm.ptr
  func.func private @fgetc(!llvm.ptr) -> i32
  func.func private @fclose(!llvm.ptr) -> i32
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @main() -> i32 {
    %1 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %2 = llvm.mlir.addressof @str_1 : !llvm.ptr
    %0 = func.call @fopen(%1, %2) : (!llvm.ptr, !llvm.ptr) -> !llvm.ptr
    %3 = llvm.mlir.zero : !llvm.ptr
    %4 = llvm.icmp "eq" %0, %3 : !llvm.ptr
    cf.cond_br %4, ^bb0, ^bb1
    ^bb0:
      %5 = llvm.mlir.addressof @str_2 : !llvm.ptr
      %6 = llvm.call @printf(%5) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
      %7 = arith.constant 1 : i32
      func.return %7 : i32
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %9 = arith.constant 2000 : i32
    %10 = arith.constant 4 : i32
    %11 = arith.extsi %9 : i32 to i64
    %12 = arith.extsi %10 : i32 to i64
    %8 = func.call @calloc(%11, %12) : (i64, i64) -> !llvm.ptr
    %14 = arith.constant 2000 : i32
    %15 = arith.constant 4 : i32
    %16 = arith.extsi %14 : i32 to i64
    %17 = arith.extsi %15 : i32 to i64
    %13 = func.call @calloc(%16, %17) : (i64, i64) -> !llvm.ptr
    %18 = llvm.mlir.zero : !llvm.ptr
    %19 = llvm.icmp "eq" %8, %18 : !llvm.ptr
    %20 = scf.if %19 -> (i1) {
      %21 = arith.constant true
      scf.yield %21 : i1
    } else {
      %22 = llvm.mlir.zero : !llvm.ptr
      %23 = llvm.icmp "eq" %13, %22 : !llvm.ptr
      scf.yield %23 : i1
    }
    cf.cond_br %20, ^bb3, ^bb4
    ^bb3:
      %24 = arith.constant 1 : i32
      func.return %24 : i32
    ^bb4:
      cf.br ^bb5
    ^bb5:
    %25 = arith.constant 0 : i32
    %26 = llvm.mlir.constant(1 : i64) : i64
    %27 = llvm.alloca %26 x i32 : (i64) -> !llvm.ptr
    llvm.store %25, %27 : i32, !llvm.ptr
    %28 = func.call @fgetc(%0) : (!llvm.ptr) -> i32
    %29 = llvm.mlir.constant(1 : i64) : i64
    %30 = llvm.alloca %29 x i32 : (i64) -> !llvm.ptr
    llvm.store %28, %30 : i32, !llvm.ptr
    cf.br ^bb6
    ^bb6:
    %31 = llvm.load %30 : !llvm.ptr -> i32
    %32 = arith.constant 0 : i32
    %33 = arith.cmpi sge, %31, %32 : i32
    cf.cond_br %33, ^bb7, ^bb8
    ^bb7:
      cf.br ^bb9
      ^bb9:
      %34 = llvm.load %30 : !llvm.ptr -> i32
      %35 = arith.constant 0 : i32
      %36 = arith.cmpi sge, %34, %35 : i32
      %37 = scf.if %36 -> (i1) {
        %38 = llvm.load %30 : !llvm.ptr -> i32
        %39 = arith.constant 48 : i32
        %40 = arith.cmpi slt, %38, %39 : i32
        %41 = scf.if %40 -> (i1) {
          %42 = arith.constant true
          scf.yield %42 : i1
        } else {
          %43 = llvm.load %30 : !llvm.ptr -> i32
          %44 = arith.constant 57 : i32
          %45 = arith.cmpi sgt, %43, %44 : i32
          scf.yield %45 : i1
        }
        scf.yield %41 : i1
      } else {
        %46 = arith.constant false
        scf.yield %46 : i1
      }
      cf.cond_br %37, ^bb10, ^bb11
      ^bb10:
        %47 = func.call @fgetc(%0) : (!llvm.ptr) -> i32
        llvm.store %47, %30 : i32, !llvm.ptr
        cf.br ^bb9
      ^bb11:
      %48 = llvm.load %30 : !llvm.ptr -> i32
      %49 = arith.constant 0 : i32
      %50 = arith.cmpi slt, %48, %49 : i32
      cf.cond_br %50, ^bb12, ^bb13
      ^bb12:
        cf.br ^bb8
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %51 = arith.constant 0 : i32
      %52 = llvm.mlir.constant(1 : i64) : i64
      %53 = llvm.alloca %52 x i32 : (i64) -> !llvm.ptr
      llvm.store %51, %53 : i32, !llvm.ptr
      cf.br ^bb15
      ^bb15:
      %54 = llvm.load %30 : !llvm.ptr -> i32
      %55 = arith.constant 48 : i32
      %56 = arith.cmpi sge, %54, %55 : i32
      %57 = scf.if %56 -> (i1) {
        %58 = llvm.load %30 : !llvm.ptr -> i32
        %59 = arith.constant 57 : i32
        %60 = arith.cmpi sle, %58, %59 : i32
        scf.yield %60 : i1
      } else {
        %61 = arith.constant false
        scf.yield %61 : i1
      }
      cf.cond_br %57, ^bb16, ^bb17
      ^bb16:
        %62 = llvm.load %53 : !llvm.ptr -> i32
        %63 = arith.constant 10 : i32
        %64 = arith.muli %62, %63 : i32
        %65 = llvm.load %30 : !llvm.ptr -> i32
        %66 = arith.constant 48 : i32
        %67 = arith.subi %65, %66 : i32
        %68 = arith.addi %64, %67 : i32
        llvm.store %68, %53 : i32, !llvm.ptr
        %69 = func.call @fgetc(%0) : (!llvm.ptr) -> i32
        llvm.store %69, %30 : i32, !llvm.ptr
        cf.br ^bb15
      ^bb17:
      %70 = llvm.load %53 : !llvm.ptr -> i32
      %71 = llvm.load %27 : !llvm.ptr -> i32
      %72 = arith.extsi %71 : i32 to i64
      %73 = llvm.getelementptr %8[%72] : (!llvm.ptr, i64) -> !llvm.ptr, i32
      llvm.store %70, %73 : i32, !llvm.ptr
      %74 = llvm.load %27 : !llvm.ptr -> i32
      %75 = arith.constant 1 : i32
      %76 = arith.addi %74, %75 : i32
      llvm.store %76, %27 : i32, !llvm.ptr
      cf.br ^bb6
    ^bb8:
    %77 = func.call @fclose(%0) : (!llvm.ptr) -> i32
    %78 = arith.constant 0 : i32
    %79 = arith.extsi %78 : i32 to i64
    %80 = llvm.mlir.constant(1 : i64) : i64
    %81 = llvm.alloca %80 x i64 : (i64) -> !llvm.ptr
    llvm.store %79, %81 : i64, !llvm.ptr
    %82 = arith.constant 0 : i1
    %83 = llvm.mlir.constant(1 : i64) : i64
    %84 = llvm.alloca %83 x i1 : (i64) -> !llvm.ptr
    llvm.store %82, %84 : i1, !llvm.ptr
    %85 = arith.constant 97 : i32
    %86 = llvm.mlir.constant(1 : i64) : i64
    %87 = llvm.alloca %86 x i32 : (i64) -> !llvm.ptr
    llvm.store %85, %87 : i32, !llvm.ptr
    cf.br ^bb18
    ^bb18:
    %88 = llvm.load %87 : !llvm.ptr -> i32
    %89 = arith.constant 122 : i32
    %90 = arith.cmpi sle, %88, %89 : i32
    cf.cond_br %90, ^bb19, ^bb20
    ^bb19:
      %91 = arith.constant 97 : i32
      %92 = llvm.mlir.constant(1 : i64) : i64
      %93 = llvm.alloca %92 x i32 : (i64) -> !llvm.ptr
      llvm.store %91, %93 : i32, !llvm.ptr
      cf.br ^bb21
      ^bb21:
      %94 = llvm.load %93 : !llvm.ptr -> i32
      %95 = arith.constant 122 : i32
      %96 = arith.cmpi sle, %94, %95 : i32
      cf.cond_br %96, ^bb22, ^bb23
      ^bb22:
        %97 = arith.constant 97 : i32
        %98 = llvm.mlir.constant(1 : i64) : i64
        %99 = llvm.alloca %98 x i32 : (i64) -> !llvm.ptr
        llvm.store %97, %99 : i32, !llvm.ptr
        cf.br ^bb24
        ^bb24:
        %100 = llvm.load %99 : !llvm.ptr -> i32
        %101 = arith.constant 122 : i32
        %102 = arith.cmpi sle, %100, %101 : i32
        cf.cond_br %102, ^bb25, ^bb26
        ^bb25:
          %103 = arith.constant 1 : i1
          %104 = llvm.mlir.constant(1 : i64) : i64
          %105 = llvm.alloca %104 x i1 : (i64) -> !llvm.ptr
          llvm.store %103, %105 : i1, !llvm.ptr
          %106 = arith.constant 0 : i32
          %107 = arith.extsi %106 : i32 to i64
          %108 = llvm.mlir.constant(1 : i64) : i64
          %109 = llvm.alloca %108 x i64 : (i64) -> !llvm.ptr
          llvm.store %107, %109 : i64, !llvm.ptr
          %110 = arith.constant 0 : i32
          %111 = llvm.mlir.constant(1 : i64) : i64
          %112 = llvm.alloca %111 x i32 : (i64) -> !llvm.ptr
          llvm.store %110, %112 : i32, !llvm.ptr
          cf.br ^bb27
          ^bb27:
          %113 = llvm.load %112 : !llvm.ptr -> i32
          %114 = llvm.load %27 : !llvm.ptr -> i32
          %115 = arith.cmpi slt, %113, %114 : i32
          cf.cond_br %115, ^bb28, ^bb29
          ^bb28:
            %116 = llvm.load %87 : !llvm.ptr -> i32
            %117 = llvm.mlir.constant(1 : i64) : i64
            %118 = llvm.alloca %117 x i32 : (i64) -> !llvm.ptr
            llvm.store %116, %118 : i32, !llvm.ptr
            %119 = llvm.load %112 : !llvm.ptr -> i32
            %120 = arith.constant 3 : i32
            %121 = arith.remsi %119, %120 : i32
            %122 = arith.constant 1 : i32
            %123 = arith.cmpi eq, %121, %122 : i32
            cf.cond_br %123, ^bb30, ^bb31
            ^bb30:
              %124 = llvm.load %93 : !llvm.ptr -> i32
              llvm.store %124, %118 : i32, !llvm.ptr
              cf.br ^bb32
            ^bb31:
              cf.br ^bb32
            ^bb32:
            %125 = llvm.load %112 : !llvm.ptr -> i32
            %126 = arith.constant 3 : i32
            %127 = arith.remsi %125, %126 : i32
            %128 = arith.constant 2 : i32
            %129 = arith.cmpi eq, %127, %128 : i32
            cf.cond_br %129, ^bb33, ^bb34
            ^bb33:
              %130 = llvm.load %99 : !llvm.ptr -> i32
              llvm.store %130, %118 : i32, !llvm.ptr
              cf.br ^bb35
            ^bb34:
              cf.br ^bb35
            ^bb35:
            %132 = llvm.load %112 : !llvm.ptr -> i32
            %133 = arith.extsi %132 : i32 to i64
            %134 = llvm.getelementptr %8[%133] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            %131 = llvm.load %134 : !llvm.ptr -> i32
            %135 = llvm.load %118 : !llvm.ptr -> i32
            %136 = arith.xori %131, %135 : i32
            %137 = arith.constant 32 : i32
            %138 = arith.cmpi slt, %136, %137 : i32
            %139 = scf.if %138 -> (i1) {
              %140 = arith.constant true
              scf.yield %140 : i1
            } else {
              %141 = arith.constant 126 : i32
              %142 = arith.cmpi sgt, %136, %141 : i32
              scf.yield %142 : i1
            }
            cf.cond_br %139, ^bb36, ^bb37
            ^bb36:
              %143 = arith.constant 0 : i1
              llvm.store %143, %105 : i1, !llvm.ptr
              cf.br ^bb29
            ^bb37:
              cf.br ^bb38
            ^bb38:
            %144 = llvm.load %112 : !llvm.ptr -> i32
            %145 = arith.extsi %144 : i32 to i64
            %146 = llvm.getelementptr %13[%145] : (!llvm.ptr, i64) -> !llvm.ptr, i32
            llvm.store %136, %146 : i32, !llvm.ptr
            %147 = llvm.load %109 : !llvm.ptr -> i64
            %148 = arith.extsi %136 : i32 to i64
            %149 = arith.addi %147, %148 : i64
            llvm.store %149, %109 : i64, !llvm.ptr
            %150 = llvm.load %112 : !llvm.ptr -> i32
            %151 = arith.constant 1 : i32
            %152 = arith.addi %150, %151 : i32
            llvm.store %152, %112 : i32, !llvm.ptr
            cf.br ^bb27
          ^bb29:
          %153 = llvm.load %105 : !llvm.ptr -> i1
          cf.cond_br %153, ^bb39, ^bb40
          ^bb39:
            %154 = arith.constant 0 : i1
            %155 = llvm.mlir.constant(1 : i64) : i64
            %156 = llvm.alloca %155 x i1 : (i64) -> !llvm.ptr
            llvm.store %154, %156 : i1, !llvm.ptr
            %157 = arith.constant 0 : i32
            llvm.store %157, %112 : i32, !llvm.ptr
            cf.br ^bb42
            ^bb42:
            %158 = llvm.load %112 : !llvm.ptr -> i32
            %159 = arith.constant 4 : i32
            %160 = arith.addi %158, %159 : i32
            %161 = llvm.load %27 : !llvm.ptr -> i32
            %162 = arith.cmpi slt, %160, %161 : i32
            cf.cond_br %162, ^bb43, ^bb44
            ^bb43:
              %164 = llvm.load %112 : !llvm.ptr -> i32
              %165 = arith.extsi %164 : i32 to i64
              %166 = llvm.getelementptr %13[%165] : (!llvm.ptr, i64) -> !llvm.ptr, i32
              %163 = llvm.load %166 : !llvm.ptr -> i32
              %167 = arith.constant 32 : i32
              %168 = arith.cmpi eq, %163, %167 : i32
              %169 = scf.if %168 -> (i1) {
                %171 = llvm.load %112 : !llvm.ptr -> i32
                %172 = arith.constant 1 : i32
                %173 = arith.addi %171, %172 : i32
                %174 = arith.extsi %173 : i32 to i64
                %175 = llvm.getelementptr %13[%174] : (!llvm.ptr, i64) -> !llvm.ptr, i32
                %170 = llvm.load %175 : !llvm.ptr -> i32
                %176 = arith.constant 116 : i32
                %177 = arith.cmpi eq, %170, %176 : i32
                scf.yield %177 : i1
              } else {
                %178 = arith.constant false
                scf.yield %178 : i1
              }
              %179 = scf.if %169 -> (i1) {
                %181 = llvm.load %112 : !llvm.ptr -> i32
                %182 = arith.constant 2 : i32
                %183 = arith.addi %181, %182 : i32
                %184 = arith.extsi %183 : i32 to i64
                %185 = llvm.getelementptr %13[%184] : (!llvm.ptr, i64) -> !llvm.ptr, i32
                %180 = llvm.load %185 : !llvm.ptr -> i32
                %186 = arith.constant 104 : i32
                %187 = arith.cmpi eq, %180, %186 : i32
                scf.yield %187 : i1
              } else {
                %188 = arith.constant false
                scf.yield %188 : i1
              }
              %189 = scf.if %179 -> (i1) {
                %191 = llvm.load %112 : !llvm.ptr -> i32
                %192 = arith.constant 3 : i32
                %193 = arith.addi %191, %192 : i32
                %194 = arith.extsi %193 : i32 to i64
                %195 = llvm.getelementptr %13[%194] : (!llvm.ptr, i64) -> !llvm.ptr, i32
                %190 = llvm.load %195 : !llvm.ptr -> i32
                %196 = arith.constant 101 : i32
                %197 = arith.cmpi eq, %190, %196 : i32
                scf.yield %197 : i1
              } else {
                %198 = arith.constant false
                scf.yield %198 : i1
              }
              %199 = scf.if %189 -> (i1) {
                %201 = llvm.load %112 : !llvm.ptr -> i32
                %202 = arith.constant 4 : i32
                %203 = arith.addi %201, %202 : i32
                %204 = arith.extsi %203 : i32 to i64
                %205 = llvm.getelementptr %13[%204] : (!llvm.ptr, i64) -> !llvm.ptr, i32
                %200 = llvm.load %205 : !llvm.ptr -> i32
                %206 = arith.constant 32 : i32
                %207 = arith.cmpi eq, %200, %206 : i32
                scf.yield %207 : i1
              } else {
                %208 = arith.constant false
                scf.yield %208 : i1
              }
              cf.cond_br %199, ^bb45, ^bb46
              ^bb45:
                %209 = arith.constant 1 : i1
                llvm.store %209, %156 : i1, !llvm.ptr
                cf.br ^bb44
              ^bb46:
                cf.br ^bb47
              ^bb47:
              %210 = llvm.load %112 : !llvm.ptr -> i32
              %211 = arith.constant 1 : i32
              %212 = arith.addi %210, %211 : i32
              llvm.store %212, %112 : i32, !llvm.ptr
              cf.br ^bb42
            ^bb44:
            %213 = llvm.load %156 : !llvm.ptr -> i1
            cf.cond_br %213, ^bb48, ^bb49
            ^bb48:
              %214 = llvm.load %109 : !llvm.ptr -> i64
              llvm.store %214, %81 : i64, !llvm.ptr
              %215 = arith.constant 1 : i1
              llvm.store %215, %84 : i1, !llvm.ptr
              %216 = arith.constant 123 : i32
              llvm.store %216, %99 : i32, !llvm.ptr
              %217 = arith.constant 123 : i32
              llvm.store %217, %93 : i32, !llvm.ptr
              %218 = arith.constant 123 : i32
              llvm.store %218, %87 : i32, !llvm.ptr
              cf.br ^bb26
            ^bb49:
              cf.br ^bb50
            ^bb50:
            cf.br ^bb41
          ^bb40:
            cf.br ^bb41
          ^bb41:
          %219 = llvm.load %99 : !llvm.ptr -> i32
          %220 = arith.constant 1 : i32
          %221 = arith.addi %219, %220 : i32
          llvm.store %221, %99 : i32, !llvm.ptr
          cf.br ^bb24
        ^bb26:
        %222 = llvm.load %93 : !llvm.ptr -> i32
        %223 = arith.constant 1 : i32
        %224 = arith.addi %222, %223 : i32
        llvm.store %224, %93 : i32, !llvm.ptr
        cf.br ^bb21
      ^bb23:
      %225 = llvm.load %87 : !llvm.ptr -> i32
      %226 = arith.constant 1 : i32
      %227 = arith.addi %225, %226 : i32
      llvm.store %227, %87 : i32, !llvm.ptr
      cf.br ^bb18
    ^bb20:
    %228 = llvm.load %84 : !llvm.ptr -> i1
    %230 = arith.constant 1 : i1
    %229 = arith.xori %228, %230 : i1
    cf.cond_br %229, ^bb51, ^bb52
    ^bb51:
      %232 = llvm.mlir.addressof @str_3 : !llvm.ptr
      %233 = llvm.call @printf(%232) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr) -> i32
      cf.br ^bb53
    ^bb52:
      %234 = llvm.mlir.addressof @str_4 : !llvm.ptr
      %235 = llvm.load %81 : !llvm.ptr -> i64
      %236 = llvm.call @printf(%234, %235) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, i64) -> i32
      cf.br ^bb53
    ^bb53:
    func.call @free(%13) : (!llvm.ptr) -> ()
    func.call @free(%8) : (!llvm.ptr) -> ()
    %239 = arith.constant 0 : i32
    func.return %239 : i32
  }
}