#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 */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void roman(char *buf, unsigned int n) {
  n /= 10;
  static const struct {
    char *str;
    unsigned int val;
  } symbols[] = {{"M", 1000}, {"CM", 900}, {"D", 500}, {"CD", 400}, {"C", 100},
                 {"XC", 90},  {"L", 50},   {"XL", 40}, {"X", 10},   {"IX", 9},
                 {"V", 5},    {"IV", 4},   {"I", 1},   {NULL, 0}};
  buf[0] = '\0';
  for (unsigned int i = 0; symbols[i].val > 0; ++i) {
    while (n >= symbols[i].val) {
      assert(strlen(buf) + strlen(symbols[i].str) < 128);
      strcat(buf, symbols[i].str);
      n -= symbols[i].val;
    }
  }
  assert(n == 0);
}


x86 assembly (clang, -O0):
<roman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2bd8(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpl   $0x0,0x8(%rax)
jbe    1232 <roman+0x102>
jmp    117e <roman+0x4e>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
lea    0x2bb3(%rip),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
cmp    0x8(%rcx),%eax
jb     121f <roman+0xef>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2b8b(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
cmp    $0x80,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2b53(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2b38(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <roman+0x4e>
jmp    1224 <roman+0xf4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <roman+0x2c>
cmpl   $0x0,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roman>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%eax
mov    $0xcccccccd,%ebp
imul   %rax,%rbp
shr    $0x23,%rbp
movb   $0x0,(%rdi)
lea    0x2bf1(%rip),%rax
xor    %r12d,%r12d
jmp    1183 <roman+0x53>
nopl   0x0(%rax)
mov    (%rsp),%r12
add    $0x1,%r12
mov    %r12,%rax
shl    $0x4,%rax
lea    0x2bca(%rip),%rcx
add    %rcx,%rax
add    $0x8,%rax
cmp    $0xd,%r12
je     11df <roman+0xaf>
mov    (%rax),%r13d
cmp    %r13d,%ebp
mov    %r12,(%rsp)
jb     1160 <roman+0x30>
shl    $0x4,%r12
lea    0x2ba6(%rip),%rax
add    %rax,%r12
nopl   (%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    (%r12),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %r15d,%eax
xor    %edi,%edi
cmp    $0x80,%eax
setl   %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
sub    %r13d,%ebp
cmp    %r13d,%ebp
jae    11a0 <roman+0x70>
jmp    1160 <roman+0x30>
xor    %edi,%edi
test   %ebp,%ebp
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
%struct.anon = type { i8*, i32 }
@roman.symbols = internal constant [14 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i32 1000 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i32 900 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i32 500 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i32 400 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i32 100 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i32 90 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i32 50 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i32 40 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i32 10 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i32 9 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i32 0, i32 0), i32 5 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i32 0, i32 0), i32 4 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0), i32 1 }, %struct.anon zeroinitializer]
@.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"
define void @roman(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = udiv i32 %6, 10
store i32 %7, i32* %4
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
store i32 0, i32* %5
br label %10
10: ; preds = %54, %2
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %12
%14 = getelementptr inbounds %struct.anon, %struct.anon* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = icmp ugt i32 %15, 0
br i1 %16, label %17, label %57
17: ; preds = %10
br label %18
18: ; preds = %26, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %21
%23 = getelementptr inbounds %struct.anon, %struct.anon* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = icmp uge i32 %19, %24
br i1 %25, label %26, label %53
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = load i32, i32* %5
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %30
%32 = getelementptr inbounds %struct.anon, %struct.anon* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %28, %34
%36 = icmp slt i32 %35, 128
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %41
%43 = getelementptr inbounds %struct.anon, %struct.anon* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i32 @strcat(i8* %39, i8* %44)
%46 = load i32, i32* %5
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %47
%49 = getelementptr inbounds %struct.anon, %struct.anon* %48, i32 0, i32 1
%50 = load i32, i32* %49
%51 = load i32, i32* %4
%52 = sub i32 %51, %50
store i32 %52, i32* %4
br label %18
53: ; preds = %18
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = add i32 %55, 1
store i32 %56, i32* %5
br label %10
57: ; preds = %10
%58 = load i32, i32* %4
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
ret void
}

LLVM IR (-O2):
%struct.anon = type { i8*, i32 }
@roman.symbols = internal unnamed_addr constant [14 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i32 1000 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i32 900 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i32 500 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i32 400 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i32 100 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i32 90 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i32 50 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i32 40 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i32 0, i32 0), i32 10 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i32 9 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i32 0, i32 0), i32 5 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i32 0, i32 0), i32 4 }, %struct.anon { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0), i32 1 }, %struct.anon zeroinitializer]
@.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"
define void @roman(i8* %0, i32 %1) {
%3 = udiv i32 %1, 10
store i8 0, i8* %0
br label %4
4: ; preds = %2, %28
%5 = phi i64 [ 0, %2 ], [ %30, %28 ]
%6 = phi i32* [ getelementptr inbounds ([14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 0, i32 1), %2 ], [ %31, %28 ]
%7 = phi i32 [ %3, %2 ], [ %29, %28 ]
%8 = load i32, i32* %6
%9 = icmp ult i32 %7, %8
br i1 %9, label %28, label %10
10: ; preds = %4
%11 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %5, i32 0
br label %16
12: ; preds = %28
%13 = icmp eq i32 %29, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret void
16: ; preds = %10, %16
%17 = phi i32 [ %7, %10 ], [ %26, %16 ]
%18 = tail call i32 @strlen(i8* %0)
%19 = load i8*, i8** %11
%20 = tail call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, %18
%22 = icmp slt i32 %21, 128
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @strcat(i8* %0, i8* %19)
%26 = sub i32 %17, %8
%27 = icmp ult i32 %26, %8
br i1 %27, label %28, label %16
28: ; preds = %16, %4
%29 = phi i32 [ %7, %4 ], [ %26, %16 ]
%30 = add nuw nsw i64 %5, 1
%31 = getelementptr inbounds [14 x %struct.anon], [14 x %struct.anon]* @roman.symbols, i64 0, i64 %30, i32 1
%32 = icmp eq i64 %30, 13
br i1 %32, label %12, label %4
}