Problem 610
Roman Numerals II: expected value of minimal Roman process. Ported from native C++ to pure Flow.
View problem on Project Euler
Performance comparison
| Metric | Our solution | Best known |
| Time complexity | O(n^2) | O(n * s^2) |
| Space complexity | O(1) | O(s^2) |
| Approach | Flow solution | Markov chain or DP over states |
| Verdict | Unknown |
Flow source
# Project Euler 610
# Roman Numerals II: expected value of minimal Roman process.
# Ported from native C++ to pure Flow.
extern {
function calloc(n: i64, size: i64) -> ptr<void>
function free(p: ptr<void>) -> void
function pow(base: f64, exp: f64) -> f64
}
const Terminal: f64 = 0.02
const AnyLetter: f64 = 0.14
# Encoding: each char is 3 bits (I=1,V=2,X=3,L=4,C=5,D=6,M=7).
# Chars packed from LSB. Length stored in bits 45-50.
const CHAR_MASK: i64 = 0x1FFFFFFFFFFF
let mut n2r: ptr<i64> = null as ptr<i64>
let mut next_arr: ptr<i32> = null as ptr<i32>
let mut next_cnt: ptr<i32> = null as ptr<i32>
let mut memo: ptr<f64> = null as ptr<f64>
let mut memo_ok: ptr<i8> = null as ptr<i8>
function char_value(code: i32) -> i32 {
if code == 1 { return 1 }
if code == 2 { return 5 }
if code == 3 { return 10 }
if code == 4 { return 50 }
if code == 5 { return 100 }
if code == 6 { return 500 }
return 1000
}
function encode_roman(n: i32) -> i64 {
let mut enc: i64 = 0
let mut pos: i32 = 0
while n >= 1000 {
enc = enc | ((7 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 1000
}
if n >= 900 {
enc = enc | ((5 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((7 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 900
}
if n >= 500 {
enc = enc | ((6 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 500
}
if n >= 400 {
enc = enc | ((5 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((6 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 400
}
while n >= 100 {
enc = enc | ((5 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 100
}
if n >= 90 {
enc = enc | ((3 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((5 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 90
}
if n >= 50 {
enc = enc | ((4 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 50
}
if n >= 40 {
enc = enc | ((3 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((4 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 40
}
while n >= 10 {
enc = enc | ((3 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 10
}
if n >= 9 {
enc = enc | ((1 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((3 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 9
}
if n >= 5 {
enc = enc | ((2 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 5
}
if n >= 4 {
enc = enc | ((1 as i64) << ((pos as i64) * 3))
pos = pos + 1
enc = enc | ((2 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 4
}
while n >= 1 {
enc = enc | ((1 as i64) << ((pos as i64) * 3))
pos = pos + 1
n = n - 1
}
enc = enc | ((pos as i64) << 45)
return enc
}
function decode_roman(enc: i64) -> i32 {
let len: i32 = ((enc >> 45) & 0x3F) as i32
let mut result: i32 = 0
let mut last: i32 = 0
let mut subtract: bool = false
let mut i: i32 = len - 1
while i >= 0 {
let code: i32 = ((enc >> ((i as i64) * 3)) & 7) as i32
let current: i32 = char_value(code)
if current < last {
subtract = true
last = current
} else {
if current > last {
subtract = false
last = current
}
}
if subtract {
result = result - current
} else {
result = result + current
}
i = i - 1
}
return result
}
function build_transitions() -> void {
let mut i: i32 = 0
while i < 1000 {
next_cnt[i] = 0
let base_enc: i64 = n2r[i]
let base_len: i32 = ((base_enc >> 45) & 0x3F) as i32
let base_chars: i64 = base_enc & CHAR_MASK
let mut letter: i32 = 1
while letter <= 7 {
let new_enc: i64 = base_chars | ((letter as i64) << ((base_len as i64) * 3))
let new_len: i32 = base_len + 1
new_enc = new_enc | ((new_len as i64) << 45)
let num: i32 = decode_roman(new_enc)
let check_enc: i64 = encode_roman(num)
if check_enc == new_enc {
let idx: i32 = next_cnt[i]
next_arr[i * 7 + idx] = num
next_cnt[i] = idx + 1
}
letter = letter + 1
}
i = i + 1
}
}
function search(current: i32) -> f64 {
if memo_ok[current] != 0 { return memo[current] }
if next_cnt[current] == 0 {
memo_ok[current] = 1
memo[current] = current as f64
return current as f64
}
let mut result: f64 = Terminal * (current as f64)
let mut percentages: f64 = Terminal
let mut j: i32 = 0
while j < next_cnt[current] {
let next_num: i32 = next_arr[current * 7 + j]
result = result + AnyLetter * search(next_num)
percentages = percentages + AnyLetter
j = j + 1
}
result = result / percentages
memo_ok[current] = 1
memo[current] = result
return result
}
function main() -> i32 {
n2r = calloc(1000, 8) as ptr<i64>
next_arr = calloc(7000, 4) as ptr<i32>
next_cnt = calloc(1000, 4) as ptr<i32>
memo = calloc(1000, 8) as ptr<f64>
memo_ok = calloc(1000, 1) as ptr<i8>
let mut i: i32 = 0
while i < 1000 {
n2r[i] = encode_roman(i)
i = i + 1
}
build_transitions()
let mut upTo1000: f64 = 0.0
upTo1000 = upTo1000 + AnyLetter * search(1)
upTo1000 = upTo1000 + AnyLetter * search(5)
upTo1000 = upTo1000 + AnyLetter * search(10)
upTo1000 = upTo1000 + AnyLetter * search(50)
upTo1000 = upTo1000 + AnyLetter * search(100)
upTo1000 = upTo1000 + AnyLetter * search(500)
let precision: f64 = 0.000000001
let mut numM: i32 = 1
let mut result: f64 = upTo1000
let mut done: bool = false
while !done {
let manyM: f64 = (numM as f64) * 1000.0 * (1.0 - AnyLetter)
let increment: f64 = manyM + upTo1000
let term: f64 = increment * pow(AnyLetter, numM as f64)
result = result + term
if term < precision {
done = true
} else {
numM = numM + 1
}
}
printf("%.8f\n", result)
free(n2r as ptr<void>)
free(next_arr as ptr<void>)
free(next_cnt as ptr<void>)
free(memo as ptr<void>)
free(memo_ok as ptr<void>)
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 char_value_i32(int32_t code);
int64_t encode_roman_i32(int32_t n);
int32_t decode_roman_i64(int64_t enc);
void build_transitions(void);
double search_i32(int32_t current);
int32_t main(void);
static const double Terminal = 0.02;
static const double AnyLetter = 0.14;
static const int64_t CHAR_MASK = 35184372088831;
/* Module statics */
static int64_t* n2r = ((int64_t*)(NULL));
static int32_t* next_arr = ((int32_t*)(NULL));
static int32_t* next_cnt = ((int32_t*)(NULL));
static double* memo = ((double*)(NULL));
static int8_t* memo_ok = ((int8_t*)(NULL));
int32_t char_value_i32(int32_t code) {
if (code == 1) {
return 1;
}
if (code == 2) {
return 5;
}
if (code == 3) {
return 10;
}
if (code == 4) {
return 50;
}
if (code == 5) {
return 100;
}
if (code == 6) {
return 500;
}
return 1000;
}
int64_t encode_roman_i32(int32_t n) {
int64_t enc = 0;
int32_t pos = 0;
while (n >= 1000) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(7))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 1000);
}
if (n >= 900) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(5))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(7))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 900);
}
if (n >= 500) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(6))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 500);
}
if (n >= 400) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(5))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(6))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 400);
}
while (n >= 100) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(5))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 100);
}
if (n >= 90) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(3))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(5))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 90);
}
if (n >= 50) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(4))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 50);
}
if (n >= 40) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(3))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(4))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 40);
}
while (n >= 10) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(3))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 10);
}
if (n >= 9) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(1))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(3))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 9);
}
if (n >= 5) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(2))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 5);
}
if (n >= 4) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(1))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(2))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 4);
}
while (n >= 1) {
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(1))), ((((int64_t)(pos)) * 3))));
pos = (pos + 1);
n = (n - 1);
}
enc = (enc | FLOW_CHECKED_SHL((((int64_t)(pos))), (45)));
return enc;
}
int32_t decode_roman_i64(int64_t enc) {
int32_t len = ((int32_t)((FLOW_CHECKED_SHR((enc), (45)) & 63)));
int32_t result = 0;
int32_t last = 0;
bool subtract = 0;
int32_t i = (len - 1);
while (i >= 0) {
int32_t code = ((int32_t)((FLOW_CHECKED_SHR((enc), ((((int64_t)(i)) * 3))) & 7)));
int32_t current = char_value_i32(code);
if (current < last) {
subtract = 1;
last = current;
} else {
if (current > last) {
subtract = 0;
last = current;
}
}
if (subtract) {
result = (result - current);
} else {
result = (result + current);
}
i = (i - 1);
}
return result;
}
void build_transitions(void) {
int32_t i = 0;
while (i < 1000) {
next_cnt[i] = 0;
int64_t base_enc = n2r[i];
int32_t base_len = ((int32_t)((FLOW_CHECKED_SHR((base_enc), (45)) & 63)));
int64_t base_chars = (base_enc & CHAR_MASK);
int32_t letter = 1;
while (letter <= 7) {
int64_t new_enc = (base_chars | FLOW_CHECKED_SHL((((int64_t)(letter))), ((((int64_t)(base_len)) * 3))));
int32_t new_len = (base_len + 1);
new_enc = (new_enc | FLOW_CHECKED_SHL((((int64_t)(new_len))), (45)));
int32_t num = decode_roman_i64(new_enc);
int64_t check_enc = encode_roman_i32(num);
if (check_enc == new_enc) {
int32_t idx = next_cnt[i];
next_arr[((i * 7) + idx)] = num;
next_cnt[i] = (idx + 1);
}
letter = (letter + 1);
}
i = (i + 1);
}
}
double search_i32(int32_t current) {
if (memo_ok[current] != 0) {
return memo[current];
}
if (next_cnt[current] == 0) {
memo_ok[current] = 1;
memo[current] = ((double)(current));
return ((double)(current));
}
double result = (Terminal * ((double)(current)));
double percentages = Terminal;
int32_t j = 0;
while (j < next_cnt[current]) {
int32_t next_num = next_arr[((current * 7) + j)];
result = (result + (AnyLetter * search_i32(next_num)));
percentages = (percentages + AnyLetter);
j = (j + 1);
}
result = (result / percentages);
memo_ok[current] = 1;
memo[current] = result;
return result;
}
int32_t main(void) {
n2r = ((int64_t*)(calloc(1000, 8)));
next_arr = ((int32_t*)(calloc(7000, 4)));
next_cnt = ((int32_t*)(calloc(1000, 4)));
memo = ((double*)(calloc(1000, 8)));
memo_ok = ((int8_t*)(calloc(1000, 1)));
int32_t i = 0;
while (i < 1000) {
n2r[i] = encode_roman_i32(i);
i = (i + 1);
}
build_transitions();
double upTo1000 = 0.0;
upTo1000 = (upTo1000 + (AnyLetter * search_i32(1)));
upTo1000 = (upTo1000 + (AnyLetter * search_i32(5)));
upTo1000 = (upTo1000 + (AnyLetter * search_i32(10)));
upTo1000 = (upTo1000 + (AnyLetter * search_i32(50)));
upTo1000 = (upTo1000 + (AnyLetter * search_i32(100)));
upTo1000 = (upTo1000 + (AnyLetter * search_i32(500)));
double precision = 0.000000001;
int32_t numM = 1;
double result = upTo1000;
bool done = 0;
while ((!(done))) {
double manyM = ((((double)(numM)) * 1000.0) * (1.0 - AnyLetter));
double increment = (manyM + upTo1000);
double term = (increment * pow(AnyLetter, ((double)(numM))));
result = (result + term);
if (term < precision) {
done = 1;
} else {
numM = (numM + 1);
}
}
printf("%.8f\n", result);
free(((void*)(n2r)));
free(((void*)(next_arr)));
free(((void*)(next_cnt)));
free(((void*)(memo)));
free(((void*)(memo_ok)));
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) -> ()
func.func private @pow(f64, f64) -> f64
// Constant: Terminal
llvm.mlir.global internal constant @Terminal(0.02 : f64) : f64
// Constant: AnyLetter
llvm.mlir.global internal constant @AnyLetter(0.14 : f64) : f64
// Constant: CHAR_MASK
llvm.mlir.global internal constant @CHAR_MASK(35184372088831 : i64) : i64
// Module static: n2r
llvm.mlir.global internal @n2r() {addr_space = 0 : i32} : !llvm.ptr {
%0 = llvm.mlir.zero : !llvm.ptr
llvm.return %0 : !llvm.ptr
}
// Module static: next_arr
llvm.mlir.global internal @next_arr() {addr_space = 0 : i32} : !llvm.ptr {
%1 = llvm.mlir.zero : !llvm.ptr
llvm.return %1 : !llvm.ptr
}
// Module static: next_cnt
llvm.mlir.global internal @next_cnt() {addr_space = 0 : i32} : !llvm.ptr {
%2 = llvm.mlir.zero : !llvm.ptr
llvm.return %2 : !llvm.ptr
}
// Module static: memo
llvm.mlir.global internal @memo() {addr_space = 0 : i32} : !llvm.ptr {
%3 = llvm.mlir.zero : !llvm.ptr
llvm.return %3 : !llvm.ptr
}
// Module static: memo_ok
llvm.mlir.global internal @memo_ok() {addr_space = 0 : i32} : !llvm.ptr {
%4 = llvm.mlir.zero : !llvm.ptr
llvm.return %4 : !llvm.ptr
}
func.func @char_value(%arg0: i32) -> i32 {
%5 = arith.constant 1 : i32
%6 = arith.cmpi eq, %arg0, %5 : i32
cf.cond_br %6, ^bb0, ^bb1
^bb0:
%7 = arith.constant 1 : i32
func.return %7 : i32
^bb1:
cf.br ^bb2
^bb2:
%8 = arith.constant 2 : i32
%9 = arith.cmpi eq, %arg0, %8 : i32
cf.cond_br %9, ^bb3, ^bb4
^bb3:
%10 = arith.constant 5 : i32
func.return %10 : i32
^bb4:
cf.br ^bb5
^bb5:
%11 = arith.constant 3 : i32
%12 = arith.cmpi eq, %arg0, %11 : i32
cf.cond_br %12, ^bb6, ^bb7
^bb6:
%13 = arith.constant 10 : i32
func.return %13 : i32
^bb7:
cf.br ^bb8
^bb8:
%14 = arith.constant 4 : i32
%15 = arith.cmpi eq, %arg0, %14 : i32
cf.cond_br %15, ^bb9, ^bb10
^bb9:
%16 = arith.constant 50 : i32
func.return %16 : i32
^bb10:
cf.br ^bb11
^bb11:
%17 = arith.constant 5 : i32
%18 = arith.cmpi eq, %arg0, %17 : i32
cf.cond_br %18, ^bb12, ^bb13
^bb12:
%19 = arith.constant 100 : i32
func.return %19 : i32
^bb13:
cf.br ^bb14
^bb14:
%20 = arith.constant 6 : i32
%21 = arith.cmpi eq, %arg0, %20 : i32
cf.cond_br %21, ^bb15, ^bb16
^bb15:
%22 = arith.constant 500 : i32
func.return %22 : i32
^bb16:
cf.br ^bb17
^bb17:
%23 = arith.constant 1000 : i32
func.return %23 : i32
}
func.func @encode_roman(%arg0: i32) -> i64 {
%24 = arith.constant 0 : i32
%25 = arith.extsi %24 : i32 to i64
%26 = llvm.mlir.constant(1 : i64) : i64
%27 = llvm.alloca %26 x i64 : (i64) -> !llvm.ptr
llvm.store %25, %27 : i64, !llvm.ptr
%28 = arith.constant 0 : 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 ^bb18(%arg0 : i32)
^bb18(%31: i32):
%32 = arith.constant 1000 : i32
%33 = arith.cmpi sge, %31, %32 : i32
cf.cond_br %33, ^bb19(%31 : i32), ^bb20(%31 : i32)
^bb19(%34: i32):
%35 = llvm.load %27 : !llvm.ptr -> i64
%36 = arith.constant 7 : i32
%37 = arith.extsi %36 : i32 to i64
%38 = llvm.load %30 : !llvm.ptr -> i32
%39 = arith.extsi %38 : i32 to i64
%40 = arith.constant 3 : i32
%42 = arith.extsi %40 : i32 to i64
%41 = arith.muli %39, %42 : i64
%43 = arith.shli %37, %41 : i64
%44 = arith.ori %35, %43 : i64
llvm.store %44, %27 : i64, !llvm.ptr
%45 = llvm.load %30 : !llvm.ptr -> i32
%46 = arith.constant 1 : i32
%47 = arith.addi %45, %46 : i32
llvm.store %47, %30 : i32, !llvm.ptr
%48 = arith.constant 1000 : i32
%49 = arith.subi %34, %48 : i32
cf.br ^bb18(%49 : i32)
^bb20(%50: i32):
%51 = arith.constant 900 : i32
%52 = arith.cmpi sge, %50, %51 : i32
%53 = scf.if %52 -> (i32) {
%54 = llvm.load %27 : !llvm.ptr -> i64
%55 = arith.constant 5 : i32
%56 = arith.extsi %55 : i32 to i64
%57 = llvm.load %30 : !llvm.ptr -> i32
%58 = arith.extsi %57 : i32 to i64
%59 = arith.constant 3 : i32
%61 = arith.extsi %59 : i32 to i64
%60 = arith.muli %58, %61 : i64
%62 = arith.shli %56, %60 : i64
%63 = arith.ori %54, %62 : i64
llvm.store %63, %27 : i64, !llvm.ptr
%64 = llvm.load %30 : !llvm.ptr -> i32
%65 = arith.constant 1 : i32
%66 = arith.addi %64, %65 : i32
llvm.store %66, %30 : i32, !llvm.ptr
%67 = llvm.load %27 : !llvm.ptr -> i64
%68 = arith.constant 7 : i32
%69 = arith.extsi %68 : i32 to i64
%70 = llvm.load %30 : !llvm.ptr -> i32
%71 = arith.extsi %70 : i32 to i64
%72 = arith.constant 3 : i32
%74 = arith.extsi %72 : i32 to i64
%73 = arith.muli %71, %74 : i64
%75 = arith.shli %69, %73 : i64
%76 = arith.ori %67, %75 : i64
llvm.store %76, %27 : i64, !llvm.ptr
%77 = llvm.load %30 : !llvm.ptr -> i32
%78 = arith.constant 1 : i32
%79 = arith.addi %77, %78 : i32
llvm.store %79, %30 : i32, !llvm.ptr
%80 = arith.constant 900 : i32
%81 = arith.subi %50, %80 : i32
scf.yield %81 : i32
} else {
scf.yield %50 : i32
}
%82 = arith.constant 500 : i32
%83 = arith.cmpi sge, %53, %82 : i32
%84 = scf.if %83 -> (i32) {
%85 = llvm.load %27 : !llvm.ptr -> i64
%86 = arith.constant 6 : i32
%87 = arith.extsi %86 : i32 to i64
%88 = llvm.load %30 : !llvm.ptr -> i32
%89 = arith.extsi %88 : i32 to i64
%90 = arith.constant 3 : i32
%92 = arith.extsi %90 : i32 to i64
%91 = arith.muli %89, %92 : i64
%93 = arith.shli %87, %91 : i64
%94 = arith.ori %85, %93 : i64
llvm.store %94, %27 : i64, !llvm.ptr
%95 = llvm.load %30 : !llvm.ptr -> i32
%96 = arith.constant 1 : i32
%97 = arith.addi %95, %96 : i32
llvm.store %97, %30 : i32, !llvm.ptr
%98 = arith.constant 500 : i32
%99 = arith.subi %53, %98 : i32
scf.yield %99 : i32
} else {
scf.yield %53 : i32
}
%100 = arith.constant 400 : i32
%101 = arith.cmpi sge, %84, %100 : i32
%102 = scf.if %101 -> (i32) {
%103 = llvm.load %27 : !llvm.ptr -> i64
%104 = arith.constant 5 : i32
%105 = arith.extsi %104 : i32 to i64
%106 = llvm.load %30 : !llvm.ptr -> i32
%107 = arith.extsi %106 : i32 to i64
%108 = arith.constant 3 : i32
%110 = arith.extsi %108 : i32 to i64
%109 = arith.muli %107, %110 : i64
%111 = arith.shli %105, %109 : i64
%112 = arith.ori %103, %111 : i64
llvm.store %112, %27 : i64, !llvm.ptr
%113 = llvm.load %30 : !llvm.ptr -> i32
%114 = arith.constant 1 : i32
%115 = arith.addi %113, %114 : i32
llvm.store %115, %30 : i32, !llvm.ptr
%116 = llvm.load %27 : !llvm.ptr -> i64
%117 = arith.constant 6 : i32
%118 = arith.extsi %117 : i32 to i64
%119 = llvm.load %30 : !llvm.ptr -> i32
%120 = arith.extsi %119 : i32 to i64
%121 = arith.constant 3 : i32
%123 = arith.extsi %121 : i32 to i64
%122 = arith.muli %120, %123 : i64
%124 = arith.shli %118, %122 : i64
%125 = arith.ori %116, %124 : i64
llvm.store %125, %27 : i64, !llvm.ptr
%126 = llvm.load %30 : !llvm.ptr -> i32
%127 = arith.constant 1 : i32
%128 = arith.addi %126, %127 : i32
llvm.store %128, %30 : i32, !llvm.ptr
%129 = arith.constant 400 : i32
%130 = arith.subi %84, %129 : i32
scf.yield %130 : i32
} else {
scf.yield %84 : i32
}
cf.br ^bb21(%102 : i32)
^bb21(%131: i32):
%132 = arith.constant 100 : i32
%133 = arith.cmpi sge, %131, %132 : i32
cf.cond_br %133, ^bb22(%131 : i32), ^bb23(%131 : i32)
^bb22(%134: i32):
%135 = llvm.load %27 : !llvm.ptr -> i64
%136 = arith.constant 5 : i32
%137 = arith.extsi %136 : i32 to i64
%138 = llvm.load %30 : !llvm.ptr -> i32
%139 = arith.extsi %138 : i32 to i64
%140 = arith.constant 3 : i32
%142 = arith.extsi %140 : i32 to i64
%141 = arith.muli %139, %142 : i64
%143 = arith.shli %137, %141 : i64
%144 = arith.ori %135, %143 : i64
llvm.store %144, %27 : i64, !llvm.ptr
%145 = llvm.load %30 : !llvm.ptr -> i32
%146 = arith.constant 1 : i32
%147 = arith.addi %145, %146 : i32
llvm.store %147, %30 : i32, !llvm.ptr
%148 = arith.constant 100 : i32
%149 = arith.subi %134, %148 : i32
cf.br ^bb21(%149 : i32)
^bb23(%150: i32):
%151 = arith.constant 90 : i32
%152 = arith.cmpi sge, %150, %151 : i32
%153 = scf.if %152 -> (i32) {
%154 = llvm.load %27 : !llvm.ptr -> i64
%155 = arith.constant 3 : i32
%156 = arith.extsi %155 : i32 to i64
%157 = llvm.load %30 : !llvm.ptr -> i32
%158 = arith.extsi %157 : i32 to i64
%159 = arith.constant 3 : i32
%161 = arith.extsi %159 : i32 to i64
%160 = arith.muli %158, %161 : i64
%162 = arith.shli %156, %160 : i64
%163 = arith.ori %154, %162 : i64
llvm.store %163, %27 : i64, !llvm.ptr
%164 = llvm.load %30 : !llvm.ptr -> i32
%165 = arith.constant 1 : i32
%166 = arith.addi %164, %165 : i32
llvm.store %166, %30 : i32, !llvm.ptr
%167 = llvm.load %27 : !llvm.ptr -> i64
%168 = arith.constant 5 : i32
%169 = arith.extsi %168 : i32 to i64
%170 = llvm.load %30 : !llvm.ptr -> i32
%171 = arith.extsi %170 : i32 to i64
%172 = arith.constant 3 : i32
%174 = arith.extsi %172 : i32 to i64
%173 = arith.muli %171, %174 : i64
%175 = arith.shli %169, %173 : i64
%176 = arith.ori %167, %175 : i64
llvm.store %176, %27 : i64, !llvm.ptr
%177 = llvm.load %30 : !llvm.ptr -> i32
%178 = arith.constant 1 : i32
%179 = arith.addi %177, %178 : i32
llvm.store %179, %30 : i32, !llvm.ptr
%180 = arith.constant 90 : i32
%181 = arith.subi %150, %180 : i32
scf.yield %181 : i32
} else {
scf.yield %150 : i32
}
%182 = arith.constant 50 : i32
%183 = arith.cmpi sge, %153, %182 : i32
%184 = scf.if %183 -> (i32) {
%185 = llvm.load %27 : !llvm.ptr -> i64
%186 = arith.constant 4 : i32
%187 = arith.extsi %186 : i32 to i64
%188 = llvm.load %30 : !llvm.ptr -> i32
%189 = arith.extsi %188 : i32 to i64
%190 = arith.constant 3 : i32
%192 = arith.extsi %190 : i32 to i64
%191 = arith.muli %189, %192 : i64
%193 = arith.shli %187, %191 : i64
%194 = arith.ori %185, %193 : i64
llvm.store %194, %27 : i64, !llvm.ptr
%195 = llvm.load %30 : !llvm.ptr -> i32
%196 = arith.constant 1 : i32
%197 = arith.addi %195, %196 : i32
llvm.store %197, %30 : i32, !llvm.ptr
%198 = arith.constant 50 : i32
%199 = arith.subi %153, %198 : i32
scf.yield %199 : i32
} else {
scf.yield %153 : i32
}
%200 = arith.constant 40 : i32
%201 = arith.cmpi sge, %184, %200 : i32
%202 = scf.if %201 -> (i32) {
%203 = llvm.load %27 : !llvm.ptr -> i64
%204 = arith.constant 3 : i32
%205 = arith.extsi %204 : i32 to i64
%206 = llvm.load %30 : !llvm.ptr -> i32
%207 = arith.extsi %206 : i32 to i64
%208 = arith.constant 3 : i32
%210 = arith.extsi %208 : i32 to i64
%209 = arith.muli %207, %210 : i64
%211 = arith.shli %205, %209 : i64
%212 = arith.ori %203, %211 : i64
llvm.store %212, %27 : i64, !llvm.ptr
%213 = llvm.load %30 : !llvm.ptr -> i32
%214 = arith.constant 1 : i32
%215 = arith.addi %213, %214 : i32
llvm.store %215, %30 : i32, !llvm.ptr
%216 = llvm.load %27 : !llvm.ptr -> i64
%217 = arith.constant 4 : i32
%218 = arith.extsi %217 : i32 to i64
%219 = llvm.load %30 : !llvm.ptr -> i32
%220 = arith.extsi %219 : i32 to i64
%221 = arith.constant 3 : i32
%223 = arith.extsi %221 : i32 to i64
%222 = arith.muli %220, %223 : i64
%224 = arith.shli %218, %222 : i64
%225 = arith.ori %216, %224 : i64
llvm.store %225, %27 : i64, !llvm.ptr
%226 = llvm.load %30 : !llvm.ptr -> i32
%227 = arith.constant 1 : i32
%228 = arith.addi %226, %227 : i32
llvm.store %228, %30 : i32, !llvm.ptr
%229 = arith.constant 40 : i32
%230 = arith.subi %184, %229 : i32
scf.yield %230 : i32
} else {
scf.yield %184 : i32
}
cf.br ^bb24(%202 : i32)
^bb24(%231: i32):
%232 = arith.constant 10 : i32
%233 = arith.cmpi sge, %231, %232 : i32
cf.cond_br %233, ^bb25(%231 : i32), ^bb26(%231 : i32)
^bb25(%234: i32):
%235 = llvm.load %27 : !llvm.ptr -> i64
%236 = arith.constant 3 : i32
%237 = arith.extsi %236 : i32 to i64
%238 = llvm.load %30 : !llvm.ptr -> i32
%239 = arith.extsi %238 : i32 to i64
%240 = arith.constant 3 : i32
%242 = arith.extsi %240 : i32 to i64
%241 = arith.muli %239, %242 : i64
%243 = arith.shli %237, %241 : i64
%244 = arith.ori %235, %243 : i64
llvm.store %244, %27 : i64, !llvm.ptr
%245 = llvm.load %30 : !llvm.ptr -> i32
%246 = arith.constant 1 : i32
%247 = arith.addi %245, %246 : i32
llvm.store %247, %30 : i32, !llvm.ptr
%248 = arith.constant 10 : i32
%249 = arith.subi %234, %248 : i32
cf.br ^bb24(%249 : i32)
^bb26(%250: i32):
%251 = arith.constant 9 : i32
%252 = arith.cmpi sge, %250, %251 : i32
%253 = scf.if %252 -> (i32) {
%254 = llvm.load %27 : !llvm.ptr -> i64
%255 = arith.constant 1 : i32
%256 = arith.extsi %255 : i32 to i64
%257 = llvm.load %30 : !llvm.ptr -> i32
%258 = arith.extsi %257 : i32 to i64
%259 = arith.constant 3 : i32
%261 = arith.extsi %259 : i32 to i64
%260 = arith.muli %258, %261 : i64
%262 = arith.shli %256, %260 : i64
%263 = arith.ori %254, %262 : i64
llvm.store %263, %27 : i64, !llvm.ptr
%264 = llvm.load %30 : !llvm.ptr -> i32
%265 = arith.constant 1 : i32
%266 = arith.addi %264, %265 : i32
llvm.store %266, %30 : i32, !llvm.ptr
%267 = llvm.load %27 : !llvm.ptr -> i64
%268 = arith.constant 3 : i32
%269 = arith.extsi %268 : i32 to i64
%270 = llvm.load %30 : !llvm.ptr -> i32
%271 = arith.extsi %270 : i32 to i64
%272 = arith.constant 3 : i32
%274 = arith.extsi %272 : i32 to i64
%273 = arith.muli %271, %274 : i64
%275 = arith.shli %269, %273 : i64
%276 = arith.ori %267, %275 : i64
llvm.store %276, %27 : i64, !llvm.ptr
%277 = llvm.load %30 : !llvm.ptr -> i32
%278 = arith.constant 1 : i32
%279 = arith.addi %277, %278 : i32
llvm.store %279, %30 : i32, !llvm.ptr
%280 = arith.constant 9 : i32
%281 = arith.subi %250, %280 : i32
scf.yield %281 : i32
} else {
scf.yield %250 : i32
}
%282 = arith.constant 5 : i32
%283 = arith.cmpi sge, %253, %282 : i32
%284 = scf.if %283 -> (i32) {
%285 = llvm.load %27 : !llvm.ptr -> i64
%286 = arith.constant 2 : i32
%287 = arith.extsi %286 : i32 to i64
%288 = llvm.load %30 : !llvm.ptr -> i32
%289 = arith.extsi %288 : i32 to i64
%290 = arith.constant 3 : i32
%292 = arith.extsi %290 : i32 to i64
%291 = arith.muli %289, %292 : i64
%293 = arith.shli %287, %291 : i64
%294 = arith.ori %285, %293 : i64
llvm.store %294, %27 : i64, !llvm.ptr
%295 = llvm.load %30 : !llvm.ptr -> i32
%296 = arith.constant 1 : i32
%297 = arith.addi %295, %296 : i32
llvm.store %297, %30 : i32, !llvm.ptr
%298 = arith.constant 5 : i32
%299 = arith.subi %253, %298 : i32
scf.yield %299 : i32
} else {
scf.yield %253 : i32
}
%300 = arith.constant 4 : i32
%301 = arith.cmpi sge, %284, %300 : i32
%302 = scf.if %301 -> (i32) {
%303 = llvm.load %27 : !llvm.ptr -> i64
%304 = arith.constant 1 : i32
%305 = arith.extsi %304 : i32 to i64
%306 = llvm.load %30 : !llvm.ptr -> i32
%307 = arith.extsi %306 : i32 to i64
%308 = arith.constant 3 : i32
%310 = arith.extsi %308 : i32 to i64
%309 = arith.muli %307, %310 : i64
%311 = arith.shli %305, %309 : i64
%312 = arith.ori %303, %311 : i64
llvm.store %312, %27 : i64, !llvm.ptr
%313 = llvm.load %30 : !llvm.ptr -> i32
%314 = arith.constant 1 : i32
%315 = arith.addi %313, %314 : i32
llvm.store %315, %30 : i32, !llvm.ptr
%316 = llvm.load %27 : !llvm.ptr -> i64
%317 = arith.constant 2 : i32
%318 = arith.extsi %317 : i32 to i64
%319 = llvm.load %30 : !llvm.ptr -> i32
%320 = arith.extsi %319 : i32 to i64
%321 = arith.constant 3 : i32
%323 = arith.extsi %321 : i32 to i64
%322 = arith.muli %320, %323 : i64
%324 = arith.shli %318, %322 : i64
%325 = arith.ori %316, %324 : i64
llvm.store %325, %27 : i64, !llvm.ptr
%326 = llvm.load %30 : !llvm.ptr -> i32
%327 = arith.constant 1 : i32
%328 = arith.addi %326, %327 : i32
llvm.store %328, %30 : i32, !llvm.ptr
%329 = arith.constant 4 : i32
%330 = arith.subi %284, %329 : i32
scf.yield %330 : i32
} else {
scf.yield %284 : i32
}
cf.br ^bb27(%302 : i32)
^bb27(%331: i32):
%332 = arith.constant 1 : i32
%333 = arith.cmpi sge, %331, %332 : i32
cf.cond_br %333, ^bb28(%331 : i32), ^bb29(%331 : i32)
^bb28(%334: i32):
%335 = llvm.load %27 : !llvm.ptr -> i64
%336 = arith.constant 1 : i32
%337 = arith.extsi %336 : i32 to i64
%338 = llvm.load %30 : !llvm.ptr -> i32
%339 = arith.extsi %338 : i32 to i64
%340 = arith.constant 3 : i32
%342 = arith.extsi %340 : i32 to i64
%341 = arith.muli %339, %342 : i64
%343 = arith.shli %337, %341 : i64
%344 = arith.ori %335, %343 : i64
llvm.store %344, %27 : i64, !llvm.ptr
%345 = llvm.load %30 : !llvm.ptr -> i32
%346 = arith.constant 1 : i32
%347 = arith.addi %345, %346 : i32
llvm.store %347, %30 : i32, !llvm.ptr
%348 = arith.constant 1 : i32
%349 = arith.subi %334, %348 : i32
cf.br ^bb27(%349 : i32)
^bb29(%350: i32):
%351 = llvm.load %27 : !llvm.ptr -> i64
%352 = llvm.load %30 : !llvm.ptr -> i32
%353 = arith.extsi %352 : i32 to i64
%354 = arith.constant 45 : i32
%356 = arith.extsi %354 : i32 to i64
%355 = arith.shli %353, %356 : i64
%357 = arith.ori %351, %355 : i64
llvm.store %357, %27 : i64, !llvm.ptr
%358 = llvm.load %27 : !llvm.ptr -> i64
func.return %358 : i64
}
func.func @decode_roman(%arg0: i64) -> i32 {
%359 = arith.constant 45 : i32
%361 = arith.extsi %359 : i32 to i64
%360 = arith.shrsi %arg0, %361 : i64
%362 = arith.constant 63 : i32
%364 = arith.extsi %362 : i32 to i64
%363 = arith.andi %360, %364 : i64
%365 = arith.trunci %363 : i64 to i32
%366 = arith.constant 0 : i32
%367 = llvm.mlir.constant(1 : i64) : i64
%368 = llvm.alloca %367 x i32 : (i64) -> !llvm.ptr
llvm.store %366, %368 : i32, !llvm.ptr
%369 = arith.constant 0 : i32
%370 = llvm.mlir.constant(1 : i64) : i64
%371 = llvm.alloca %370 x i32 : (i64) -> !llvm.ptr
llvm.store %369, %371 : i32, !llvm.ptr
%372 = arith.constant 0 : i1
%373 = llvm.mlir.constant(1 : i64) : i64
%374 = llvm.alloca %373 x i1 : (i64) -> !llvm.ptr
llvm.store %372, %374 : i1, !llvm.ptr
%375 = arith.constant 1 : i32
%376 = arith.subi %365, %375 : i32
%377 = llvm.mlir.constant(1 : i64) : i64
%378 = llvm.alloca %377 x i32 : (i64) -> !llvm.ptr
llvm.store %376, %378 : i32, !llvm.ptr
cf.br ^bb30
^bb30:
%379 = llvm.load %378 : !llvm.ptr -> i32
%380 = arith.constant 0 : i32
%381 = arith.cmpi sge, %379, %380 : i32
cf.cond_br %381, ^bb31, ^bb32
^bb31:
%382 = llvm.load %378 : !llvm.ptr -> i32
%383 = arith.extsi %382 : i32 to i64
%384 = arith.constant 3 : i32
%386 = arith.extsi %384 : i32 to i64
%385 = arith.muli %383, %386 : i64
%387 = arith.shrsi %arg0, %385 : i64
%388 = arith.constant 7 : i32
%390 = arith.extsi %388 : i32 to i64
%389 = arith.andi %387, %390 : i64
%391 = arith.trunci %389 : i64 to i32
%392 = func.call @char_value(%391) : (i32) -> i32
%393 = llvm.load %371 : !llvm.ptr -> i32
%394 = arith.cmpi slt, %392, %393 : i32
cf.cond_br %394, ^bb33, ^bb34
^bb33:
%395 = arith.constant 1 : i1
llvm.store %395, %374 : i1, !llvm.ptr
llvm.store %392, %371 : i32, !llvm.ptr
cf.br ^bb35
^bb34:
%396 = llvm.load %371 : !llvm.ptr -> i32
%397 = arith.cmpi sgt, %392, %396 : i32
cf.cond_br %397, ^bb36, ^bb37
^bb36:
%398 = arith.constant 0 : i1
llvm.store %398, %374 : i1, !llvm.ptr
llvm.store %392, %371 : i32, !llvm.ptr
cf.br ^bb38
^bb37:
cf.br ^bb38
^bb38:
cf.br ^bb35
^bb35:
%399 = llvm.load %374 : !llvm.ptr -> i1
cf.cond_br %399, ^bb39, ^bb40
^bb39:
%400 = llvm.load %368 : !llvm.ptr -> i32
%401 = arith.subi %400, %392 : i32
llvm.store %401, %368 : i32, !llvm.ptr
cf.br ^bb41
^bb40:
%402 = llvm.load %368 : !llvm.ptr -> i32
%403 = arith.addi %402, %392 : i32
llvm.store %403, %368 : i32, !llvm.ptr
cf.br ^bb41
^bb41:
%404 = llvm.load %378 : !llvm.ptr -> i32
%405 = arith.constant 1 : i32
%406 = arith.subi %404, %405 : i32
llvm.store %406, %378 : i32, !llvm.ptr
cf.br ^bb30
^bb32:
%407 = llvm.load %368 : !llvm.ptr -> i32
func.return %407 : i32
}
func.func @build_transitions() -> () {
%408 = arith.constant 0 : i32
%409 = llvm.mlir.constant(1 : i64) : i64
%410 = llvm.alloca %409 x i32 : (i64) -> !llvm.ptr
llvm.store %408, %410 : i32, !llvm.ptr
cf.br ^bb42
^bb42:
%411 = llvm.load %410 : !llvm.ptr -> i32
%412 = arith.constant 1000 : i32
%413 = arith.cmpi slt, %411, %412 : i32
cf.cond_br %413, ^bb43, ^bb44
^bb43:
%414 = arith.constant 0 : i32
%415 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%416 = llvm.load %415 : !llvm.ptr -> !llvm.ptr
%417 = llvm.load %410 : !llvm.ptr -> i32
%418 = arith.extsi %417 : i32 to i64
%419 = llvm.getelementptr %416[%418] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %414, %419 : i32, !llvm.ptr
%421 = llvm.mlir.addressof @n2r : !llvm.ptr
%422 = llvm.load %421 : !llvm.ptr -> !llvm.ptr
%423 = llvm.load %410 : !llvm.ptr -> i32
%424 = arith.extsi %423 : i32 to i64
%425 = llvm.getelementptr %422[%424] : (!llvm.ptr, i64) -> !llvm.ptr, i64
%420 = llvm.load %425 : !llvm.ptr -> i64
%426 = arith.constant 45 : i32
%428 = arith.extsi %426 : i32 to i64
%427 = arith.shrsi %420, %428 : i64
%429 = arith.constant 63 : i32
%431 = arith.extsi %429 : i32 to i64
%430 = arith.andi %427, %431 : i64
%432 = arith.trunci %430 : i64 to i32
%433 = llvm.mlir.addressof @CHAR_MASK : !llvm.ptr
%434 = llvm.load %433 : !llvm.ptr -> i64
%435 = arith.andi %420, %434 : i64
%436 = arith.constant 1 : i32
%437 = llvm.mlir.constant(1 : i64) : i64
%438 = llvm.alloca %437 x i32 : (i64) -> !llvm.ptr
llvm.store %436, %438 : i32, !llvm.ptr
cf.br ^bb45
^bb45:
%439 = llvm.load %438 : !llvm.ptr -> i32
%440 = arith.constant 7 : i32
%441 = arith.cmpi sle, %439, %440 : i32
cf.cond_br %441, ^bb46, ^bb47
^bb46:
%442 = llvm.load %438 : !llvm.ptr -> i32
%443 = arith.extsi %442 : i32 to i64
%444 = arith.extsi %432 : i32 to i64
%445 = arith.constant 3 : i32
%447 = arith.extsi %445 : i32 to i64
%446 = arith.muli %444, %447 : i64
%448 = arith.shli %443, %446 : i64
%449 = arith.ori %435, %448 : i64
%450 = arith.constant 1 : i32
%451 = arith.addi %432, %450 : i32
%452 = arith.extsi %451 : i32 to i64
%453 = arith.constant 45 : i32
%455 = arith.extsi %453 : i32 to i64
%454 = arith.shli %452, %455 : i64
%456 = arith.ori %449, %454 : i64
%457 = func.call @decode_roman(%456) : (i64) -> i32
%458 = func.call @encode_roman(%457) : (i32) -> i64
%459 = arith.cmpi eq, %458, %456 : i64
cf.cond_br %459, ^bb48, ^bb49
^bb48:
%461 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%462 = llvm.load %461 : !llvm.ptr -> !llvm.ptr
%463 = llvm.load %410 : !llvm.ptr -> i32
%464 = arith.extsi %463 : i32 to i64
%465 = llvm.getelementptr %462[%464] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%460 = llvm.load %465 : !llvm.ptr -> i32
%466 = llvm.mlir.addressof @next_arr : !llvm.ptr
%467 = llvm.load %466 : !llvm.ptr -> !llvm.ptr
%468 = llvm.load %410 : !llvm.ptr -> i32
%469 = arith.constant 7 : i32
%470 = arith.muli %468, %469 : i32
%471 = arith.addi %470, %460 : i32
%472 = arith.extsi %471 : i32 to i64
%473 = llvm.getelementptr %467[%472] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %457, %473 : i32, !llvm.ptr
%474 = arith.constant 1 : i32
%475 = arith.addi %460, %474 : i32
%476 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%477 = llvm.load %476 : !llvm.ptr -> !llvm.ptr
%478 = llvm.load %410 : !llvm.ptr -> i32
%479 = arith.extsi %478 : i32 to i64
%480 = llvm.getelementptr %477[%479] : (!llvm.ptr, i64) -> !llvm.ptr, i32
llvm.store %475, %480 : i32, !llvm.ptr
cf.br ^bb50
^bb49:
cf.br ^bb50
^bb50:
%481 = llvm.load %438 : !llvm.ptr -> i32
%482 = arith.constant 1 : i32
%483 = arith.addi %481, %482 : i32
llvm.store %483, %438 : i32, !llvm.ptr
cf.br ^bb45
^bb47:
%484 = llvm.load %410 : !llvm.ptr -> i32
%485 = arith.constant 1 : i32
%486 = arith.addi %484, %485 : i32
llvm.store %486, %410 : i32, !llvm.ptr
cf.br ^bb42
^bb44:
func.return
}
func.func @search(%arg0: i32) -> f64 {
%488 = llvm.mlir.addressof @memo_ok : !llvm.ptr
%489 = llvm.load %488 : !llvm.ptr -> !llvm.ptr
%490 = arith.extsi %arg0 : i32 to i64
%491 = llvm.getelementptr %489[%490] : (!llvm.ptr, i64) -> !llvm.ptr, i8
%487 = llvm.load %491 : !llvm.ptr -> i8
%492 = arith.constant 0 : i32
%494 = arith.extsi %487 : i8 to i32
%493 = arith.cmpi ne, %494, %492 : i32
cf.cond_br %493, ^bb51, ^bb52
^bb51:
%496 = llvm.mlir.addressof @memo : !llvm.ptr
%497 = llvm.load %496 : !llvm.ptr -> !llvm.ptr
%498 = arith.extsi %arg0 : i32 to i64
%499 = llvm.getelementptr %497[%498] : (!llvm.ptr, i64) -> !llvm.ptr, f64
%495 = llvm.load %499 : !llvm.ptr -> f64
func.return %495 : f64
^bb52:
cf.br ^bb53
^bb53:
%501 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%502 = llvm.load %501 : !llvm.ptr -> !llvm.ptr
%503 = arith.extsi %arg0 : i32 to i64
%504 = llvm.getelementptr %502[%503] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%500 = llvm.load %504 : !llvm.ptr -> i32
%505 = arith.constant 0 : i32
%506 = arith.cmpi eq, %500, %505 : i32
cf.cond_br %506, ^bb54, ^bb55
^bb54:
%507 = arith.constant 1 : i32
%508 = llvm.mlir.addressof @memo_ok : !llvm.ptr
%509 = llvm.load %508 : !llvm.ptr -> !llvm.ptr
%510 = arith.trunci %507 : i32 to i8
%511 = arith.extsi %arg0 : i32 to i64
%512 = llvm.getelementptr %509[%511] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %510, %512 : i8, !llvm.ptr
%513 = arith.sitofp %arg0 : i32 to f64
%514 = llvm.mlir.addressof @memo : !llvm.ptr
%515 = llvm.load %514 : !llvm.ptr -> !llvm.ptr
%516 = arith.extsi %arg0 : i32 to i64
%517 = llvm.getelementptr %515[%516] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %513, %517 : f64, !llvm.ptr
%518 = arith.sitofp %arg0 : i32 to f64
func.return %518 : f64
^bb55:
cf.br ^bb56
^bb56:
%519 = llvm.mlir.addressof @Terminal : !llvm.ptr
%520 = llvm.load %519 : !llvm.ptr -> f64
%521 = arith.sitofp %arg0 : i32 to f64
%522 = arith.mulf %520, %521 : f64
%523 = llvm.mlir.constant(1 : i64) : i64
%524 = llvm.alloca %523 x f64 : (i64) -> !llvm.ptr
llvm.store %522, %524 : f64, !llvm.ptr
%525 = llvm.mlir.addressof @Terminal : !llvm.ptr
%526 = llvm.load %525 : !llvm.ptr -> f64
%527 = llvm.mlir.constant(1 : i64) : i64
%528 = llvm.alloca %527 x f64 : (i64) -> !llvm.ptr
llvm.store %526, %528 : f64, !llvm.ptr
%529 = arith.constant 0 : i32
%530 = llvm.mlir.constant(1 : i64) : i64
%531 = llvm.alloca %530 x i32 : (i64) -> !llvm.ptr
llvm.store %529, %531 : i32, !llvm.ptr
cf.br ^bb57
^bb57:
%532 = llvm.load %531 : !llvm.ptr -> i32
%534 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%535 = llvm.load %534 : !llvm.ptr -> !llvm.ptr
%536 = arith.extsi %arg0 : i32 to i64
%537 = llvm.getelementptr %535[%536] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%533 = llvm.load %537 : !llvm.ptr -> i32
%538 = arith.cmpi slt, %532, %533 : i32
cf.cond_br %538, ^bb58, ^bb59
^bb58:
%540 = llvm.mlir.addressof @next_arr : !llvm.ptr
%541 = llvm.load %540 : !llvm.ptr -> !llvm.ptr
%542 = arith.constant 7 : i32
%543 = arith.muli %arg0, %542 : i32
%544 = llvm.load %531 : !llvm.ptr -> i32
%545 = arith.addi %543, %544 : i32
%546 = arith.extsi %545 : i32 to i64
%547 = llvm.getelementptr %541[%546] : (!llvm.ptr, i64) -> !llvm.ptr, i32
%539 = llvm.load %547 : !llvm.ptr -> i32
%548 = llvm.load %524 : !llvm.ptr -> f64
%549 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%550 = llvm.load %549 : !llvm.ptr -> f64
%551 = func.call @search(%539) : (i32) -> f64
%552 = arith.mulf %550, %551 : f64
%553 = arith.addf %548, %552 : f64
llvm.store %553, %524 : f64, !llvm.ptr
%554 = llvm.load %528 : !llvm.ptr -> f64
%555 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%556 = llvm.load %555 : !llvm.ptr -> f64
%557 = arith.addf %554, %556 : f64
llvm.store %557, %528 : f64, !llvm.ptr
%558 = llvm.load %531 : !llvm.ptr -> i32
%559 = arith.constant 1 : i32
%560 = arith.addi %558, %559 : i32
llvm.store %560, %531 : i32, !llvm.ptr
cf.br ^bb57
^bb59:
%561 = llvm.load %524 : !llvm.ptr -> f64
%562 = llvm.load %528 : !llvm.ptr -> f64
%563 = arith.divf %561, %562 : f64
llvm.store %563, %524 : f64, !llvm.ptr
%564 = arith.constant 1 : i32
%565 = llvm.mlir.addressof @memo_ok : !llvm.ptr
%566 = llvm.load %565 : !llvm.ptr -> !llvm.ptr
%567 = arith.trunci %564 : i32 to i8
%568 = arith.extsi %arg0 : i32 to i64
%569 = llvm.getelementptr %566[%568] : (!llvm.ptr, i64) -> !llvm.ptr, i8
llvm.store %567, %569 : i8, !llvm.ptr
%570 = llvm.load %524 : !llvm.ptr -> f64
%571 = llvm.mlir.addressof @memo : !llvm.ptr
%572 = llvm.load %571 : !llvm.ptr -> !llvm.ptr
%573 = arith.extsi %arg0 : i32 to i64
%574 = llvm.getelementptr %572[%573] : (!llvm.ptr, i64) -> !llvm.ptr, f64
llvm.store %570, %574 : f64, !llvm.ptr
%575 = llvm.load %524 : !llvm.ptr -> f64
func.return %575 : f64
}
func.func @main() -> i32 {
%577 = arith.constant 1000 : i32
%578 = arith.constant 8 : i32
%579 = arith.extsi %577 : i32 to i64
%580 = arith.extsi %578 : i32 to i64
%576 = func.call @calloc(%579, %580) : (i64, i64) -> !llvm.ptr
%581 = llvm.mlir.addressof @n2r : !llvm.ptr
llvm.store %576, %581 : !llvm.ptr, !llvm.ptr
%583 = arith.constant 7000 : i32
%584 = arith.constant 4 : i32
%585 = arith.extsi %583 : i32 to i64
%586 = arith.extsi %584 : i32 to i64
%582 = func.call @calloc(%585, %586) : (i64, i64) -> !llvm.ptr
%587 = llvm.mlir.addressof @next_arr : !llvm.ptr
llvm.store %582, %587 : !llvm.ptr, !llvm.ptr
%589 = arith.constant 1000 : i32
%590 = arith.constant 4 : i32
%591 = arith.extsi %589 : i32 to i64
%592 = arith.extsi %590 : i32 to i64
%588 = func.call @calloc(%591, %592) : (i64, i64) -> !llvm.ptr
%593 = llvm.mlir.addressof @next_cnt : !llvm.ptr
llvm.store %588, %593 : !llvm.ptr, !llvm.ptr
%595 = arith.constant 1000 : i32
%596 = arith.constant 8 : i32
%597 = arith.extsi %595 : i32 to i64
%598 = arith.extsi %596 : i32 to i64
%594 = func.call @calloc(%597, %598) : (i64, i64) -> !llvm.ptr
%599 = llvm.mlir.addressof @memo : !llvm.ptr
llvm.store %594, %599 : !llvm.ptr, !llvm.ptr
%601 = arith.constant 1000 : i32
%602 = arith.constant 1 : i32
%603 = arith.extsi %601 : i32 to i64
%604 = arith.extsi %602 : i32 to i64
%600 = func.call @calloc(%603, %604) : (i64, i64) -> !llvm.ptr
%605 = llvm.mlir.addressof @memo_ok : !llvm.ptr
llvm.store %600, %605 : !llvm.ptr, !llvm.ptr
%606 = arith.constant 0 : i32
%607 = llvm.mlir.constant(1 : i64) : i64
%608 = llvm.alloca %607 x i32 : (i64) -> !llvm.ptr
llvm.store %606, %608 : i32, !llvm.ptr
cf.br ^bb60
^bb60:
%609 = llvm.load %608 : !llvm.ptr -> i32
%610 = arith.constant 1000 : i32
%611 = arith.cmpi slt, %609, %610 : i32
cf.cond_br %611, ^bb61, ^bb62
^bb61:
%613 = llvm.load %608 : !llvm.ptr -> i32
%612 = func.call @encode_roman(%613) : (i32) -> i64
%614 = llvm.mlir.addressof @n2r : !llvm.ptr
%615 = llvm.load %614 : !llvm.ptr -> !llvm.ptr
%616 = llvm.load %608 : !llvm.ptr -> i32
%617 = arith.extsi %616 : i32 to i64
%618 = llvm.getelementptr %615[%617] : (!llvm.ptr, i64) -> !llvm.ptr, i64
llvm.store %612, %618 : i64, !llvm.ptr
%619 = llvm.load %608 : !llvm.ptr -> i32
%620 = arith.constant 1 : i32
%621 = arith.addi %619, %620 : i32
llvm.store %621, %608 : i32, !llvm.ptr
cf.br ^bb60
^bb62:
func.call @build_transitions() : () -> ()
%623 = arith.constant 0.0 : f32
%624 = arith.extf %623 : f32 to f64
%625 = llvm.mlir.constant(1 : i64) : i64
%626 = llvm.alloca %625 x f64 : (i64) -> !llvm.ptr
llvm.store %624, %626 : f64, !llvm.ptr
%627 = llvm.load %626 : !llvm.ptr -> f64
%628 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%629 = llvm.load %628 : !llvm.ptr -> f64
%631 = arith.constant 1 : i32
%630 = func.call @search(%631) : (i32) -> f64
%632 = arith.mulf %629, %630 : f64
%633 = arith.addf %627, %632 : f64
llvm.store %633, %626 : f64, !llvm.ptr
%634 = llvm.load %626 : !llvm.ptr -> f64
%635 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%636 = llvm.load %635 : !llvm.ptr -> f64
%638 = arith.constant 5 : i32
%637 = func.call @search(%638) : (i32) -> f64
%639 = arith.mulf %636, %637 : f64
%640 = arith.addf %634, %639 : f64
llvm.store %640, %626 : f64, !llvm.ptr
%641 = llvm.load %626 : !llvm.ptr -> f64
%642 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%643 = llvm.load %642 : !llvm.ptr -> f64
%645 = arith.constant 10 : i32
%644 = func.call @search(%645) : (i32) -> f64
%646 = arith.mulf %643, %644 : f64
%647 = arith.addf %641, %646 : f64
llvm.store %647, %626 : f64, !llvm.ptr
%648 = llvm.load %626 : !llvm.ptr -> f64
%649 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%650 = llvm.load %649 : !llvm.ptr -> f64
%652 = arith.constant 50 : i32
%651 = func.call @search(%652) : (i32) -> f64
%653 = arith.mulf %650, %651 : f64
%654 = arith.addf %648, %653 : f64
llvm.store %654, %626 : f64, !llvm.ptr
%655 = llvm.load %626 : !llvm.ptr -> f64
%656 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%657 = llvm.load %656 : !llvm.ptr -> f64
%659 = arith.constant 100 : i32
%658 = func.call @search(%659) : (i32) -> f64
%660 = arith.mulf %657, %658 : f64
%661 = arith.addf %655, %660 : f64
llvm.store %661, %626 : f64, !llvm.ptr
%662 = llvm.load %626 : !llvm.ptr -> f64
%663 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%664 = llvm.load %663 : !llvm.ptr -> f64
%666 = arith.constant 500 : i32
%665 = func.call @search(%666) : (i32) -> f64
%667 = arith.mulf %664, %665 : f64
%668 = arith.addf %662, %667 : f64
llvm.store %668, %626 : f64, !llvm.ptr
%669 = arith.constant 0.000000001 : f32
%670 = arith.extf %669 : f32 to f64
%671 = arith.constant 1 : i32
%672 = llvm.mlir.constant(1 : i64) : i64
%673 = llvm.alloca %672 x i32 : (i64) -> !llvm.ptr
llvm.store %671, %673 : i32, !llvm.ptr
%674 = llvm.load %626 : !llvm.ptr -> f64
%675 = llvm.mlir.constant(1 : i64) : i64
%676 = llvm.alloca %675 x f64 : (i64) -> !llvm.ptr
llvm.store %674, %676 : f64, !llvm.ptr
%677 = arith.constant 0 : i1
%678 = llvm.mlir.constant(1 : i64) : i64
%679 = llvm.alloca %678 x i1 : (i64) -> !llvm.ptr
llvm.store %677, %679 : i1, !llvm.ptr
cf.br ^bb63
^bb63:
%680 = llvm.load %679 : !llvm.ptr -> i1
%682 = arith.constant 1 : i1
%681 = arith.xori %680, %682 : i1
cf.cond_br %681, ^bb64, ^bb65
^bb64:
%684 = llvm.load %673 : !llvm.ptr -> i32
%685 = arith.sitofp %684 : i32 to f64
%686 = arith.constant 1000.0 : f32
%688 = arith.extf %686 : f32 to f64
%687 = arith.mulf %685, %688 : f64
%689 = arith.constant 1.0 : f32
%690 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%691 = llvm.load %690 : !llvm.ptr -> f64
%693 = arith.extf %689 : f32 to f64
%692 = arith.subf %693, %691 : f64
%694 = arith.mulf %687, %692 : f64
%695 = llvm.load %626 : !llvm.ptr -> f64
%696 = arith.addf %694, %695 : f64
%698 = llvm.mlir.addressof @AnyLetter : !llvm.ptr
%699 = llvm.load %698 : !llvm.ptr -> f64
%700 = llvm.load %673 : !llvm.ptr -> i32
%701 = arith.sitofp %700 : i32 to f64
%697 = func.call @pow(%699, %701) : (f64, f64) -> f64
%702 = arith.mulf %696, %697 : f64
%703 = llvm.load %676 : !llvm.ptr -> f64
%704 = arith.addf %703, %702 : f64
llvm.store %704, %676 : f64, !llvm.ptr
%705 = arith.cmpf olt, %702, %670 : f64
cf.cond_br %705, ^bb66, ^bb67
^bb66:
%706 = arith.constant 1 : i1
llvm.store %706, %679 : i1, !llvm.ptr
cf.br ^bb68
^bb67:
%707 = llvm.load %673 : !llvm.ptr -> i32
%708 = arith.constant 1 : i32
%709 = arith.addi %707, %708 : i32
llvm.store %709, %673 : i32, !llvm.ptr
cf.br ^bb68
^bb68:
cf.br ^bb63
^bb65:
%710 = llvm.mlir.addressof @str_0 : !llvm.ptr
%711 = llvm.load %676 : !llvm.ptr -> f64
%712 = llvm.call @printf(%710, %711) vararg(!llvm.func<i32 (ptr, ...)>) : (!llvm.ptr, f64) -> i32
%714 = llvm.mlir.addressof @n2r : !llvm.ptr
%715 = llvm.load %714 : !llvm.ptr -> !llvm.ptr
func.call @free(%715) : (!llvm.ptr) -> ()
%717 = llvm.mlir.addressof @next_arr : !llvm.ptr
%718 = llvm.load %717 : !llvm.ptr -> !llvm.ptr
func.call @free(%718) : (!llvm.ptr) -> ()
%720 = llvm.mlir.addressof @next_cnt : !llvm.ptr
%721 = llvm.load %720 : !llvm.ptr -> !llvm.ptr
func.call @free(%721) : (!llvm.ptr) -> ()
%723 = llvm.mlir.addressof @memo : !llvm.ptr
%724 = llvm.load %723 : !llvm.ptr -> !llvm.ptr
func.call @free(%724) : (!llvm.ptr) -> ()
%726 = llvm.mlir.addressof @memo_ok : !llvm.ptr
%727 = llvm.load %726 : !llvm.ptr -> !llvm.ptr
func.call @free(%727) : (!llvm.ptr) -> ()
%728 = arith.constant 0 : i32
func.return %728 : i32
}
}