#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
char *intToRoman(int num) {
  int nums[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  char str[13][3] = {{"M"},  {"CM"}, {"D"},  {"CD"}, {"C"},  {"XC"}, {"L"},
                     {"XL"}, {"X"},  {"IX"}, {"V"},  {"IV"}, {"I"}};
  char *ret = (char *)malloc(sizeof(char) * 16);
  memset(ret, 0, 16);
  for (int i = 0; i < 13; i++) {
    while (num >= nums[i]) {
      num -= nums[i];
      strcat(ret, str[i]);
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<intToRoman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x27,%edx
call   1040 <memcpy@plt>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
movl   $0x0,-0x7c(%rbp)
cmpl   $0xd,-0x7c(%rbp)
jge    11fd <intToRoman+0xbd>
jmp    11ac <intToRoman+0x6c>
mov    -0x4(%rbp),%eax
movslq -0x7c(%rbp),%rcx
cmp    -0x40(%rbp,%rcx,4),%eax
jl     11ea <intToRoman+0xaa>
movslq -0x7c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x78(%rbp),%rdi
movslq -0x7c(%rbp),%rax
lea    -0x70(%rbp),%rsi
imul   $0x3,%rax,%rax
add    %rax,%rsi
call   1060 <strcat@plt>
jmp    11ac <intToRoman+0x6c>
jmp    11ef <intToRoman+0xaf>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    119d <intToRoman+0x5d>
mov    -0x78(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
mov    0xf18(%rip),%rax
mov    %rax,0x1f(%rsp)
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %r12d,%r12d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0xe77(%rip),%r13
jmp    119a <intToRoman+0x6a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    $0xd,%r12
je     11c3 <intToRoman+0x93>
mov    0x0(%r13,%r12,4),%ebp
cmp    %ebp,%ebx
jl     1190 <intToRoman+0x60>
lea    (%r12,%r12,2),%rax
lea    (%rsp,%rax,1),%r15
nopl   0x0(%rax,%rax,1)
sub    %ebp,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
cmp    %ebp,%ebx
jge    11b0 <intToRoman+0x80>
jmp    1190 <intToRoman+0x60>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.intToRoman.nums = [13 x i32] [i32 1000, i32 900, i32 500, i32 400, i32 100, i32 90, i32 50, i32 40, i32 10, i32 9, i32 5, i32 4, i32 1]
@__const.intToRoman.str = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
define i8* @intToRoman(i32 %0) {
%2 = alloca i32
%3 = alloca [13 x i32]
%4 = alloca [13 x [3 x i8]]
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %2
%7 = bitcast [13 x i32]* %3 to i8*
%8 = bitcast [13 x [3 x i8]]* %4 to i8*
%9 = call i64 @malloc(i32 16)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @memset(i8* %11, i32 0, i32 16)
store i32 0, i32* %6
br label %13
13: ; preds = %38, %1
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 13
br i1 %15, label %16, label %41
16: ; preds = %13
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %2
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = icmp sge i32 %18, %22
br i1 %23, label %24, label %37
24: ; preds = %17
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %2
%30 = sub nsw i32 %29, %28
store i32 %30, i32* %2
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %4, i64 0, i64 %33
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %34, i64 0, i64 0
%36 = call i32 @strcat(i8* %31, i8* %35)
br label %17
37: ; preds = %17
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %13
41: ; preds = %13
%42 = load i8*, i8** %5
ret i8* %42
}

LLVM IR (-O2):
@__const.intToRoman.nums = [13 x i32] [i32 1000, i32 900, i32 500, i32 400, i32 100, i32 90, i32 50, i32 40, i32 10, i32 9, i32 5, i32 4, i32 1]
@__const.intToRoman.str = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
define i8* @intToRoman(i32 %0) {
%2 = alloca [13 x [3 x i8]]
%3 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %2, i64 0, i64 0, i64 0
%4 = tail call i64 @malloc(i32 16)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memset(i8* %5, i32 0, i32 16)
br label %7
7: ; preds = %1, %21
%8 = phi i64 [ 0, %1 ], [ %23, %21 ]
%9 = phi i32 [ %0, %1 ], [ %22, %21 ]
%10 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.intToRoman.nums, i64 0, i64 %8
%11 = load i32, i32* %10
%12 = icmp slt i32 %9, %11
br i1 %12, label %21, label %13
13: ; preds = %7
%14 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %2, i64 0, i64 %8, i64 0
br label %16
15: ; preds = %21
ret i8* %5
16: ; preds = %13, %16
%17 = phi i32 [ %9, %13 ], [ %18, %16 ]
%18 = sub nsw i32 %17, %11
%19 = call i32 @strcat(i8* %5, i8* %14)
%20 = icmp slt i32 %18, %11
br i1 %20, label %21, label %16
21: ; preds = %16, %7
%22 = phi i32 [ %9, %7 ], [ %18, %16 ]
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, 13
br i1 %24, label %15, label %7
}