#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 */
typedef int /*<<< orphan*/ units;

/* Variables and functions */
scalar_t__ malloc(int);
char *intToRoman1(int num) {
  char *table[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                   "XL", "X",  "IX", "V",  "IV", "I"};
  int units[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  int index = 0;
  char *s = (char *)malloc(sizeof(char) * 20);
  for (int i = 0; i < sizeof(units) / sizeof(int); i++) {
    while (num >= units[i]) {
      if (i % 2) {
        s[index++] = table[i][0];
        s[index++] = table[i][1];
      } else
        s[index++] = table[i][0];
      num -= units[i];
    }
  }
  s[index] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<intToRoman1>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2c77(%rip),%rsi
mov    $0x68,%edx
call   1030 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
lea    0xecf(%rip),%rsi
mov    $0x34,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0xb4(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0xc0(%rbp)
movl   $0x0,-0xc4(%rbp)
movslq -0xc4(%rbp),%rax
cmp    $0xd,%rax
jae    1282 <intToRoman1+0x162>
jmp    1196 <intToRoman1+0x76>
mov    -0x4(%rbp),%eax
movslq -0xc4(%rbp),%rcx
cmp    -0xb0(%rbp,%rcx,4),%eax
jl     1269 <intToRoman1+0x149>
mov    -0xc4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1222 <intToRoman1+0x102>
movslq -0xc4(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    (%rax),%dl
mov    -0xc0(%rbp),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xb4(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0xc4(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    0x1(%rax),%dl
mov    -0xc0(%rbp),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xb4(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    124e <intToRoman1+0x12e>
movslq -0xc4(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    (%rax),%dl
mov    -0xc0(%rbp),%rax
mov    -0xb4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xb4(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movslq -0xc4(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <intToRoman1+0x76>
jmp    126e <intToRoman1+0x14e>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    1180 <intToRoman1+0x60>
mov    -0xc0(%rbp),%rax
movslq -0xb4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc0(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman1>:
push   %rbx
mov    %edi,%ebx
mov    $0x14,%edi
call   1030 <malloc@plt>
xor    %r10d,%r10d
lea    0xef9(%rip),%r9
lea    0x2c82(%rip),%r8
xor    %edi,%edi
jmp    114a <intToRoman1+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r10
cmp    $0xd,%r10
je     1189 <intToRoman1+0x79>
mov    (%r9,%r10,4),%esi
cmp    %esi,%ebx
jl     1140 <intToRoman1+0x30>
mov    (%r8,%r10,8),%r11
jmp    116f <intToRoman1+0x5f>
nopl   0x0(%rax,%rax,1)
movslq %edi,%rdi
mov    %cl,(%rax,%rdi,1)
add    $0x1,%edi
sub    %esi,%ebx
cmp    %esi,%ebx
jl     1140 <intToRoman1+0x30>
movzbl (%r11),%ecx
test   $0x1,%r10b
je     1160 <intToRoman1+0x50>
movslq %edi,%rdx
add    $0x1,%edi
mov    %cl,(%rax,%rdx,1)
movzbl 0x1(%r11),%ecx
jmp    1160 <intToRoman1+0x50>
movslq %edi,%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"M\00"
@.str.1 = [3 x i8] c"CM\00"
@.str.2 = [2 x i8] c"D\00"
@.str.3 = [3 x i8] c"CD\00"
@.str.4 = [2 x i8] c"C\00"
@.str.5 = [3 x i8] c"XC\00"
@.str.6 = [2 x i8] c"L\00"
@.str.7 = [3 x i8] c"XL\00"
@.str.8 = [2 x i8] c"X\00"
@.str.9 = [3 x i8] c"IX\00"
@.str.10 = [2 x i8] c"V\00"
@.str.11 = [3 x i8] c"IV\00"
@.str.12 = [2 x i8] c"I\00"
@__const.intToRoman1.table = [13 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0)]
@__const.intToRoman1.units = [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]
define i8* @intToRoman1(i32 %0) {
%2 = alloca i32
%3 = alloca [13 x i8*]
%4 = alloca [13 x i32]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %2
%8 = bitcast [13 x i8*]* %3 to i8*
%9 = bitcast [13 x i32]* %4 to i8*
store i32 0, i32* %5
%10 = call i64 @malloc(i32 20)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
store i32 0, i32* %7
br label %12
12: ; preds = %71, %1
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %14, 13
br i1 %15, label %16, label %74
16: ; preds = %12
br label %17
17: ; preds = %63, %16
%18 = load i32, i32* %2
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [13 x i32], [13 x i32]* %4, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = icmp sge i32 %18, %22
br i1 %23, label %24, label %70
24: ; preds = %17
%25 = load i32, i32* %7
%26 = srem i32 %25, 2
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %51
28: ; preds = %24
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [13 x i8*], [13 x i8*]* %3, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 %34, i8* %39
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [13 x i8*], [13 x i8*]* %3, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = load i8*, i8** %6
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 %45, i8* %50
br label %63
51: ; preds = %24
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [13 x i8*], [13 x i8*]* %3, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = getelementptr inbounds i8, i8* %55, i64 0
%57 = load i8, i8* %56
%58 = load i8*, i8** %6
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
store i8 %57, i8* %62
br label %63
63: ; preds = %51, %28
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [13 x i32], [13 x i32]* %4, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = load i32, i32* %2
%69 = sub nsw i32 %68, %67
store i32 %69, i32* %2
br label %17
70: ; preds = %17
br label %71
71: ; preds = %70
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %12
74: ; preds = %12
%75 = load i8*, i8** %6
%76 = load i32, i32* %5
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 0, i8* %78
%79 = load i8*, i8** %6
ret i8* %79
}

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