Problem 856

Expecting Pair — expected cards until first pair (DP over rank buckets).

Answer17.09661501
Output17.09661501
StatusPASS
Native helperno
Runtime0 ms
Peak memory18496 KB
Time complexityO(n log n) (estimated)
Space complexityO(n) (estimated)

Performance comparison

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

Flow source

# Project Euler 856
# Expecting Pair — expected cards until first pair (DP over rank buckets).

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

const HASH_N: i64 = 1 << 20

let mut keys: ptr<i64> = null
let mut vals: ptr<f64> = null
let mut used: ptr<i8> = null

function pack(cur: i64, a0: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> i64 {
    return (((((cur * 16 + a0) * 16 + a1) * 16 + a2) * 16 + a3) * 16 + a4)
}

function expected_additional(cur: i64, a0: i64, a1: i64, a2: i64, a3: i64, a4: i64) -> f64 {
    let remaining: i64 = cur + a1 + 2 * a2 + 3 * a3 + 4 * a4
    if remaining == 0 {
        return 0.0
    }
    let key: i64 = pack(cur, a0, a1, a2, a3, a4)
    let mut h: i64 = (key * 11400714819323198485) & (HASH_N - 1)
    while used[h] != 0 {
        if keys[h] == key {
            return vals[h]
        }
        h = (h + 1) & (HASH_N - 1)
    }

    let mut result: f64 = 1.0
    # count = 1..4: draw a rank with that many cards left
    let mut count: i64 = 1
    while count <= 4 {
        let mut ranks: i64 = 0
        if count == 1 { ranks = a1 }
        if count == 2 { ranks = a2 }
        if count == 3 { ranks = a3 }
        if count == 4 { ranks = a4 }
        if ranks > 0 {
            let mut na0: i64 = a0
            let mut na1: i64 = a1
            let mut na2: i64 = a2
            let mut na3: i64 = a3
            let mut na4: i64 = a4
            if count == 1 { na1 = na1 - 1 }
            if count == 2 { na2 = na2 - 1 }
            if count == 3 { na3 = na3 - 1 }
            if count == 4 { na4 = na4 - 1 }
            # return old current-rank remainder into its bucket
            if cur == 0 { na0 = na0 + 1 }
            if cur == 1 { na1 = na1 + 1 }
            if cur == 2 { na2 = na2 + 1 }
            if cur == 3 { na3 = na3 + 1 }
            if cur == 4 { na4 = na4 + 1 }
            let nxt: f64 = expected_additional(count - 1, na0, na1, na2, na3, na4)
            result = result + ((count as f64) * (ranks as f64) / (remaining as f64)) * nxt
        }
        count = count + 1
    }

    used[h] = 1
    keys[h] = key
    vals[h] = result
    return result
}

function main() -> i32 {
    keys = calloc(HASH_N, 8)
    vals = calloc(HASH_N, 8)
    used = calloc(HASH_N, 1)
    let ans: f64 = 1.0 + expected_additional(3, 0, 0, 0, 0, 12)
    printf("%.8f\n", ans)
    free(keys)
    free(vals)
    free(used)
    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; }

int64_t pack_i64_i64_i64_i64_i64_i64(int64_t cur, int64_t a0, int64_t a1, int64_t a2, int64_t a3, int64_t a4);
double expected_additional_i64_i64_i64_i64_i64_i64(int64_t cur, int64_t a0, int64_t a1, int64_t a2, int64_t a3, int64_t a4);
int32_t main(void);

static const int64_t HASH_N = FLOW_CHECKED_SHL((1), (20));

/* Module statics */
static int64_t* keys = NULL;
static double* vals = NULL;
static int8_t* used = NULL;



int64_t pack_i64_i64_i64_i64_i64_i64(int64_t cur, int64_t a0, int64_t a1, int64_t a2, int64_t a3, int64_t a4) {
    return ((((((((((cur * 16) + a0) * 16) + a1) * 16) + a2) * 16) + a3) * 16) + a4);
}

double expected_additional_i64_i64_i64_i64_i64_i64(int64_t cur, int64_t a0, int64_t a1, int64_t a2, int64_t a3, int64_t a4) {
    int64_t remaining = ((((cur + a1) + (2 * a2)) + (3 * a3)) + (4 * a4));
    if (remaining == 0) {
        return 0.0;
    }
    int64_t key = pack_i64_i64_i64_i64_i64_i64(cur, a0, a1, a2, a3, a4);
    int64_t h = ((key * ((__int128)0x9E3779B97F4A7C15ULL)) & (HASH_N - 1));
    while (used[h] != 0) {
        if (keys[h] == key) {
            return vals[h];
        }
        h = ((h + 1) & (HASH_N - 1));
    }
    double result = 1.0;
    int64_t count = 1;
    while (count <= 4) {
        int64_t ranks = 0;
        if (count == 1) {
            ranks = a1;
        }
        if (count == 2) {
            ranks = a2;
        }
        if (count == 3) {
            ranks = a3;
        }
        if (count == 4) {
            ranks = a4;
        }
        if (ranks > 0) {
            int64_t na0 = a0;
            int64_t na1 = a1;
            int64_t na2 = a2;
            int64_t na3 = a3;
            int64_t na4 = a4;
            if (count == 1) {
                na1 = (na1 - 1);
            }
            if (count == 2) {
                na2 = (na2 - 1);
            }
            if (count == 3) {
                na3 = (na3 - 1);
            }
            if (count == 4) {
                na4 = (na4 - 1);
            }
            if (cur == 0) {
                na0 = (na0 + 1);
            }
            if (cur == 1) {
                na1 = (na1 + 1);
            }
            if (cur == 2) {
                na2 = (na2 + 1);
            }
            if (cur == 3) {
                na3 = (na3 + 1);
            }
            if (cur == 4) {
                na4 = (na4 + 1);
            }
            double nxt = expected_additional_i64_i64_i64_i64_i64_i64((count - 1), na0, na1, na2, na3, na4);
            result = (result + (((((double)(count)) * ((double)(ranks))) / ((double)(remaining))) * nxt));
        }
        count = (count + 1);
    }
    used[h] = 1;
    keys[h] = key;
    vals[h] = result;
    return result;
}

int32_t main(void) {
    keys = calloc(HASH_N, 8);
    vals = calloc(HASH_N, 8);
    used = calloc(HASH_N, 1);
    double ans = (1.0 + expected_additional_i64_i64_i64_i64_i64_i64(3, 0, 0, 0, 0, 12));
    printf("%.8f\n", ans);
    free(keys);
    free(vals);
    free(used);
    return 0;
}

Generated MLIR

module {
  llvm.func @printf(!llvm.ptr, ...) -> i32
  llvm.mlir.global internal constant @str_0("%.8f\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) -> ()
  // Constant: HASH_N
  llvm.mlir.global internal constant @HASH_N(1048576 : i64) : i64
  // Module static: keys
  llvm.mlir.global internal @keys() {addr_space = 0 : i32} : !llvm.ptr {
    %0 = llvm.mlir.zero : !llvm.ptr
    llvm.return %0 : !llvm.ptr
  }
  // Module static: vals
  llvm.mlir.global internal @vals() {addr_space = 0 : i32} : !llvm.ptr {
    %1 = llvm.mlir.zero : !llvm.ptr
    llvm.return %1 : !llvm.ptr
  }
  // Module static: used
  llvm.mlir.global internal @used() {addr_space = 0 : i32} : !llvm.ptr {
    %2 = llvm.mlir.zero : !llvm.ptr
    llvm.return %2 : !llvm.ptr
  }
  func.func @pack(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64) -> i64 {
    %3 = arith.constant 16 : i32
    %5 = arith.extsi %3 : i32 to i64
    %4 = arith.muli %arg0, %5 : i64
    %6 = arith.addi %4, %arg1 : i64
    %7 = arith.constant 16 : i32
    %9 = arith.extsi %7 : i32 to i64
    %8 = arith.muli %6, %9 : i64
    %10 = arith.addi %8, %arg2 : i64
    %11 = arith.constant 16 : i32
    %13 = arith.extsi %11 : i32 to i64
    %12 = arith.muli %10, %13 : i64
    %14 = arith.addi %12, %arg3 : i64
    %15 = arith.constant 16 : i32
    %17 = arith.extsi %15 : i32 to i64
    %16 = arith.muli %14, %17 : i64
    %18 = arith.addi %16, %arg4 : i64
    %19 = arith.constant 16 : i32
    %21 = arith.extsi %19 : i32 to i64
    %20 = arith.muli %18, %21 : i64
    %22 = arith.addi %20, %arg5 : i64
    func.return %22 : i64
  }
  func.func @expected_additional(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64) -> f64 {
    %23 = arith.addi %arg0, %arg2 : i64
    %24 = arith.constant 2 : i32
    %26 = arith.extsi %24 : i32 to i64
    %25 = arith.muli %26, %arg3 : i64
    %27 = arith.addi %23, %25 : i64
    %28 = arith.constant 3 : i32
    %30 = arith.extsi %28 : i32 to i64
    %29 = arith.muli %30, %arg4 : i64
    %31 = arith.addi %27, %29 : i64
    %32 = arith.constant 4 : i32
    %34 = arith.extsi %32 : i32 to i64
    %33 = arith.muli %34, %arg5 : i64
    %35 = arith.addi %31, %33 : i64
    %36 = arith.constant 0 : i32
    %38 = arith.extsi %36 : i32 to i64
    %37 = arith.cmpi eq, %35, %38 : i64
    cf.cond_br %37, ^bb0, ^bb1
    ^bb0:
      %39 = arith.constant 0.0 : f32
      %40 = arith.extf %39 : f32 to f64
      func.return %40 : f64
    ^bb1:
      cf.br ^bb2
    ^bb2:
    %41 = func.call @pack(%arg0, %arg1, %arg2, %arg3, %arg4, %arg5) : (i64, i64, i64, i64, i64, i64) -> i64
    %42 = arith.constant 11400714815028231189 : i32
    %44 = arith.extsi %42 : i32 to i64
    %43 = arith.muli %41, %44 : i64
    %45 = llvm.mlir.addressof @HASH_N : !llvm.ptr
    %46 = llvm.load %45 : !llvm.ptr -> i64
    %47 = arith.constant 1 : i32
    %49 = arith.extsi %47 : i32 to i64
    %48 = arith.subi %46, %49 : i64
    %50 = arith.andi %43, %48 : i64
    %51 = llvm.mlir.constant(1 : i64) : i64
    %52 = llvm.alloca %51 x i64 : (i64) -> !llvm.ptr
    llvm.store %50, %52 : i64, !llvm.ptr
    cf.br ^bb3
    ^bb3:
    %54 = llvm.mlir.addressof @used : !llvm.ptr
    %55 = llvm.load %54 : !llvm.ptr -> !llvm.ptr
    %56 = llvm.load %52 : !llvm.ptr -> i64
    %57 = llvm.getelementptr %55[%56] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    %53 = llvm.load %57 : !llvm.ptr -> i8
    %58 = arith.constant 0 : i32
    %60 = arith.extsi %53 : i8 to i32
    %59 = arith.cmpi ne, %60, %58 : i32
    cf.cond_br %59, ^bb4, ^bb5
    ^bb4:
      %62 = llvm.mlir.addressof @keys : !llvm.ptr
      %63 = llvm.load %62 : !llvm.ptr -> !llvm.ptr
      %64 = llvm.load %52 : !llvm.ptr -> i64
      %65 = llvm.getelementptr %63[%64] : (!llvm.ptr, i64) -> !llvm.ptr, i64
      %61 = llvm.load %65 : !llvm.ptr -> i64
      %66 = arith.cmpi eq, %61, %41 : i64
      cf.cond_br %66, ^bb6, ^bb7
      ^bb6:
        %68 = llvm.mlir.addressof @vals : !llvm.ptr
        %69 = llvm.load %68 : !llvm.ptr -> !llvm.ptr
        %70 = llvm.load %52 : !llvm.ptr -> i64
        %71 = llvm.getelementptr %69[%70] : (!llvm.ptr, i64) -> !llvm.ptr, f64
        %67 = llvm.load %71 : !llvm.ptr -> f64
        func.return %67 : f64
      ^bb7:
        cf.br ^bb8
      ^bb8:
      %72 = llvm.load %52 : !llvm.ptr -> i64
      %73 = arith.constant 1 : i32
      %75 = arith.extsi %73 : i32 to i64
      %74 = arith.addi %72, %75 : i64
      %76 = llvm.mlir.addressof @HASH_N : !llvm.ptr
      %77 = llvm.load %76 : !llvm.ptr -> i64
      %78 = arith.constant 1 : i32
      %80 = arith.extsi %78 : i32 to i64
      %79 = arith.subi %77, %80 : i64
      %81 = arith.andi %74, %79 : i64
      llvm.store %81, %52 : i64, !llvm.ptr
      cf.br ^bb3
    ^bb5:
    %82 = arith.constant 1.0 : f32
    %83 = arith.extf %82 : f32 to f64
    %84 = llvm.mlir.constant(1 : i64) : i64
    %85 = llvm.alloca %84 x f64 : (i64) -> !llvm.ptr
    llvm.store %83, %85 : f64, !llvm.ptr
    %86 = arith.constant 1 : i32
    %87 = arith.extsi %86 : i32 to i64
    %88 = llvm.mlir.constant(1 : i64) : i64
    %89 = llvm.alloca %88 x i64 : (i64) -> !llvm.ptr
    llvm.store %87, %89 : i64, !llvm.ptr
    cf.br ^bb9
    ^bb9:
    %90 = llvm.load %89 : !llvm.ptr -> i64
    %91 = arith.constant 4 : i32
    %93 = arith.extsi %91 : i32 to i64
    %92 = arith.cmpi sle, %90, %93 : i64
    cf.cond_br %92, ^bb10, ^bb11
    ^bb10:
      %94 = arith.constant 0 : i32
      %95 = arith.extsi %94 : i32 to i64
      %96 = llvm.mlir.constant(1 : i64) : i64
      %97 = llvm.alloca %96 x i64 : (i64) -> !llvm.ptr
      llvm.store %95, %97 : i64, !llvm.ptr
      %98 = llvm.load %89 : !llvm.ptr -> i64
      %99 = arith.constant 1 : i32
      %101 = arith.extsi %99 : i32 to i64
      %100 = arith.cmpi eq, %98, %101 : i64
      cf.cond_br %100, ^bb12, ^bb13
      ^bb12:
        llvm.store %arg2, %97 : i64, !llvm.ptr
        cf.br ^bb14
      ^bb13:
        cf.br ^bb14
      ^bb14:
      %102 = llvm.load %89 : !llvm.ptr -> i64
      %103 = arith.constant 2 : i32
      %105 = arith.extsi %103 : i32 to i64
      %104 = arith.cmpi eq, %102, %105 : i64
      cf.cond_br %104, ^bb15, ^bb16
      ^bb15:
        llvm.store %arg3, %97 : i64, !llvm.ptr
        cf.br ^bb17
      ^bb16:
        cf.br ^bb17
      ^bb17:
      %106 = llvm.load %89 : !llvm.ptr -> i64
      %107 = arith.constant 3 : i32
      %109 = arith.extsi %107 : i32 to i64
      %108 = arith.cmpi eq, %106, %109 : i64
      cf.cond_br %108, ^bb18, ^bb19
      ^bb18:
        llvm.store %arg4, %97 : i64, !llvm.ptr
        cf.br ^bb20
      ^bb19:
        cf.br ^bb20
      ^bb20:
      %110 = llvm.load %89 : !llvm.ptr -> i64
      %111 = arith.constant 4 : i32
      %113 = arith.extsi %111 : i32 to i64
      %112 = arith.cmpi eq, %110, %113 : i64
      cf.cond_br %112, ^bb21, ^bb22
      ^bb21:
        llvm.store %arg5, %97 : i64, !llvm.ptr
        cf.br ^bb23
      ^bb22:
        cf.br ^bb23
      ^bb23:
      %114 = llvm.load %97 : !llvm.ptr -> i64
      %115 = arith.constant 0 : i32
      %117 = arith.extsi %115 : i32 to i64
      %116 = arith.cmpi sgt, %114, %117 : i64
      cf.cond_br %116, ^bb24, ^bb25
      ^bb24:
        %118 = llvm.mlir.constant(1 : i64) : i64
        %119 = llvm.alloca %118 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg1, %119 : i64, !llvm.ptr
        %120 = llvm.mlir.constant(1 : i64) : i64
        %121 = llvm.alloca %120 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg2, %121 : i64, !llvm.ptr
        %122 = llvm.mlir.constant(1 : i64) : i64
        %123 = llvm.alloca %122 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg3, %123 : i64, !llvm.ptr
        %124 = llvm.mlir.constant(1 : i64) : i64
        %125 = llvm.alloca %124 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg4, %125 : i64, !llvm.ptr
        %126 = llvm.mlir.constant(1 : i64) : i64
        %127 = llvm.alloca %126 x i64 : (i64) -> !llvm.ptr
        llvm.store %arg5, %127 : i64, !llvm.ptr
        %128 = llvm.load %89 : !llvm.ptr -> i64
        %129 = arith.constant 1 : i32
        %131 = arith.extsi %129 : i32 to i64
        %130 = arith.cmpi eq, %128, %131 : i64
        cf.cond_br %130, ^bb27, ^bb28
        ^bb27:
          %132 = llvm.load %121 : !llvm.ptr -> i64
          %133 = arith.constant 1 : i32
          %135 = arith.extsi %133 : i32 to i64
          %134 = arith.subi %132, %135 : i64
          llvm.store %134, %121 : i64, !llvm.ptr
          cf.br ^bb29
        ^bb28:
          cf.br ^bb29
        ^bb29:
        %136 = llvm.load %89 : !llvm.ptr -> i64
        %137 = arith.constant 2 : i32
        %139 = arith.extsi %137 : i32 to i64
        %138 = arith.cmpi eq, %136, %139 : i64
        cf.cond_br %138, ^bb30, ^bb31
        ^bb30:
          %140 = llvm.load %123 : !llvm.ptr -> i64
          %141 = arith.constant 1 : i32
          %143 = arith.extsi %141 : i32 to i64
          %142 = arith.subi %140, %143 : i64
          llvm.store %142, %123 : i64, !llvm.ptr
          cf.br ^bb32
        ^bb31:
          cf.br ^bb32
        ^bb32:
        %144 = llvm.load %89 : !llvm.ptr -> i64
        %145 = arith.constant 3 : i32
        %147 = arith.extsi %145 : i32 to i64
        %146 = arith.cmpi eq, %144, %147 : i64
        cf.cond_br %146, ^bb33, ^bb34
        ^bb33:
          %148 = llvm.load %125 : !llvm.ptr -> i64
          %149 = arith.constant 1 : i32
          %151 = arith.extsi %149 : i32 to i64
          %150 = arith.subi %148, %151 : i64
          llvm.store %150, %125 : i64, !llvm.ptr
          cf.br ^bb35
        ^bb34:
          cf.br ^bb35
        ^bb35:
        %152 = llvm.load %89 : !llvm.ptr -> i64
        %153 = arith.constant 4 : i32
        %155 = arith.extsi %153 : i32 to i64
        %154 = arith.cmpi eq, %152, %155 : i64
        cf.cond_br %154, ^bb36, ^bb37
        ^bb36:
          %156 = llvm.load %127 : !llvm.ptr -> i64
          %157 = arith.constant 1 : i32
          %159 = arith.extsi %157 : i32 to i64
          %158 = arith.subi %156, %159 : i64
          llvm.store %158, %127 : i64, !llvm.ptr
          cf.br ^bb38
        ^bb37:
          cf.br ^bb38
        ^bb38:
        %160 = arith.constant 0 : i32
        %162 = arith.extsi %160 : i32 to i64
        %161 = arith.cmpi eq, %arg0, %162 : i64
        cf.cond_br %161, ^bb39, ^bb40
        ^bb39:
          %163 = llvm.load %119 : !llvm.ptr -> i64
          %164 = arith.constant 1 : i32
          %166 = arith.extsi %164 : i32 to i64
          %165 = arith.addi %163, %166 : i64
          llvm.store %165, %119 : i64, !llvm.ptr
          cf.br ^bb41
        ^bb40:
          cf.br ^bb41
        ^bb41:
        %167 = arith.constant 1 : i32
        %169 = arith.extsi %167 : i32 to i64
        %168 = arith.cmpi eq, %arg0, %169 : i64
        cf.cond_br %168, ^bb42, ^bb43
        ^bb42:
          %170 = llvm.load %121 : !llvm.ptr -> i64
          %171 = arith.constant 1 : i32
          %173 = arith.extsi %171 : i32 to i64
          %172 = arith.addi %170, %173 : i64
          llvm.store %172, %121 : i64, !llvm.ptr
          cf.br ^bb44
        ^bb43:
          cf.br ^bb44
        ^bb44:
        %174 = arith.constant 2 : i32
        %176 = arith.extsi %174 : i32 to i64
        %175 = arith.cmpi eq, %arg0, %176 : i64
        cf.cond_br %175, ^bb45, ^bb46
        ^bb45:
          %177 = llvm.load %123 : !llvm.ptr -> i64
          %178 = arith.constant 1 : i32
          %180 = arith.extsi %178 : i32 to i64
          %179 = arith.addi %177, %180 : i64
          llvm.store %179, %123 : i64, !llvm.ptr
          cf.br ^bb47
        ^bb46:
          cf.br ^bb47
        ^bb47:
        %181 = arith.constant 3 : i32
        %183 = arith.extsi %181 : i32 to i64
        %182 = arith.cmpi eq, %arg0, %183 : i64
        cf.cond_br %182, ^bb48, ^bb49
        ^bb48:
          %184 = llvm.load %125 : !llvm.ptr -> i64
          %185 = arith.constant 1 : i32
          %187 = arith.extsi %185 : i32 to i64
          %186 = arith.addi %184, %187 : i64
          llvm.store %186, %125 : i64, !llvm.ptr
          cf.br ^bb50
        ^bb49:
          cf.br ^bb50
        ^bb50:
        %188 = arith.constant 4 : i32
        %190 = arith.extsi %188 : i32 to i64
        %189 = arith.cmpi eq, %arg0, %190 : i64
        cf.cond_br %189, ^bb51, ^bb52
        ^bb51:
          %191 = llvm.load %127 : !llvm.ptr -> i64
          %192 = arith.constant 1 : i32
          %194 = arith.extsi %192 : i32 to i64
          %193 = arith.addi %191, %194 : i64
          llvm.store %193, %127 : i64, !llvm.ptr
          cf.br ^bb53
        ^bb52:
          cf.br ^bb53
        ^bb53:
        %196 = llvm.load %89 : !llvm.ptr -> i64
        %197 = arith.constant 1 : i32
        %199 = arith.extsi %197 : i32 to i64
        %198 = arith.subi %196, %199 : i64
        %200 = llvm.load %119 : !llvm.ptr -> i64
        %201 = llvm.load %121 : !llvm.ptr -> i64
        %202 = llvm.load %123 : !llvm.ptr -> i64
        %203 = llvm.load %125 : !llvm.ptr -> i64
        %204 = llvm.load %127 : !llvm.ptr -> i64
        %195 = func.call @expected_additional(%198, %200, %201, %202, %203, %204) : (i64, i64, i64, i64, i64, i64) -> f64
        %205 = llvm.load %85 : !llvm.ptr -> f64
        %206 = llvm.load %89 : !llvm.ptr -> i64
        %207 = arith.sitofp %206 : i64 to f64
        %208 = llvm.load %97 : !llvm.ptr -> i64
        %209 = arith.sitofp %208 : i64 to f64
        %210 = arith.mulf %207, %209 : f64
        %211 = arith.sitofp %35 : i64 to f64
        %212 = arith.divf %210, %211 : f64
        %213 = arith.mulf %212, %195 : f64
        %214 = arith.addf %205, %213 : f64
        llvm.store %214, %85 : f64, !llvm.ptr
        cf.br ^bb26
      ^bb25:
        cf.br ^bb26
      ^bb26:
      %215 = llvm.load %89 : !llvm.ptr -> i64
      %216 = arith.constant 1 : i32
      %218 = arith.extsi %216 : i32 to i64
      %217 = arith.addi %215, %218 : i64
      llvm.store %217, %89 : i64, !llvm.ptr
      cf.br ^bb9
    ^bb11:
    %219 = arith.constant 1 : i32
    %220 = llvm.mlir.addressof @used : !llvm.ptr
    %221 = llvm.load %220 : !llvm.ptr -> !llvm.ptr
    %222 = llvm.load %52 : !llvm.ptr -> i64
    %223 = arith.trunci %219 : i32 to i8
    %224 = llvm.getelementptr %221[%222] : (!llvm.ptr, i64) -> !llvm.ptr, i8
    llvm.store %223, %224 : i8, !llvm.ptr
    %225 = llvm.mlir.addressof @keys : !llvm.ptr
    %226 = llvm.load %225 : !llvm.ptr -> !llvm.ptr
    %227 = llvm.load %52 : !llvm.ptr -> i64
    %228 = llvm.getelementptr %226[%227] : (!llvm.ptr, i64) -> !llvm.ptr, i64
    llvm.store %41, %228 : i64, !llvm.ptr
    %229 = llvm.load %85 : !llvm.ptr -> f64
    %230 = llvm.mlir.addressof @vals : !llvm.ptr
    %231 = llvm.load %230 : !llvm.ptr -> !llvm.ptr
    %232 = llvm.load %52 : !llvm.ptr -> i64
    %233 = llvm.getelementptr %231[%232] : (!llvm.ptr, i64) -> !llvm.ptr, f64
    llvm.store %229, %233 : f64, !llvm.ptr
    %234 = llvm.load %85 : !llvm.ptr -> f64
    func.return %234 : f64
  }
  func.func @main() -> i32 {
    %236 = llvm.mlir.addressof @HASH_N : !llvm.ptr
    %237 = llvm.load %236 : !llvm.ptr -> i64
    %238 = arith.constant 8 : i32
    %239 = arith.extsi %238 : i32 to i64
    %235 = func.call @calloc(%237, %239) : (i64, i64) -> !llvm.ptr
    %240 = llvm.mlir.addressof @keys : !llvm.ptr
    llvm.store %235, %240 : !llvm.ptr, !llvm.ptr
    %242 = llvm.mlir.addressof @HASH_N : !llvm.ptr
    %243 = llvm.load %242 : !llvm.ptr -> i64
    %244 = arith.constant 8 : i32
    %245 = arith.extsi %244 : i32 to i64
    %241 = func.call @calloc(%243, %245) : (i64, i64) -> !llvm.ptr
    %246 = llvm.mlir.addressof @vals : !llvm.ptr
    llvm.store %241, %246 : !llvm.ptr, !llvm.ptr
    %248 = llvm.mlir.addressof @HASH_N : !llvm.ptr
    %249 = llvm.load %248 : !llvm.ptr -> i64
    %250 = arith.constant 1 : i32
    %251 = arith.extsi %250 : i32 to i64
    %247 = func.call @calloc(%249, %251) : (i64, i64) -> !llvm.ptr
    %252 = llvm.mlir.addressof @used : !llvm.ptr
    llvm.store %247, %252 : !llvm.ptr, !llvm.ptr
    %253 = arith.constant 1.0 : f32
    %255 = arith.constant 3 : i32
    %256 = arith.constant 0 : i32
    %257 = arith.constant 0 : i32
    %258 = arith.constant 0 : i32
    %259 = arith.constant 0 : i32
    %260 = arith.constant 12 : i32
    %261 = arith.extsi %255 : i32 to i64
    %262 = arith.extsi %256 : i32 to i64
    %263 = arith.extsi %257 : i32 to i64
    %264 = arith.extsi %258 : i32 to i64
    %265 = arith.extsi %259 : i32 to i64
    %266 = arith.extsi %260 : i32 to i64
    %254 = func.call @expected_additional(%261, %262, %263, %264, %265, %266) : (i64, i64, i64, i64, i64, i64) -> f64
    %268 = arith.extf %253 : f32 to f64
    %267 = arith.addf %268, %254 : f64
    %269 = llvm.mlir.addressof @str_0 : !llvm.ptr
    %270 = llvm.call @printf(%269, %267) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
    %272 = llvm.mlir.addressof @keys : !llvm.ptr
    %273 = llvm.load %272 : !llvm.ptr -> !llvm.ptr
    func.call @free(%273) : (!llvm.ptr) -> ()
    %275 = llvm.mlir.addressof @vals : !llvm.ptr
    %276 = llvm.load %275 : !llvm.ptr -> !llvm.ptr
    func.call @free(%276) : (!llvm.ptr) -> ()
    %278 = llvm.mlir.addressof @used : !llvm.ptr
    %279 = llvm.load %278 : !llvm.ptr -> !llvm.ptr
    func.call @free(%279) : (!llvm.ptr) -> ()
    %280 = arith.constant 0 : i32
    func.return %280 : i32
  }
}