#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *itr(int, char, char, char);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
char *intToRoman_t(int num) {
  char *ret = (char *)malloc(sizeof(char *) * 16);
  memset(ret, 0, 16);
  if (num / 1000) {
    char *tmp = itr(num / 1000, 'M', 'z', 'z');
    strcat(ret, tmp);
    free(tmp);
  }
  num %= 1000;
  if (num / 100) {
    char *tmp = itr(num / 100, 'C', 'D', 'M');
    strcat(ret, tmp);
    free(tmp);
  }
  num %= 100;
  if (num / 10) {
    char *tmp = itr(num / 10, 'X', 'L', 'C');
    strcat(ret, tmp);
    free(tmp);
  }
  num %= 10;
  if (num) {
    char *tmp = itr(num, 'I', 'V', 'X');
    strcat(ret, tmp);
    free(tmp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<intToRoman_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     11c5 <intToRoman_t+0x75>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x4d,%esi
mov    $0x7a,%ecx
mov    %ecx,%edx
call   1040 <itr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1222 <intToRoman_t+0xd2>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x43,%esi
mov    $0x44,%edx
mov    $0x4d,%ecx
call   1040 <itr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     127f <intToRoman_t+0x12f>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x58,%esi
mov    $0x4c,%edx
mov    $0x43,%ecx
call   1040 <itr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     12c8 <intToRoman_t+0x178>
mov    -0x4(%rbp),%edi
mov    $0x49,%esi
mov    $0x56,%edx
mov    $0x58,%ecx
call   1040 <itr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman_t>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x80,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    0x3e7(%rbx),%eax
movslq %ebx,%rbp
cmp    $0x7cf,%eax
jb     11c0 <intToRoman_t+0x70>
imul   $0x10624dd3,%rbp,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x26,%rdi
add    %eax,%edi
mov    $0x4d,%esi
mov    $0x7a,%edx
mov    $0x7a,%ecx
call   1040 <itr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
imul   $0x10624dd3,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
neg    %eax
add    %ebp,%eax
add    $0x63,%eax
movswl %cx,%ebp
cmp    $0xc7,%eax
jb     1229 <intToRoman_t+0xd9>
imul   $0x147b,%ebp,%edi
mov    %edi,%eax
shr    $0x1f,%eax
sar    $0x13,%edi
add    %eax,%edi
mov    $0x43,%esi
mov    $0x44,%edx
mov    $0x4d,%ecx
call   1040 <itr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
imul   $0x147b,%ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x13,%eax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%ebp
lea    0x9(%rbp),%eax
movsbl %bpl,%ebp
cmp    $0x13,%ax
jb     1286 <intToRoman_t+0x136>
imul   $0x67,%ebp,%eax
movzwl %ax,%ecx
shr    $0xa,%eax
shr    $0xf,%ecx
add    %al,%cl
movsbl %cl,%edi
mov    $0x58,%esi
mov    $0x4c,%edx
mov    $0x43,%ecx
call   1040 <itr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
imul   $0x67,%ebp,%eax
movzwl %ax,%ecx
shr    $0xa,%eax
shr    $0xf,%ecx
add    %al,%cl
movzbl %cl,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%bpl
je     12cf <intToRoman_t+0x17f>
movsbl %bpl,%edi
mov    $0x49,%esi
mov    $0x56,%edx
mov    $0x58,%ecx
call   1040 <itr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @intToRoman_t(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %2
%8 = call i64 @malloc(i32 128)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @memset(i8* %10, i32 0, i32 16)
%12 = load i32, i32* %2
%13 = sdiv i32 %12, 1000
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %1
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 1000
%18 = call i8* @itr(i32 %17, i8 signext 77, i8 signext 122, i8 signext 122)
store i8* %18, i8** %4
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %15, %1
%25 = load i32, i32* %2
%26 = srem i32 %25, 1000
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 100
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %24
%31 = load i32, i32* %2
%32 = sdiv i32 %31, 100
%33 = call i8* @itr(i32 %32, i8 signext 67, i8 signext 68, i8 signext 77)
store i8* %33, i8** %5
%34 = load i8*, i8** %3
%35 = load i8*, i8** %5
%36 = call i32 @strcat(i8* %34, i8* %35)
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %30, %24
%40 = load i32, i32* %2
%41 = srem i32 %40, 100
store i32 %41, i32* %2
%42 = load i32, i32* %2
%43 = sdiv i32 %42, 10
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %54
45: ; preds = %39
%46 = load i32, i32* %2
%47 = sdiv i32 %46, 10
%48 = call i8* @itr(i32 %47, i8 signext 88, i8 signext 76, i8 signext 67)
store i8* %48, i8** %6
%49 = load i8*, i8** %3
%50 = load i8*, i8** %6
%51 = call i32 @strcat(i8* %49, i8* %50)
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %45, %39
%55 = load i32, i32* %2
%56 = srem i32 %55, 10
store i32 %56, i32* %2
%57 = load i32, i32* %2
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %54
%60 = load i32, i32* %2
%61 = call i8* @itr(i32 %60, i8 signext 73, i8 signext 86, i8 signext 88)
store i8* %61, i8** %7
%62 = load i8*, i8** %3
%63 = load i8*, i8** %7
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %59, %54
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
define i8* @intToRoman_t(i32 %0) {
%2 = tail call i64 @malloc(i32 128)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @memset(i8* %3, i32 0, i32 16)
%5 = add i32 %0, 999
%6 = icmp ult i32 %5, 1999
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = sdiv i32 %0, 1000
%9 = tail call i8* @itr(i32 %8, i8 signext 77, i8 signext 122, i8 signext 122)
%10 = tail call i32 @strcat(i8* %3, i8* %9)
%11 = tail call i32 @free(i8* %9)
br label %12
12: ; preds = %7, %1
%13 = srem i32 %0, 1000
%14 = add nsw i32 %13, 99
%15 = icmp ult i32 %14, 199
%16 = trunc i32 %13 to i16
br i1 %15, label %23, label %17
17: ; preds = %12
%18 = sdiv i16 %16, 100
%19 = sext i16 %18 to i32
%20 = tail call i8* @itr(i32 %19, i8 signext 67, i8 signext 68, i8 signext 77)
%21 = tail call i32 @strcat(i8* %3, i8* %20)
%22 = tail call i32 @free(i8* %20)
br label %23
23: ; preds = %12, %17
%24 = srem i16 %16, 100
%25 = add nsw i16 %24, 9
%26 = icmp ult i16 %25, 19
%27 = trunc i16 %24 to i8
br i1 %26, label %34, label %28
28: ; preds = %23
%29 = sdiv i8 %27, 10
%30 = sext i8 %29 to i32
%31 = tail call i8* @itr(i32 %30, i8 signext 88, i8 signext 76, i8 signext 67)
%32 = tail call i32 @strcat(i8* %3, i8* %31)
%33 = tail call i32 @free(i8* %31)
br label %34
34: ; preds = %23, %28
%35 = srem i8 %27, 10
%36 = icmp eq i8 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = sext i8 %35 to i32
%39 = tail call i8* @itr(i32 %38, i8 signext 73, i8 signext 86, i8 signext 88)
%40 = tail call i32 @strcat(i8* %3, i8* %39)
%41 = tail call i32 @free(i8* %39)
br label %42
42: ; preds = %37, %34
ret i8* %3
}