Problem 253

Expected maximum number of pieces when randomly clearing a row of 40.

Answer11.492847
Output11.492847
StatusPASS
Native helperno
Runtime430 ms
Peak memory98896 KB
Time complexityO(n^2) (estimated)
Space complexityO(n^2) (estimated)

Performance comparison

MetricOur solutionBest known
Time complexityO(n^2)O(n * s^2)
Space complexityO(n^2)O(s^2)
ApproachFlow solutionMarkov chain or DP over states
VerdictUnknown

Flow source

# Project Euler 253
# Expected maximum number of pieces when randomly clearing a row of 40.

extern {
    function calloc(n: i64, size: i64) -> ptr<void>
    function free(p: ptr<void>) -> void
}

# Represent state as sorted list of segment lengths in a fixed buffer of 40 i8s + length.
# Memo: open addressing hash map key = state bytes + best, value = f64.

function pack_key(seg: ptr<i8>, nseg: i32, best: i32, out: ptr<i8>) -> void {
    for i in 0..nseg {
        out[i] = seg[i]
    }
    for i in nseg..40 {
        out[i] = 0
    }
    out[40] = best as i8
}

function hash_key(key: ptr<i8>) -> i64 {
    let mut h: i64 = 1469598103934665603
    for i in 0..41 {
        h = h ^ (key[i] as i64)
        h = h * 1099511628211
    }
    if h < 0 { h = -h }
    return h
}

function sort_segs(seg: ptr<i8>, n: i32) -> void {
    for i in 1..n {
        let key: i8 = seg[i]
        let mut j: i32 = i - 1
        while j >= 0 && (seg[j] as i32) > (key as i32) {
            seg[j + 1] = seg[j]
            j = j - 1
        }
        seg[j + 1] = key
    }
}

# Global-ish via pointers passed around
function expected(seg: ptr<i8>, nseg: i32, best: i32, keys: ptr<i8>, vals: ptr<f64>, used: ptr<i8>, cap: i64) -> f64 {
    if nseg == 0 {
        return best as f64
    }
    let key: ptr<i8> = calloc(41, 1)
    pack_key(seg, nseg, best, key)
    let h0: i64 = hash_key(key) % cap
    let mut slot: i64 = h0
    while used[slot] == 1 {
        let mut same: bool = true
        let mut i: i32 = 0
        while i < 41 {
            if keys[slot * 41 + i] != key[i] { same = false; break }
            i = i + 1
        }
        if same {
            let v: f64 = vals[slot]
            free(key)
            return v
        }
        slot = slot + 1
        if slot == cap { slot = 0 }
    }
    # compute
    let mut remaining: i32 = 0
    for i in 0..nseg {
        remaining = remaining + (seg[i] as i32)
    }
    let mut total: f64 = 0.0
    let mut i: i32 = 0
    while i < nseg {
        let seg_len: i32 = seg[i] as i32
        let mut j: i32 = i + 1
        while j < nseg && (seg[j] as i32) == seg_len {
            j = j + 1
        }
        let count: i32 = j - i
        # build base = state without one copy of seg_len at i
        let base: ptr<i8> = calloc(40, 1)
        let mut bn: i32 = 0
        for k in 0..nseg {
            if k != i {
                base[bn] = seg[k]
                bn = bn + 1
            }
        }
        if seg_len == 1 {
            let nb: i32 = best
            let mut nn: i32 = bn
            # next state is base
            let nxt: ptr<i8> = calloc(40, 1)
            for k in 0..bn { nxt[k] = base[k] }
            let nbest: i32 = nb
            if nn > nbest { nbest = nn }
            total = total + (count as f64) * expected(nxt, nn, nbest, keys, vals, used, cap)
            free(nxt)
        } else {
            # case: shrink to seg_len-1
            let nxt: ptr<i8> = calloc(40, 1)
            for k in 0..bn { nxt[k] = base[k] }
            nxt[bn] = (seg_len - 1) as i8
            let nn: i32 = bn + 1
            sort_segs(nxt, nn)
            let nbest: i32 = best
            if nn > nbest { nbest = nn }
            total = total + (2.0 * (count as f64)) * expected(nxt, nn, nbest, keys, vals, used, cap)
            free(nxt)
            # splits
            let rest: i32 = seg_len - 1
            for left in 1..(rest / 2 + 1) {
                let right: i32 = rest - left
                let mult: f64 = 2.0
                if left == right { mult = 1.0 }
                let nxt2: ptr<i8> = calloc(40, 1)
                for k in 0..bn { nxt2[k] = base[k] }
                nxt2[bn] = left as i8
                nxt2[bn + 1] = right as i8
                let nn2: i32 = bn + 2
                sort_segs(nxt2, nn2)
                let nbest2: i32 = best
                if nn2 > nbest2 { nbest2 = nn2 }
                total = total + (mult * (count as f64)) * expected(nxt2, nn2, nbest2, keys, vals, used, cap)
                free(nxt2)
            }
        }
        free(base)
        i = j
    }
    let result: f64 = total / (remaining as f64)
    # insert
    used[slot] = 1
    for i in 0..41 {
        keys[slot * 41 + i] = key[i]
    }
    vals[slot] = result
    free(key)
    return result
}

function main() -> i32 {
    let CAP: i64 = 2000003
    let keys: ptr<i8> = calloc(CAP * 41, 1)
    let vals: ptr<f64> = calloc(CAP, 8)
    let used: ptr<i8> = calloc(CAP, 1)
    let seg: ptr<i8> = calloc(40, 1)
    seg[0] = 40
    let ans: f64 = expected(seg, 1, 1, keys, vals, used, CAP)
    printf("%.6f\n", ans)
    free(keys); free(vals); free(used); free(seg)
    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; }

void pack_key_ptr_i8_i32_i32_ptr_i8(int8_t* seg, int32_t nseg, int32_t best, int8_t* out);
int64_t hash_key_ptr_i8(int8_t* key);
void sort_segs_ptr_i8_i32(int8_t* seg, int32_t n);
double expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(int8_t* seg, int32_t nseg, int32_t best, int8_t* keys, double* vals, int8_t* used, int64_t cap);
int32_t main(void);



