#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*/ symbolValues;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char const *);
char *strdup(char *);
char *intToRoman(int Value) {
  if (Value >= 4000) {
    return 0;
  }
  char romanNumeral[64];
  memset(romanNumeral, 0, 64);
  int symbolValues[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  const char *symbolsForValues[] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                                    "XL", "X",  "IX", "V",  "IV", "I"};
  int symbolValueCount = sizeof(symbolValues) / sizeof(symbolValues[0]);
  int index = 0;
  for (index = 0; index < symbolValueCount; ++index) {
    for (; Value >= symbolValues[index]; Value -= symbolValues[index]) {
      strcat(romanNumeral, symbolsForValues[index]);
    }
  }
  return strdup(romanNumeral);
}


x86 assembly (clang, -O0):
<intToRoman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0xfa0,-0xc(%rbp)
jl     1168 <intToRoman+0x28>
movq   $0x0,-0x8(%rbp)
jmp    124d <intToRoman+0x10d>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    -0x90(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
lea    -0x100(%rbp),%rdi
lea    0x2c12(%rip),%rsi
mov    $0x68,%edx
call   1040 <memcpy@plt>
movl   $0xd,-0x104(%rbp)
movl   $0x0,-0x108(%rbp)
movl   $0x0,-0x108(%rbp)
mov    -0x108(%rbp),%eax
cmp    -0x104(%rbp),%eax
jge    1240 <intToRoman+0x100>
jmp    11dd <intToRoman+0x9d>
mov    -0xc(%rbp),%eax
movslq -0x108(%rbp),%rcx
cmp    -0x90(%rbp,%rcx,4),%eax
jl     1227 <intToRoman+0xe7>
lea    -0x50(%rbp),%rdi
movslq -0x108(%rbp),%rax
mov    -0x100(%rbp,%rax,8),%rsi
ff
call   1050 <strcat@plt>
movslq -0x108(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11dd <intToRoman+0x9d>
jmp    122c <intToRoman+0xec>
mov    -0x108(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x108(%rbp)
jmp    11c6 <intToRoman+0x86>
lea    -0x50(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToRoman>:
cmp    $0xf9f,%edi
jle    113b <intToRoman+0xb>
xor    %eax,%eax
ret
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
lea    0xecd(%rip),%rbp
jmp    117a <intToRoman+0x4a>
nopl   0x0(%rax)
add    $0x1,%r12
cmp    $0xd,%r12
je     11b5 <intToRoman+0x85>
lea    0xe7f(%rip),%rax
mov    (%rax,%r12,4),%r13d
cmp    %r13d,%ebx
jl     1170 <intToRoman+0x40>
movslq 0x0(%rbp,%r12,4),%r15
add    %rbp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
sub    %r13d,%ebx
cmp    %r13d,%ebx
jge    11a0 <intToRoman+0x70>
jmp    1170 <intToRoman+0x40>
mov    %rsp,%rdi
call   1050 <strdup@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.intToRoman.symbolValues = [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]
@.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.intToRoman.symbolsForValues = [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)]
define i8* @intToRoman(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [13 x i32]
%6 = alloca [13 x i8*]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 4000
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %50
12: ; preds = %1
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 64)
%15 = bitcast [13 x i32]* %5 to i8*
%16 = bitcast [13 x i8*]* %6 to i8*
store i32 13, i32* %7
store i32 0, i32* %8
store i32 0, i32* %8
br label %17
17: ; preds = %44, %12
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %47
21: ; preds = %17
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %3
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [13 x i32], [13 x i32]* %5, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp sge i32 %23, %27
br i1 %28, label %29, label %43
29: ; preds = %22
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [13 x i8*], [13 x i8*]* %6, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @strcat(i8* %30, i8* %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [13 x i32], [13 x i32]* %5, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %3
%42 = sub nsw i32 %41, %40
store i32 %42, i32* %3
br label %22
43: ; preds = %22
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %17
47: ; preds = %17
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%49 = call i8* @strdup(i8* %48)
store i8* %49, i8** %2
br label %50
50: ; preds = %47, %11
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@__const.intToRoman.symbolValues = [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]
@.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"
@reltable.intToRoman = [13 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.2 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.4 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.5 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.6 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.7 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.8 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.9 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.10 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.11 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.12 to i64), i64 ptrtoint ([13 x i32]* @reltable.intToRoman to i64)) to i32)]
define noalias i8* @intToRoman(i32 %0) {
%2 = alloca [64 x i8]
%3 = icmp sgt i32 %0, 3999
br i1 %3, label %27, label %4
4: ; preds = %1
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 64)
br label %7
7: ; preds = %4, %21
%8 = phi i64 [ 0, %4 ], [ %23, %21 ]
%9 = phi i32 [ %0, %4 ], [ %22, %21 ]
%10 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.intToRoman.symbolValues, 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 = shl i64 %8, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([13 x i32]* @reltable.intToRoman to i8*), i64 %14)
br label %16
16: ; preds = %13, %16
%17 = phi i32 [ %9, %13 ], [ %19, %16 ]
%18 = call i32 @strcat(i8* %5, i8* %15)
%19 = sub nsw i32 %17, %11
%20 = icmp slt i32 %19, %11
br i1 %20, label %21, label %16
21: ; preds = %16, %7
%22 = phi i32 [ %9, %7 ], [ %19, %16 ]
%23 = add nuw nsw i64 %8, 1
%24 = icmp eq i64 %23, 13
br i1 %24, label %25, label %7
25: ; preds = %21
%26 = call i8* @strdup(i8* %5)
br label %27
27: ; preds = %1, %25
%28 = phi i8* [ %26, %25 ], [ null, %1 ]
ret i8* %28
}