char *intToRoman(int num) {
  char one[][5] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
  char two[][5] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
  char three[][5] = {"",  "C",  "CC",  "CCC",  "CD",
                     "D", "DC", "DCC", "DCCC", "CM"};
  char four[][5] = {"", "M", "MM", "MMM"};
  char *result = (char *)malloc(sizeof(char) * 16);
  result[0] = '\0';
  strcat(result, four[num / 1000]);
  num %= 1000;
  strcat(result, three[num / 100]);
  num %= 100;
  strcat(result, two[num / 10]);
  num %= 10;
  strcat(result, one[num]);
  return result;
}


x86 assembly (clang, -O0):
<intToRoman>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x32,%edx
call   1030 <memcpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xee2(%rip),%rsi
mov    $0x32,%edx
call   1030 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xf0a(%rip),%rsi
mov    $0x32,%edx
call   1030 <memcpy@plt>
mov    0xf39(%rip),%rax
mov    %rax,-0xe0(%rbp)
mov    0xf33(%rip),%rax
mov    %rax,-0xd8(%rbp)
mov    0xf2e(%rip),%eax
mov    %eax,-0xd0(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0xe8(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
lea    -0xe0(%rbp),%rsi
imul   $0x5,%rax,%rax
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0xe8(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cltq
lea    -0xc0(%rbp),%rsi
imul   $0x5,%rax,%rax
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0xe8(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cltq
lea    -0x80(%rbp),%rsi
imul   $0x5,%rax,%rax
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0xe8(%rbp),%rdi
movslq -0x4(%rbp),%rax
lea    -0x40(%rbp),%rsi
imul   $0x5,%rax,%rax
add    %rax,%rsi
call   1050 <strcat@plt>
mov    -0xe8(%rbp),%rax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman>:
push   %rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %edi,%ebp
movzwl 0xefc(%rip),%eax
mov    %ax,0xd0(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movzwl 0xf00(%rip),%eax
mov    %ax,0x90(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movzwl 0xf0a(%rip),%eax
mov    %ax,0x50(%rsp)
movaps 0xeee(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0xefb(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax)
movslq %ebp,%rbp
imul   $0x10624dd3,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rbx
lea    (%rbx,%rbx,4),%rax
lea    (%rsp,%rax,1),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
imul   $0x3e8,%ebx,%eax
sub    %eax,%ebp
movswl %bp,%eax
imul   $0x147b,%eax,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
sar    $0x13,%ebx
add    %eax,%ebx
movswq %bx,%rax
lea    (%rax,%rax,4),%rax
lea    (%rsp,%rax,1),%rsi
add    $0x20,%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
imul   $0x64,%ebx,%eax
sub    %eax,%ebp
movsbl %bpl,%eax
imul   $0x67,%eax,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
shr    $0xa,%ecx
add    %al,%cl
movsbq %cl,%rbx
lea    (%rbx,%rbx,4),%rax
lea    (%rsp,%rax,1),%rsi
add    $0x60,%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
movzbl %bl,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%bpl
movsbq %bpl,%rax
lea    (%rax,%rax,4),%rax
lea    (%rsp,%rax,1),%rsi
add    $0xa0,%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
mov    %r14,%rax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.intToRoman.one = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"I\00\00\00\00", [5 x i8] c"II\00\00\00", [5 x i8] c"III\00\00", [5 x i8] c"IV\00\00\00", [5 x i8] c"V\00\00\00\00", [5 x i8] c"VI\00\00\00", [5 x i8] c"VII\00\00", [5 x i8] c"VIII\00", [5 x i8] c"IX\00\00\00"]
@__const.intToRoman.two = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"X\00\00\00\00", [5 x i8] c"XX\00\00\00", [5 x i8] c"XXX\00\00", [5 x i8] c"XL\00\00\00", [5 x i8] c"L\00\00\00\00", [5 x i8] c"LX\00\00\00", [5 x i8] c"LXX\00\00", [5 x i8] c"LXXX\00", [5 x i8] c"XC\00\00\00"]
@__const.intToRoman.three = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"C\00\00\00\00", [5 x i8] c"CC\00\00\00", [5 x i8] c"CCC\00\00", [5 x i8] c"CD\00\00\00", [5 x i8] c"D\00\00\00\00", [5 x i8] c"DC\00\00\00", [5 x i8] c"DCC\00\00", [5 x i8] c"DCCC\00", [5 x i8] c"CM\00\00\00"]
@__const.intToRoman.four = [4 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"M\00\00\00\00", [5 x i8] c"MM\00\00\00", [5 x i8] c"MMM\00\00"]
define i8* @intToRoman(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x [5 x i8]]
%4 = alloca [10 x [5 x i8]]
%5 = alloca [10 x [5 x i8]]
%6 = alloca [4 x [5 x i8]]
%7 = alloca i8*
store i32 %0, i32* %2
%8 = bitcast [10 x [5 x i8]]* %3 to i8*
%9 = bitcast [10 x [5 x i8]]* %4 to i8*
%10 = bitcast [10 x [5 x i8]]* %5 to i8*
%11 = bitcast [4 x [5 x i8]]* %6 to i8*
%12 = call i8* @malloc(i64 16)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
%15 = load i8*, i8** %7
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 1000
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x [5 x i8]], [4 x [5 x i8]]* %6, i64 0, i64 %18
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%21 = call i8* @strcat(i8* %15, i8* %20)
%22 = load i32, i32* %2
%23 = srem i32 %22, 1000
store i32 %23, i32* %2
%24 = load i8*, i8** %7
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 100
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %5, i64 0, i64 %27
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %28, i64 0, i64 0
%30 = call i8* @strcat(i8* %24, i8* %29)
%31 = load i32, i32* %2
%32 = srem i32 %31, 100
store i32 %32, i32* %2
%33 = load i8*, i8** %7
%34 = load i32, i32* %2
%35 = sdiv i32 %34, 10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %4, i64 0, i64 %36
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %37, i64 0, i64 0
%39 = call i8* @strcat(i8* %33, i8* %38)
%40 = load i32, i32* %2
%41 = srem i32 %40, 10
store i32 %41, i32* %2
%42 = load i8*, i8** %7
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %3, i64 0, i64 %44
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %45, i64 0, i64 0
%47 = call i8* @strcat(i8* %42, i8* %46)
%48 = load i8*, i8** %7
ret i8* %48
}

LLVM IR (-O2):
@__const.intToRoman.one = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"I\00\00\00\00", [5 x i8] c"II\00\00\00", [5 x i8] c"III\00\00", [5 x i8] c"IV\00\00\00", [5 x i8] c"V\00\00\00\00", [5 x i8] c"VI\00\00\00", [5 x i8] c"VII\00\00", [5 x i8] c"VIII\00", [5 x i8] c"IX\00\00\00"]
@__const.intToRoman.two = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"X\00\00\00\00", [5 x i8] c"XX\00\00\00", [5 x i8] c"XXX\00\00", [5 x i8] c"XL\00\00\00", [5 x i8] c"L\00\00\00\00", [5 x i8] c"LX\00\00\00", [5 x i8] c"LXX\00\00", [5 x i8] c"LXXX\00", [5 x i8] c"XC\00\00\00"]
@__const.intToRoman.three = [10 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"C\00\00\00\00", [5 x i8] c"CC\00\00\00", [5 x i8] c"CCC\00\00", [5 x i8] c"CD\00\00\00", [5 x i8] c"D\00\00\00\00", [5 x i8] c"DC\00\00\00", [5 x i8] c"DCC\00\00", [5 x i8] c"DCCC\00", [5 x i8] c"CM\00\00\00"]
@__const.intToRoman.four = [4 x [5 x i8]] [[5 x i8] zeroinitializer, [5 x i8] c"M\00\00\00\00", [5 x i8] c"MM\00\00\00", [5 x i8] c"MMM\00\00"]
define i8* @intToRoman(i32 %0) {
%2 = alloca [10 x [5 x i8]]
%3 = alloca [10 x [5 x i8]]
%4 = alloca [10 x [5 x i8]]
%5 = alloca [4 x [5 x i8]]
%6 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %2, i64 0, i64 0, i64 0
%7 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %3, i64 0, i64 0, i64 0
%8 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %4, i64 0, i64 0, i64 0
%9 = getelementptr inbounds [4 x [5 x i8]], [4 x [5 x i8]]* %5, i64 0, i64 0, i64 0
%10 = tail call dereferenceable_or_null(16) i8* @malloc(i64 16)
store i8 0, i8* %10
%11 = sdiv i32 %0, 1000
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4 x [5 x i8]], [4 x [5 x i8]]* %5, i64 0, i64 %12, i64 0
%14 = call i8* @strcat(i8* %10, i8* %13)
%15 = srem i32 %0, 1000
%16 = trunc i32 %15 to i16
%17 = sdiv i16 %16, 100
%18 = sext i16 %17 to i64
%19 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %4, i64 0, i64 %18, i64 0
%20 = call i8* @strcat(i8* %10, i8* %19)
%21 = srem i16 %16, 100
%22 = trunc i16 %21 to i8
%23 = sdiv i8 %22, 10
%24 = sext i8 %23 to i64
%25 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %3, i64 0, i64 %24, i64 0
%26 = call i8* @strcat(i8* %10, i8* %25)
%27 = srem i8 %22, 10
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds [10 x [5 x i8]], [10 x [5 x i8]]* %2, i64 0, i64 %28, i64 0
%30 = call i8* @strcat(i8* %10, i8* %29)
ret i8* %10
}