void pack_key_ptr_i8_i32_i32_ptr_i8(int8_t* seg, int32_t nseg, int32_t best, int8_t* out) {
    int32_t __flow_step_1 = 1;
    for (int32_t i = 0; (0 <= nseg) ? i < nseg : i > nseg; i += (0 <= nseg) ? 1 : -1) {
        out[i] = seg[i];
    }
    int32_t __flow_step_2 = 1;
    for (int32_t i = nseg; (nseg <= 40) ? i < 40 : i > 40; i += (nseg <= 40) ? 1 : -1) {
        out[i] = 0;
    }
    out[40] = ((int8_t)(best));
}

int64_t hash_key_ptr_i8(int8_t* key) {
    int64_t h = 1469598103934665603;
    int32_t __flow_step_3 = 1;
    for (int32_t i = 0; (0 <= 41) ? i < 41 : i > 41; i += (0 <= 41) ? 1 : -1) {
        h = (h ^ ((int64_t)(key[i])));
        h = (h * 1099511628211);
    }
    if (h < 0) {
        h = (-h);
    }
    return h;
}

void sort_segs_ptr_i8_i32(int8_t* seg, int32_t n) {
    int32_t __flow_step_4 = 1;
    for (int32_t i = 1; (1 <= n) ? i < n : i > n; i += (1 <= n) ? 1 : -1) {
        int8_t key = seg[i];
        int32_t j = (i - 1);
        while ((j >= 0 && ((int32_t)(seg[j])) > ((int32_t)(key)))) {
            seg[(j + 1)] = seg[j];
            j = (j - 1);
        }
        seg[(j + 1)] = key;
    }
}

double expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(int8_t* seg, int32_t nseg, int32_t best, int8_t* keys, double* vals, int8_t* used, int64_t cap) {
    if (nseg == 0) {
        return ((double)(best));
    }
    int8_t* key = (int8_t*)(calloc(41, 1));
    pack_key_ptr_i8_i32_i32_ptr_i8(seg, nseg, best, key);
    int64_t h0 = FLOW_CHECKED_MOD((hash_key_ptr_i8(key)), (cap));
    int64_t slot = h0;
    while (used[slot] == 1) {
        bool same = 1;
        int32_t i = 0;
        while (i < 41) {
            if (keys[((slot * 41) + i)] != key[i]) {
                same = 0;
                break;
            }
            i = (i + 1);
        }
        if (same) {
            double v = vals[slot];
            free(key);
            return v;
        }
        slot = (slot + 1);
        if (slot == cap) {
            slot = 0;
        }
    }
    int32_t remaining = 0;
    int32_t __flow_step_5 = 1;
    for (int32_t i = 0; (0 <= nseg) ? i < nseg : i > nseg; i += (0 <= nseg) ? 1 : -1) {
        remaining = (remaining + ((int32_t)(seg[i])));
    }
    double total = 0.0;
    int32_t i = 0;
    while (i < nseg) {
        int32_t seg_len = ((int32_t)(seg[i]));
        int32_t j = (i + 1);
        while ((j < nseg && ((int32_t)(seg[j])) == seg_len)) {
            j = (j + 1);
        }
        int32_t count = (j - i);
        int8_t* base = (int8_t*)(calloc(40, 1));
        int32_t bn = 0;
        int32_t __flow_step_6 = 1;
        for (int32_t k = 0; (0 <= nseg) ? k < nseg : k > nseg; k += (0 <= nseg) ? 1 : -1) {
            if (k != i) {
                base[bn] = seg[k];
                bn = (bn + 1);
            }
        }
        if (seg_len == 1) {
            int32_t nb = best;
            int32_t nn = bn;
            int8_t* nxt = (int8_t*)(calloc(40, 1));
            int32_t __flow_step_7 = 1;
            for (int32_t k = 0; (0 <= bn) ? k < bn : k > bn; k += (0 <= bn) ? 1 : -1) {
                nxt[k] = base[k];
            }
            int32_t nbest = nb;
            if (nn > nbest) {
                nbest = nn;
            }
            total = (total + (((double)(count)) * expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(nxt, nn, nbest, keys, vals, used, cap)));
            free(nxt);
        } else {
            int8_t* nxt = (int8_t*)(calloc(40, 1));
            int32_t __flow_step_8 = 1;
            for (int32_t k = 0; (0 <= bn) ? k < bn : k > bn; k += (0 <= bn) ? 1 : -1) {
                nxt[k] = base[k];
            }
            nxt[bn] = ((int8_t)((seg_len - 1)));
            int32_t nn = (bn + 1);
            sort_segs_ptr_i8_i32(nxt, nn);
            int32_t nbest = best;
            if (nn > nbest) {
                nbest = nn;
            }
            total = (total + ((2.0 * ((double)(count))) * expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(nxt, nn, nbest, keys, vals, used, cap)));
            free(nxt);
            int32_t rest = (seg_len - 1);
            int32_t __flow_step_9 = 1;
            for (int32_t left = 1; (1 <= (FLOW_CHECKED_DIV((rest), (2)) + 1)) ? left < (FLOW_CHECKED_DIV((rest), (2)) + 1) : left > (FLOW_CHECKED_DIV((rest), (2)) + 1); left += (1 <= (FLOW_CHECKED_DIV((rest), (2)) + 1)) ? 1 : -1) {
                int32_t right = (rest - left);
                double mult = 2.0;
                if (left == right) {
                    mult = 1.0;
                }
                int8_t* nxt2 = (int8_t*)(calloc(40, 1));
                int32_t __flow_step_10 = 1;
                for (int32_t k = 0; (0 <= bn) ? k < bn : k > bn; k += (0 <= bn) ? 1 : -1) {
                    nxt2[k] = base[k];
                }
                nxt2[bn] = ((int8_t)(left));
                nxt2[(bn + 1)] = ((int8_t)(right));
                int32_t nn2 = (bn + 2);
                sort_segs_ptr_i8_i32(nxt2, nn2);
                int32_t nbest2 = best;
                if (nn2 > nbest2) {
                    nbest2 = nn2;
                }
                total = (total + ((mult * ((double)(count))) * expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(nxt2, nn2, nbest2, keys, vals, used, cap)));
                free(nxt2);
            }
        }
        free(base);
        i = j;
    }
    double result = (total / ((double)(remaining)));
    used[slot] = 1;
    int32_t __flow_step_11 = 1;
    for (int32_t i = 0; (0 <= 41) ? i < 41 : i > 41; i += (0 <= 41) ? 1 : -1) {
        keys[((slot * 41) + i)] = key[i];
    }
    vals[slot] = result;
    free(key);
    return result;
}

