#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 strlen(char *);
char *intToRoman(int num) {
  int k[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}, i;
  char v[] = "M\0\0CM\0D\0\0CD\0C\0\0XC\0L\0\0XL\0X\0\0IX\0V\0\0IV\0I\0\0";
  char *str = (char *)malloc(256), *s = (char *)str, *c;
  for (i = 0; i < 13; ++i) {
    c = v + 3 * i;
    while (num / k[i]) {
      *s++ = *c;
      if (strlen(c) > 1)
        *s++ = c[1];
      num -= k[i];
    }
  }
  *s = '\0';
  return str;
}


x86 assembly (clang, -O0):
<intToRoman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xee2(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0xd,-0x44(%rbp)
jge    122b <intToRoman+0xfb>
lea    -0x70(%rbp),%rax
imul   $0x3,-0x44(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x4(%rbp),%eax
movslq -0x44(%rbp),%rcx
cltd
idivl  -0x40(%rbp,%rcx,4)
cmp    $0x0,%eax
je     1218 <intToRoman+0xe8>
mov    -0x88(%rbp),%rax
mov    (%rax),%cl
mov    -0x80(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x80(%rbp)
mov    %cl,(%rax)
mov    -0x88(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    1203 <intToRoman+0xd3>
mov    -0x88(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x80(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x80(%rbp)
mov    %cl,(%rax)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <intToRoman+0x74>
jmp    121d <intToRoman+0xed>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1185 <intToRoman+0x55>
mov    -0x80(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x78(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
movaps 0xf19(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x4900564900,%rax
mov    %rax,0x30(%rsp)
mov    $0x100,%edi
call   1040 <malloc@plt>
xor    %r12d,%r12d
mov    %rax,0x8(%rsp)
mov    %rax,%rbp
jmp    117a <intToRoman+0x5a>
xchg   %ax,%ax
add    $0x1,%r12
cmp    $0xd,%r12
je     11e5 <intToRoman+0xc5>
lea    0xe7f(%rip),%rax
mov    (%rax,%r12,4),%r14d
mov    %ebx,%eax
cltd
idiv   %r14d
test   %eax,%eax
je     1170 <intToRoman+0x50>
lea    (%r12,%r12,2),%rax
lea    (%rsp,%rax,1),%r15
add    $0x10,%r15
mov    %r14d,%r13d
neg    %r13d
jmp    11cb <intToRoman+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x1(%r15),%eax
mov    %al,0x1(%rbp)
add    $0x2,%rbp
lea    (%rbx,%r13,1),%eax
sub    %r14d,%ebx
cltd
idiv   %r14d
test   %eax,%eax
je     1170 <intToRoman+0x50>
movzbl (%r15),%eax
mov    %al,0x0(%rbp)
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jge    11b0 <intToRoman+0x90>
add    $0x1,%rbp
jmp    11bc <intToRoman+0x9c>
movb   $0x0,0x0(%rbp)
mov    0x8(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.intToRoman.k = [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.v = [40 x i8] c"M\00\00CM\00D\00\00CD\00C\00\00XC\00L\00\00XL\00X\00\00IX\00V\00\00IV\00I\00\00\00"
define i8* @intToRoman(i32 %0) {
%2 = alloca i32
%3 = alloca [13 x i32]
%4 = alloca i32
%5 = alloca [40 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %2
%9 = bitcast [13 x i32]* %3 to i8*
%10 = bitcast [40 x i8]* %5 to i8*
%11 = call i64 @malloc(i32 256)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
store i32 0, i32* %4
br label %14
14: ; preds = %53, %1
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 13
br i1 %16, label %17, label %56
17: ; preds = %14
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%19 = load i32, i32* %4
%20 = mul nsw i32 3, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8* %22, i8** %8
br label %23
23: ; preds = %45, %17
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%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 = sdiv i32 %24, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %52
31: ; preds = %23
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %7
store i8 %33, i8* %34
%36 = load i8*, i8** %8
%37 = call i32 @strlen(i8* %36)
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
store i8 %42, i8* %43
br label %45
45: ; preds = %39, %31
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [13 x i32], [13 x i32]* %3, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %2
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %2
br label %23
52: ; preds = %23
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %14
56: ; preds = %14
%57 = load i8*, i8** %7
store i8 0, i8* %57
%58 = load i8*, i8** %6
ret i8* %58
}

LLVM IR (-O2):
@__const.intToRoman.k = [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.v = [40 x i8] c"M\00\00CM\00D\00\00CD\00C\00\00XC\00L\00\00XL\00X\00\00IX\00V\00\00IV\00I\00\00\00"
define i8* @intToRoman(i32 %0) {
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 256)
%5 = inttoptr i64 %4 to i8*
br label %6
6: ; preds = %1, %33
%7 = phi i64 [ 0, %1 ], [ %36, %33 ]
%8 = phi i32 [ %0, %1 ], [ %35, %33 ]
%9 = phi i8* [ %5, %1 ], [ %34, %33 ]
%10 = mul nuw nsw i64 %7, 3
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 %10
%12 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.intToRoman.k, i64 0, i64 %7
%13 = load i32, i32* %12
%14 = sdiv i32 %8, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %6
%17 = getelementptr inbounds i8, i8* %11, i64 1
br label %18
18: ; preds = %16, %28
%19 = phi i32 [ %8, %16 ], [ %30, %28 ]
%20 = phi i8* [ %9, %16 ], [ %29, %28 ]
%21 = load i8, i8* %11
%22 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %21, i8* %20
%23 = call i32 @strlen(i8* %11)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8, i8* %17
%27 = getelementptr inbounds i8, i8* %20, i64 2
store i8 %26, i8* %22
br label %28
28: ; preds = %25, %18
%29 = phi i8* [ %27, %25 ], [ %22, %18 ]
%30 = sub nsw i32 %19, %13
%31 = sdiv i32 %30, %13
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %18
33: ; preds = %28, %6
%34 = phi i8* [ %9, %6 ], [ %29, %28 ]
%35 = phi i32 [ %8, %6 ], [ %30, %28 ]
%36 = add nuw nsw i64 %7, 1
%37 = icmp eq i64 %36, 13
br i1 %37, label %38, label %6
38: ; preds = %33
store i8 0, i8* %34
ret i8* %5
}