int32_t main(void) {
    int64_t CAP = 2000003;
    int8_t* keys = (int8_t*)(calloc((CAP * 41), 1));
    double* vals = (double*)(calloc(CAP, 8));
    int8_t* used = (int8_t*)(calloc(CAP, 1));
    int8_t* seg = (int8_t*)(calloc(40, 1));
    seg[0] = 40;
    double ans = expected_ptr_i8_i32_i32_ptr_i8_ptr_f64_ptr_i8_i64(seg, 1, 1, keys, vals, used, CAP);
    printf("%.6f\n", ans);
    free(keys);
    free(vals);
    free(used);
    free(seg);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%.6f\n\00") {addr_space = 0 : i32} : !llvm.array<6 x i8>
  func.func private @calloc(i64, i64) -> !llvm.ptr
  func.func private @free(!llvm.ptr) -> ()
  func.func @pack_key(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32, %arg3: !llvm.ptr) -> () {
    %0 = arith.constant 0 : i32
    %1 = arith.index_cast %0 : i32 to index
    %2 = arith.index_cast %arg1 : i32 to index
    %4 = arith.constant 1 : index
    %5 = arith.constant -1 : index
    %6 = arith.cmpi sle, %1, %2 : index
    %3 = arith.select %6, %4, %5 : index
    cf.br ^bb0(%1 : index)
    ^bb0(%7: index):
    %8 = arith.cmpi slt, %7, %2 : index
    %9 = arith.cmpi sgt, %7, %2 : index
    %10 = arith.select %6, %8, %9 : i1
    cf.cond_br %10, ^bb1(%7 : index), ^bb2(%7 : index)
    ^bb1(%11: index):
      %13 = arith.index_cast %11 : index to i64
      %14 = llvm.getelementptr %arg0[%13] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %12 = llvm.load %14 : !llvm.ptr -> i8
      %15 = arith.index_cast %11 : index to i64
      %16 = llvm.getelementptr %arg3[%15] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %12, %16 : i8, !llvm.ptr
      %17 = arith.addi %11, %3 : index
      cf.br ^bb0(%17 : index)
    ^bb2(%18: index):
    %19 = arith.constant 40 : i32
    %20 = arith.index_cast %arg1 : i32 to index
    %21 = arith.index_cast %19 : i32 to index
    %23 = arith.constant 1 : index
    %24 = arith.constant -1 : index
    %25 = arith.cmpi sle, %20, %21 : index
    %22 = arith.select %25, %23, %24 : index
    cf.br ^bb3(%20 : index)
    ^bb3(%26: index):
    %27 = arith.cmpi slt, %26, %21 : index
    %28 = arith.cmpi sgt, %26, %21 : index
    %29 = arith.select %25, %27, %28 : i1
    cf.cond_br %29, ^bb4(%26 : index), ^bb5(%26 : index)
    ^bb4(%30: index):
      %31 = arith.constant 0 : i32
      %32 = arith.trunci %31 : i32 to i8
      %33 = arith.index_cast %30 : index to i64
      %34 = llvm.getelementptr %arg3[%33] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %32, %34 : i8, !llvm.ptr
      %35 = arith.addi %30, %22 : index
      cf.br ^bb3(%35 : index)
    ^bb5(%36: index):
    %37 = arith.trunci %arg2 : i32 to i8
    %38 = arith.constant 40 : i32
    %39 = arith.extsi %38 : i32 to i64
    %40 = llvm.getelementptr %arg3[%39] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %37, %40 : i8, !llvm.ptr
    func.return
  }
  func.func @hash_key(%arg0: !llvm.ptr) -> i64 {
    %41 = arith.constant 1469598099639698307 : i32
    %42 = arith.extsi %41 : i32 to i64
    %43 = llvm.mlir.constant(1 : i64) : i64
    %44 = llvm.alloca %43 x i64 : (i64) -> !llvm.ptr
    llvm.store %42, %44 : i64, !llvm.ptr
    %45 = arith.constant 0 : i32
    %46 = arith.constant 41 : i32
    %47 = arith.index_cast %45 : i32 to index
    %48 = arith.index_cast %46 : i32 to index
    %50 = arith.constant 1 : index
    %51 = arith.constant -1 : index
    %52 = arith.cmpi sle, %47, %48 : index
    %49 = arith.select %52, %50, %51 : index
    cf.br ^bb6(%47 : index)
    ^bb6(%53: index):
    %54 = arith.cmpi slt, %53, %48 : index
    %55 = arith.cmpi sgt, %53, %48 : index
    %56 = arith.select %52, %54, %55 : i1
    cf.cond_br %56, ^bb7(%53 : index), ^bb8(%53 : index)
    ^bb7(%57: index):
      %58 = llvm.load %44 : !llvm.ptr -> i64
      %60 = arith.index_cast %57 : index to i64
      %61 = llvm.getelementptr %arg0[%60] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %59 = llvm.load %61 : !llvm.ptr -> i8
      %62 = arith.extsi %59 : i8 to i64
      %63 = arith.xori %58, %62 : i64
      llvm.store %63, %44 : i64, !llvm.ptr
      %64 = llvm.load %44 : !llvm.ptr -> i64
      %65 = arith.constant 1095216660915 : i32
      %67 = arith.extsi %65 : i32 to i64
      %66 = arith.muli %64, %67 : i64
      llvm.store %66, %44 : i64, !llvm.ptr
      %68 = arith.addi %57, %49 : index
      cf.br ^bb6(%68 : index)
    ^bb8(%69: index):
    %70 = llvm.load %44 : !llvm.ptr -> i64
    %71 = arith.constant 0 : i32
    %73 = arith.extsi %71 : i32 to i64
    %72 = arith.cmpi slt, %70, %73 : i64
    cf.cond_br %72, ^bb9, ^bb10
    ^bb9:
      %74 = llvm.load %44 : !llvm.ptr -> i64
      %76 = arith.constant 0 : i64
      %75 = arith.subi %76, %74 : i64
      llvm.store %75, %44 : i64, !llvm.ptr
      cf.br ^bb11
    ^bb10:
      cf.br ^bb11
    ^bb11:
    %77 = llvm.load %44 : !llvm.ptr -> i64
    func.return %77 : i64
  }
  func.func @sort_segs(%arg0: !llvm.ptr, %arg1: i32) -> () {
    %78 = arith.constant 1 : i32
    %79 = arith.index_cast %78 : i32 to index
    %80 = arith.index_cast %arg1 : i32 to index
    %82 = arith.constant 1 : index
    %83 = arith.constant -1 : index
    %84 = arith.cmpi sle, %79, %80 : index
    %81 = arith.select %84, %82, %83 : index
    cf.br ^bb12(%79 : index)
    ^bb12(%85: index):
    %86 = arith.cmpi slt, %85, %80 : index
    %87 = arith.cmpi sgt, %85, %80 : index
    %88 = arith.select %84, %86, %87 : i1
    cf.cond_br %88, ^bb13(%85 : index), ^bb14(%85 : index)
    ^bb13(%89: index):
      %91 = arith.index_cast %89 : index to i64
      %92 = llvm.getelementptr %arg0[%91] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %90 = llvm.load %92 : !llvm.ptr -> i8
      %93 = arith.constant 1 : i32
      %95 = arith.index_cast %89 : index to i32
      %94 = arith.subi %95, %93 : i32
      %96 = llvm.mlir.constant(1 : i64) : i64
      %97 = llvm.alloca %96 x i32 : (i64) -> !llvm.ptr
      llvm.store %94, %97 : i32, !llvm.ptr
      cf.br ^bb15
      ^bb15:
      %98 = llvm.load %97 : !llvm.ptr -> i32
      %99 = arith.constant 0 : i32
      %100 = arith.cmpi sge, %98, %99 : i32
      %101 = scf.if %100 -> (i1) {
        %103 = llvm.load %97 : !llvm.ptr -> i32
        %104 = arith.extsi %103 : i32 to i64
        %105 = llvm.getelementptr %arg0[%104] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %102 = llvm.load %105 : !llvm.ptr -> i8
        %106 = arith.extsi %102 : i8 to i32
        %107 = arith.extsi %90 : i8 to i32
        %108 = arith.cmpi sgt, %106, %107 : i32
        scf.yield %108 : i1
      } else {
        %109 = arith.constant false
        scf.yield %109 : i1
      }
      cf.cond_br %101, ^bb16, ^bb17
      ^bb16:
        %111 = llvm.load %97 : !llvm.ptr -> i32
        %112 = arith.extsi %111 : i32 to i64
        %113 = llvm.getelementptr %arg0[%112] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %110 = llvm.load %113 : !llvm.ptr -> i8
        %114 = llvm.load %97 : !llvm.ptr -> i32
        %115 = arith.constant 1 : i32
        %116 = arith.addi %114, %115 : i32
        %117 = arith.extsi %116 : i32 to i64
        %118 = llvm.getelementptr %arg0[%117] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %110, %118 : i8, !llvm.ptr
        %119 = llvm.load %97 : !llvm.ptr -> i32
        %120 = arith.constant 1 : i32
        %121 = arith.subi %119, %120 : i32
        llvm.store %121, %97 : i32, !llvm.ptr
        cf.br ^bb15
      ^bb17:
      %122 = llvm.load %97 : !llvm.ptr -> i32
      %123 = arith.constant 1 : i32
      %124 = arith.addi %122, %123 : i32
      %125 = arith.extsi %124 : i32 to i64
      %126 = llvm.getelementptr %arg0[%125] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %90, %126 : i8, !llvm.ptr
      %127 = arith.addi %89, %81 : index
      cf.br ^bb12(%127 : index)
    ^bb14(%128: index):
    func.return
  }
  func.func @expected(%arg0: !llvm.ptr, %arg1: i32, %arg2: i32, %arg3: !llvm.ptr, %arg4: !llvm.ptr, %arg5: !llvm.ptr, %arg6: i64) -> f64 {
    %129 = arith.constant 0 : i32
    %130 = arith.cmpi eq, %arg1, %129 : i32
    cf.cond_br %130, ^bb18, ^bb19
    ^bb18:
      %131 = arith.sitofp %arg2 : i32 to f64
      func.return %131 : f64
    ^bb19:
      cf.br ^bb20
    ^bb20:
    %133 = arith.constant 41 : i32
    %134 = arith.constant 1 : i32
    %135 = arith.extsi %133 : i32 to i64
    %136 = arith.extsi %134 : i32 to i64
    %132 = func.call @calloc(%135, %136) : (i64, i64) -> !llvm.ptr
    func.call @pack_key(%arg0, %arg1, %arg2, %132) : (!llvm.ptr, i32, i32, !llvm.ptr) -> ()
    %138 = func.call @hash_key(%132) : (!llvm.ptr) -> i64
    %139 = arith.remsi %138, %arg6 : i64
    %140 = llvm.mlir.constant(1 : i64) : i64
    %141 = llvm.alloca %140 x i64 : (i64) -> !llvm.ptr
    llvm.store %139, %141 : i64, !llvm.ptr
    cf.br ^bb21
    ^bb21:
    %143 = llvm.load %141 : !llvm.ptr -> i64
    %144 = llvm.getelementptr %arg5[%143] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %142 = llvm.load %144 : !llvm.ptr -> i8
    %145 = arith.constant 1 : i32
    %147 = arith.extsi %142 : i8 to i32
    %146 = arith.cmpi eq, %147, %145 : i32
    cf.cond_br %146, ^bb22, ^bb23
    ^bb22:
      %148 = arith.constant 1 : i1
      %149 = llvm.mlir.constant(1 : i64) : i64
      %150 = llvm.alloca %149 x i1 : (i64) -> !llvm.ptr
      llvm.store %148, %150 : i1, !llvm.ptr
      %151 = arith.constant 0 : i32
      %152 = llvm.mlir.constant(1 : i64) : i64
      %153 = llvm.alloca %152 x i32 : (i64) -> !llvm.ptr
      llvm.store %151, %153 : i32, !llvm.ptr
      cf.br ^bb24
      ^bb24:
      %154 = llvm.load %153 : !llvm.ptr -> i32
      %155 = arith.constant 41 : i32
      %156 = arith.cmpi slt, %154, %155 : i32
      cf.cond_br %156, ^bb25, ^bb26
      ^bb25:
        %158 = llvm.load %141 : !llvm.ptr -> i64
        %159 = arith.constant 41 : i32
        %161 = arith.extsi %159 : i32 to i64
        %160 = arith.muli %158, %161 : i64
        %162 = llvm.load %153 : !llvm.ptr -> i32
        %164 = arith.extsi %162 : i32 to i64
        %163 = arith.addi %160, %164 : i64
        %165 = llvm.getelementptr %arg3[%163] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %157 = llvm.load %165 : !llvm.ptr -> i8
        %167 = llvm.load %153 : !llvm.ptr -> i32
        %168 = arith.extsi %167 : i32 to i64
        %169 = llvm.getelementptr %132[%168] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %166 = llvm.load %169 : !llvm.ptr -> i8
        %171 = arith.extsi %157 : i8 to i32
        %172 = arith.extsi %166 : i8 to i32
        %170 = arith.cmpi ne, %171, %172 : i32
        cf.cond_br %170, ^bb27, ^bb28
        ^bb27:
          %173 = arith.constant 0 : i1
          llvm.store %173, %150 : i1, !llvm.ptr
          cf.br ^bb26
        ^bb28:
          cf.br ^bb29
        ^bb29:
        %174 = llvm.load %153 : !llvm.ptr -> i32
        %175 = arith.constant 1 : i32
        %176 = arith.addi %174, %175 : i32
        llvm.store %176, %153 : i32, !llvm.ptr
        cf.br ^bb24
      ^bb26:
      %177 = llvm.load %150 : !llvm.ptr -> i1
      cf.cond_br %177, ^bb30, ^bb31
      ^bb30:
        %179 = llvm.load %141 : !llvm.ptr -> i64
        %180 = llvm.getelementptr %arg4[%179] : (!llvm.ptr, i64) -> !llvm.ptr, f64
        %178 = llvm.load %180 : !llvm.ptr -> f64
        func.call @free(%132) : (!llvm.ptr) -> ()
        func.return %178 : f64
      ^bb31:
        cf.br ^bb32
      ^bb32:
      %182 = llvm.load %141 : !llvm.ptr -> i64
      %183 = arith.constant 1 : i32
      %185 = arith.extsi %183 : i32 to i64
      %184 = arith.addi %182, %185 : i64
      llvm.store %184, %141 : i64, !llvm.ptr
      %186 = llvm.load %141 : !llvm.ptr -> i64
      %187 = arith.cmpi eq, %186, %arg6 : i64
      cf.cond_br %187, ^bb33, ^bb34
      ^bb33:
        %188 = arith.constant 0 : i32
        %189 = arith.extsi %188 : i32 to i64
        llvm.store %189, %141 : i64, !llvm.ptr
        cf.br ^bb35
      ^bb34:
        cf.br ^bb35
      ^bb35:
      cf.br ^bb21
    ^bb23:
    %190 = arith.constant 0 : i32
    %191 = llvm.mlir.constant(1 : i64) : i64
    %192 = llvm.alloca %191 x i32 : (i64) -> !llvm.ptr
    llvm.store %190, %192 : i32, !llvm.ptr
    %193 = arith.constant 0 : i32
    %194 = arith.index_cast %193 : i32 to index
    %195 = arith.index_cast %arg1 : i32 to index
    %197 = arith.constant 1 : index
    %198 = arith.constant -1 : index
    %199 = arith.cmpi sle, %194, %195 : index
    %196 = arith.select %199, %197, %198 : index
    cf.br ^bb36(%194 : index)
    ^bb36(%200: index):
    %201 = arith.cmpi slt, %200, %195 : index
    %202 = arith.cmpi sgt, %200, %195 : index
    %203 = arith.select %199, %201, %202 : i1
    cf.cond_br %203, ^bb37(%200 : index), ^bb38(%200 : index)
    ^bb37(%204: index):
      %205 = llvm.load %192 : !llvm.ptr -> i32
      %207 = arith.index_cast %204 : index to i64
      %208 = llvm.getelementptr %arg0[%207] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %206 = llvm.load %208 : !llvm.ptr -> i8
      %209 = arith.extsi %206 : i8 to i32
      %210 = arith.addi %205, %209 : i32
      llvm.store %210, %192 : i32, !llvm.ptr
      %211 = arith.addi %204, %196 : index
      cf.br ^bb36(%211 : index)
    ^bb38(%212: index):
    %213 = arith.constant 0.0 : f32
    %214 = arith.extf %213 : f32 to f64
    %215 = llvm.mlir.constant(1 : i64) : i64
    %216 = llvm.alloca %215 x f64 : (i64) -> !llvm.ptr
    llvm.store %214, %216 : f64, !llvm.ptr
    %217 = arith.constant 0 : i32
    %218 = llvm.mlir.constant(1 : i64) : i64
    %219 = llvm.alloca %218 x i32 : (i64) -> !llvm.ptr
    llvm.store %217, %219 : i32, !llvm.ptr
    cf.br ^bb39
    ^bb39:
    %220 = llvm.load %219 : !llvm.ptr -> i32
    %221 = arith.cmpi slt, %220, %arg1 : i32
    cf.cond_br %221, ^bb40, ^bb41
    ^bb40:
      %223 = llvm.load %219 : !llvm.ptr -> i32
      %224 = arith.extsi %223 : i32 to i64
      %225 = llvm.getelementptr %arg0[%224] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %222 = llvm.load %225 : !llvm.ptr -> i8
      %226 = arith.extsi %222 : i8 to i32
      %227 = llvm.load %219 : !llvm.ptr -> i32
      %228 = arith.constant 1 : i32
      %229 = arith.addi %227, %228 : i32
      %230 = llvm.mlir.constant(1 : i64) : i64
      %231 = llvm.alloca %230 x i32 : (i64) -> !llvm.ptr
      llvm.store %229, %231 : i32, !llvm.ptr
      cf.br ^bb42
      ^bb42:
      %232 = llvm.load %231 : !llvm.ptr -> i32
      %233 = arith.cmpi slt, %232, %arg1 : i32
      %234 = scf.if %233 -> (i1) {
        %236 = llvm.load %231 : !llvm.ptr -> i32
        %237 = arith.extsi %236 : i32 to i64
        %238 = llvm.getelementptr %arg0[%237] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        %235 = llvm.load %238 : !llvm.ptr -> i8
        %239 = arith.extsi %235 : i8 to i32
        %240 = arith.cmpi eq, %239, %226 : i32
        scf.yield %240 : i1
      } else {
        %241 = arith.constant false
        scf.yield %241 : i1
      }
      cf.cond_br %234, ^bb43, ^bb44
      ^bb43:
        %242 = llvm.load %231 : !llvm.ptr -> i32
        %243 = arith.constant 1 : i32
        %244 = arith.addi %242, %243 : i32
        llvm.store %244, %231 : i32, !llvm.ptr
        cf.br ^bb42
      ^bb44:
      %245 = llvm.load %231 : !llvm.ptr -> i32
      %246 = llvm.load %219 : !llvm.ptr -> i32
      %247 = arith.subi %245, %246 : i32
      %249 = arith.constant 40 : i32
      %250 = arith.constant 1 : i32
      %251 = arith.extsi %249 : i32 to i64
      %252 = arith.extsi %250 : i32 to i64
      %248 = func.call @calloc(%251, %252) : (i64, i64) -> !llvm.ptr
      %253 = arith.constant 0 : i32
      %254 = llvm.mlir.constant(1 : i64) : i64
      %255 = llvm.alloca %254 x i32 : (i64) -> !llvm.ptr
      llvm.store %253, %255 : i32, !llvm.ptr
      %256 = arith.constant 0 : i32
      %257 = arith.index_cast %256 : i32 to index
      %258 = arith.index_cast %arg1 : i32 to index
      %260 = arith.constant 1 : index
      %261 = arith.constant -1 : index
      %262 = arith.cmpi sle, %257, %258 : index
      %259 = arith.select %262, %260, %261 : index
      cf.br ^bb45(%257 : index)
      ^bb45(%263: index):
      %264 = arith.cmpi slt, %263, %258 : index
      %265 = arith.cmpi sgt, %263, %258 : index
      %266 = arith.select %262, %264, %265 : i1
      cf.cond_br %266, ^bb46(%263 : index), ^bb47(%263 : index)
      ^bb46(%267: index):
        %268 = llvm.load %219 : !llvm.ptr -> i32
        %270 = arith.index_cast %267 : index to i32
        %269 = arith.cmpi ne, %270, %268 : i32
        cf.cond_br %269, ^bb48, ^bb49
        ^bb48:
          %272 = arith.index_cast %267 : index to i64
          %273 = llvm.getelementptr %arg0[%272] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %271 = llvm.load %273 : !llvm.ptr -> i8
          %274 = llvm.load %255 : !llvm.ptr -> i32
          %275 = arith.extsi %274 : i32 to i64
          %276 = llvm.getelementptr %248[%275] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %271, %276 : i8, !llvm.ptr
          %277 = llvm.load %255 : !llvm.ptr -> i32
          %278 = arith.constant 1 : i32
          %279 = arith.addi %277, %278 : i32
          llvm.store %279, %255 : i32, !llvm.ptr
          cf.br ^bb50
        ^bb49:
          cf.br ^bb50
        ^bb50:
        %280 = arith.addi %267, %259 : index
        cf.br ^bb45(%280 : index)
      ^bb47(%281: index):
      %282 = arith.constant 1 : i32
      %283 = arith.cmpi eq, %226, %282 : i32
      cf.cond_br %283, ^bb51, ^bb52
      ^bb51:
        %284 = llvm.load %255 : !llvm.ptr -> i32
        %285 = llvm.mlir.constant(1 : i64) : i64
        %286 = llvm.alloca %285 x i32 : (i64) -> !llvm.ptr
        llvm.store %284, %286 : i32, !llvm.ptr
        %288 = arith.constant 40 : i32
        %289 = arith.constant 1 : i32
        %290 = arith.extsi %288 : i32 to i64
        %291 = arith.extsi %289 : i32 to i64
        %287 = func.call @calloc(%290, %291) : (i64, i64) -> !llvm.ptr
        %292 = arith.constant 0 : i32
        %293 = llvm.load %255 : !llvm.ptr -> i32
        %294 = arith.index_cast %292 : i32 to index
        %295 = arith.index_cast %293 : i32 to index
        %297 = arith.constant 1 : index
        %298 = arith.constant -1 : index
        %299 = arith.cmpi sle, %294, %295 : index
        %296 = arith.select %299, %297, %298 : index
        cf.br ^bb54(%294 : index)
        ^bb54(%300: index):
        %301 = arith.cmpi slt, %300, %295 : index
        %302 = arith.cmpi sgt, %300, %295 : index
        %303 = arith.select %299, %301, %302 : i1
        cf.cond_br %303, ^bb55(%300 : index), ^bb56(%300 : index)
        ^bb55(%304: index):
          %306 = arith.index_cast %304 : index to i64
          %307 = llvm.getelementptr %248[%306] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %305 = llvm.load %307 : !llvm.ptr -> i8
          %308 = arith.index_cast %304 : index to i64
          %309 = llvm.getelementptr %287[%308] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %305, %309 : i8, !llvm.ptr
          %310 = arith.addi %304, %296 : index
          cf.br ^bb54(%310 : index)
        ^bb56(%311: index):
        %312 = llvm.load %286 : !llvm.ptr -> i32
        %313 = arith.cmpi sgt, %312, %arg2 : i32
        %314 = scf.if %313 -> (i32) {
          %315 = llvm.load %286 : !llvm.ptr -> i32
          scf.yield %315 : i32
        } else {
          scf.yield %arg2 : i32
        }
        %316 = llvm.load %216 : !llvm.ptr -> f64
        %317 = arith.sitofp %247 : i32 to f64
        %319 = llvm.load %286 : !llvm.ptr -> i32
        %318 = func.call @expected(%287, %319, %314, %arg3, %arg4, %arg5, %arg6) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> f64
        %320 = arith.mulf %317, %318 : f64
        %321 = arith.addf %316, %320 : f64
        llvm.store %321, %216 : f64, !llvm.ptr
        func.call @free(%287) : (!llvm.ptr) -> ()
        cf.br ^bb53
      ^bb52:
        %324 = arith.constant 40 : i32
        %325 = arith.constant 1 : i32
        %326 = arith.extsi %324 : i32 to i64
        %327 = arith.extsi %325 : i32 to i64
        %323 = func.call @calloc(%326, %327) : (i64, i64) -> !llvm.ptr
        %328 = arith.constant 0 : i32
        %329 = llvm.load %255 : !llvm.ptr -> i32
        %330 = arith.index_cast %328 : i32 to index
        %331 = arith.index_cast %329 : i32 to index
        %333 = arith.constant 1 : index
        %334 = arith.constant -1 : index
        %335 = arith.cmpi sle, %330, %331 : index
        %332 = arith.select %335, %333, %334 : index
        cf.br ^bb57(%330 : index)
        ^bb57(%336: index):
        %337 = arith.cmpi slt, %336, %331 : index
        %338 = arith.cmpi sgt, %336, %331 : index
        %339 = arith.select %335, %337, %338 : i1
        cf.cond_br %339, ^bb58(%336 : index), ^bb59(%336 : index)
        ^bb58(%340: index):
          %342 = arith.index_cast %340 : index to i64
          %343 = llvm.getelementptr %248[%342] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          %341 = llvm.load %343 : !llvm.ptr -> i8
          %344 = arith.index_cast %340 : index to i64
          %345 = llvm.getelementptr %323[%344] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %341, %345 : i8, !llvm.ptr
          %346 = arith.addi %340, %332 : index
          cf.br ^bb57(%346 : index)
        ^bb59(%347: index):
        %348 = arith.constant 1 : i32
        %349 = arith.subi %226, %348 : i32
        %350 = arith.trunci %349 : i32 to i8
        %351 = llvm.load %255 : !llvm.ptr -> i32
        %352 = arith.extsi %351 : i32 to i64
        %353 = llvm.getelementptr %323[%352] : (!llvm.ptr, i64) -> !llvm.ptr, i8
        llvm.store %350, %353 : i8, !llvm.ptr
        %354 = llvm.load %255 : !llvm.ptr -> i32
        %355 = arith.constant 1 : i32
        %356 = arith.addi %354, %355 : i32
        func.call @sort_segs(%323, %356) : (!llvm.ptr, i32) -> ()
        %358 = arith.cmpi sgt, %356, %arg2 : i32
        %359 = scf.if %358 -> (i32) {
          scf.yield %356 : i32
        } else {
          scf.yield %arg2 : i32
        }
        %360 = llvm.load %216 : !llvm.ptr -> f64
        %361 = arith.constant 2.0 : f32
        %362 = arith.sitofp %247 : i32 to f64
        %364 = arith.extf %361 : f32 to f64
        %363 = arith.mulf %364, %362 : f64
        %365 = func.call @expected(%323, %356, %359, %arg3, %arg4, %arg5, %arg6) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> f64
        %366 = arith.mulf %363, %365 : f64
        %367 = arith.addf %360, %366 : f64
        llvm.store %367, %216 : f64, !llvm.ptr
        func.call @free(%323) : (!llvm.ptr) -> ()
        %369 = arith.constant 1 : i32
        %370 = arith.subi %226, %369 : i32
        %371 = arith.constant 1 : i32
        %372 = arith.constant 2 : i32
        %373 = arith.divsi %370, %372 : i32
        %374 = arith.constant 1 : i32
        %375 = arith.addi %373, %374 : i32
        %376 = arith.index_cast %371 : i32 to index
        %377 = arith.index_cast %375 : i32 to index
        %379 = arith.constant 1 : index
        %380 = arith.constant -1 : index
        %381 = arith.cmpi sle, %376, %377 : index
        %378 = arith.select %381, %379, %380 : index
        cf.br ^bb60(%376 : index)
        ^bb60(%382: index):
        %383 = arith.cmpi slt, %382, %377 : index
        %384 = arith.cmpi sgt, %382, %377 : index
        %385 = arith.select %381, %383, %384 : i1
        cf.cond_br %385, ^bb61(%382 : index), ^bb62(%382 : index)
        ^bb61(%386: index):
          %388 = arith.index_cast %386 : index to i32
          %387 = arith.subi %370, %388 : i32
          %389 = arith.constant 2.0 : f32
          %390 = arith.extf %389 : f32 to f64
          %392 = arith.index_cast %386 : index to i32
          %391 = arith.cmpi eq, %392, %387 : i32
          %393 = scf.if %391 -> (f64) {
            %394 = arith.constant 1.0 : f32
            %395 = arith.extf %394 : f32 to f64
            scf.yield %395 : f64
          } else {
            scf.yield %390 : f64
          }
          %397 = arith.constant 40 : i32
          %398 = arith.constant 1 : i32
          %399 = arith.extsi %397 : i32 to i64
          %400 = arith.extsi %398 : i32 to i64
          %396 = func.call @calloc(%399, %400) : (i64, i64) -> !llvm.ptr
          %401 = arith.constant 0 : i32
          %402 = llvm.load %255 : !llvm.ptr -> i32
          %403 = arith.index_cast %401 : i32 to index
          %404 = arith.index_cast %402 : i32 to index
          %406 = arith.constant 1 : index
          %407 = arith.constant -1 : index
          %408 = arith.cmpi sle, %403, %404 : index
          %405 = arith.select %408, %406, %407 : index
          cf.br ^bb63(%403 : index)
          ^bb63(%409: index):
          %410 = arith.cmpi slt, %409, %404 : index
          %411 = arith.cmpi sgt, %409, %404 : index
          %412 = arith.select %408, %410, %411 : i1
          cf.cond_br %412, ^bb64(%409 : index), ^bb65(%409 : index)
          ^bb64(%413: index):
            %415 = arith.index_cast %413 : index to i64
            %416 = llvm.getelementptr %248[%415] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            %414 = llvm.load %416 : !llvm.ptr -> i8
            %417 = arith.index_cast %413 : index to i64
            %418 = llvm.getelementptr %396[%417] : (!llvm.ptr, i64) -> !llvm.ptr, i8
            llvm.store %414, %418 : i8, !llvm.ptr
            %419 = arith.addi %413, %405 : index
            cf.br ^bb63(%419 : index)
          ^bb65(%420: index):
          %421 = arith.index_cast %386 : index to i8
          %422 = llvm.load %255 : !llvm.ptr -> i32
          %423 = arith.extsi %422 : i32 to i64
          %424 = llvm.getelementptr %396[%423] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %421, %424 : i8, !llvm.ptr
          %425 = arith.trunci %387 : i32 to i8
          %426 = llvm.load %255 : !llvm.ptr -> i32
          %427 = arith.constant 1 : i32
          %428 = arith.addi %426, %427 : i32
          %429 = arith.extsi %428 : i32 to i64
          %430 = llvm.getelementptr %396[%429] : (!llvm.ptr, i64) -> !llvm.ptr, i8
          llvm.store %425, %430 : i8, !llvm.ptr
          %431 = llvm.load %255 : !llvm.ptr -> i32
          %432 = arith.constant 2 : i32
          %433 = arith.addi %431, %432 : i32
          func.call @sort_segs(%396, %433) : (!llvm.ptr, i32) -> ()
          %435 = arith.cmpi sgt, %433, %arg2 : i32
          %436 = scf.if %435 -> (i32) {
            scf.yield %433 : i32
          } else {
            scf.yield %arg2 : i32
          }
          %437 = llvm.load %216 : !llvm.ptr -> f64
          %438 = arith.sitofp %247 : i32 to f64
          %439 = arith.mulf %393, %438 : f64
          %440 = func.call @expected(%396, %433, %436, %arg3, %arg4, %arg5, %arg6) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> f64
          %441 = arith.mulf %439, %440 : f64
          %442 = arith.addf %437, %441 : f64
          llvm.store %442, %216 : f64, !llvm.ptr
          func.call @free(%396) : (!llvm.ptr) -> ()
          %444 = arith.addi %386, %378 : index
          cf.br ^bb60(%444 : index)
        ^bb62(%445: index):
        cf.br ^bb53
      ^bb53:
      func.call @free(%248) : (!llvm.ptr) -> ()
      %447 = llvm.load %231 : !llvm.ptr -> i32
      llvm.store %447, %219 : i32, !llvm.ptr
      cf.br ^bb39
    ^bb41:
    %448 = llvm.load %216 : !llvm.ptr -> f64
    %449 = llvm.load %192 : !llvm.ptr -> i32
    %450 = arith.sitofp %449 : i32 to f64
    %451 = arith.divf %448, %450 : f64
    %452 = arith.constant 1 : i32
    %453 = llvm.load %141 : !llvm.ptr -> i64
    %454 = arith.trunci %452 : i32 to i8
    %455 = llvm.getelementptr %arg5[%453] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %454, %455 : i8, !llvm.ptr
    %456 = arith.constant 0 : i32
    %457 = arith.constant 41 : i32
    %458 = arith.index_cast %456 : i32 to index
    %459 = arith.index_cast %457 : i32 to index
    %461 = arith.constant 1 : index
    %462 = arith.constant -1 : index
    %463 = arith.cmpi sle, %458, %459 : index
    %460 = arith.select %463, %461, %462 : index
    cf.br ^bb66(%458 : index)
    ^bb66(%464: index):
    %465 = arith.cmpi slt, %464, %459 : index
    %466 = arith.cmpi sgt, %464, %459 : index
    %467 = arith.select %463, %465, %466 : i1
    cf.cond_br %467, ^bb67(%464 : index), ^bb68(%464 : index)
    ^bb67(%468: index):
      %470 = arith.index_cast %468 : index to i64
      %471 = llvm.getelementptr %132[%470] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      %469 = llvm.load %471 : !llvm.ptr -> i8
      %472 = llvm.load %141 : !llvm.ptr -> i64
      %473 = arith.constant 41 : i32
      %475 = arith.extsi %473 : i32 to i64
      %474 = arith.muli %472, %475 : i64
      %477 = arith.trunci %474 : i64 to i32
      %478 = arith.index_cast %468 : index to i32
      %476 = arith.addi %477, %478 : i32
      %479 = arith.extsi %476 : i32 to i64
      %480 = llvm.getelementptr %arg3[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i8
      llvm.store %469, %480 : i8, !llvm.ptr
      %481 = arith.addi %468, %460 : index
      cf.br ^bb66(%481 : index)
    ^bb68(%482: index):
    %483 = llvm.load %141 : !llvm.ptr -> i64
    %484 = llvm.getelementptr %arg4[%483] : (!llvm.ptr, i64) -> !llvm.ptr, f64
    llvm.store %451, %484 : f64, !llvm.ptr
    func.call @free(%132) : (!llvm.ptr) -> ()
    func.return %451 : f64
  }
  func.func @main() -> i32 {
    %486 = arith.constant 2000003 : i32
    %487 = arith.extsi %486 : i32 to i64
    %489 = arith.constant 41 : i32
    %491 = arith.extsi %489 : i32 to i64
    %490 = arith.muli %487, %491 : i64
    %492 = arith.constant 1 : i32
    %493 = arith.extsi %492 : i32 to i64
    %488 = func.call @calloc(%490, %493) : (i64, i64) -> !llvm.ptr
    %495 = arith.constant 8 : i32
    %496 = arith.extsi %495 : i32 to i64
    %494 = func.call @calloc(%487, %496) : (i64, i64) -> !llvm.ptr
    %498 = arith.constant 1 : i32
    %499 = arith.extsi %498 : i32 to i64
    %497 = func.call @calloc(%487, %499) : (i64, i64) -> !llvm.ptr
    %501 = arith.constant 40 : i32
    %502 = arith.constant 1 : i32
    %503 = arith.extsi %501 : i32 to i64
    %504 = arith.extsi %502 : i32 to i64
    %500 = func.call @calloc(%503, %504) : (i64, i64) -> !llvm.ptr
    %505 = arith.constant 40 : i32
    %506 = arith.constant 0 : i32
    %507 = arith.trunci %505 : i32 to i8
    %508 = arith.extsi %506 : i32 to i64
    %509 = llvm.getelementptr %500[%508] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %507, %509 : i8, !llvm.ptr
    %511 = arith.constant 1 : i32
    %512 = arith.constant 1 : i32
    %510 = func.call @expected(%500, %511, %512, %488, %494, %497, %487) : (!llvm.ptr, i32, i32, !llvm.ptr, !llvm.ptr, !llvm.ptr, i64) -> f64
    %513 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %514 = llvm.call @printf(%513, %510) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
    func.call @free(%488) : (!llvm.ptr) -> ()
    func.call @free(%494) : (!llvm.ptr) -> ()
    func.call @free(%497) : (!llvm.ptr) -> ()
    func.call @free(%500) : (!llvm.ptr) -> ()
    %519 = arith.constant 0 : i32
    func.return %519 : i32
  }
}