void decimalToRoman(int nb, char *target) {
  strcpy(target, "");
  char symbols[][3] = {"M",  "CM", "D",  "CD", "C",  "XC", "L",
                       "XL", "X",  "IX", "V",  "IV", "I"};
  int value[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
  int i;
  while (nb) {
    for (i = 0; i < sizeof(value) / sizeof(value[0]); i++) {
      if (nb >= value[i])
        break;
    }
    strcat(target, symbols[i]);
    nb -= value[i];
  }
}


x86 assembly (clang, -O0):
<decimalToRoman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb3(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x27,%edx
call   1040 <memcpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xece(%rip),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x4(%rbp)
je     1206 <decimalToRoman+0xd6>
movl   $0x0,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmp    $0xd,%rax
jae    11d3 <decimalToRoman+0xa3>
mov    -0x4(%rbp),%eax
movslq -0x84(%rbp),%rcx
cmp    -0x80(%rbp,%rcx,4),%eax
jl     11ba <decimalToRoman+0x8a>
jmp    11d3 <decimalToRoman+0xa3>
jmp    11bf <decimalToRoman+0x8f>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1190 <decimalToRoman+0x60>
mov    -0x10(%rbp),%rdi
movslq -0x84(%rbp),%rax
lea    -0x40(%rbp),%rsi
imul   $0x3,%rax,%rax
add    %rax,%rsi
call   1050 <strcat@plt>
movslq -0x84(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    117c <decimalToRoman+0x4c>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decimalToRoman>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movb   $0x0,(%rsi)
mov    0xefb(%rip),%rax
mov    %rax,0x1f(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
test   %edi,%edi
je     1211 <decimalToRoman+0x101>
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xedc(%rip),%r14
jmp    117c <decimalToRoman+0x6c>
cs nopw 0x0(%rax,%rax,1)
xor    %ebx,%ebx
lea    (%rbx,%rbx,2),%rax
lea    (%rsp,%rax,1),%rsi
mov    %r15,%rdi
call   1030 <strcat@plt>
sub    (%r14,%rbx,4),%ebp
je     1211 <decimalToRoman+0x101>
cmp    $0x3e7,%ebp
jg     1160 <decimalToRoman+0x50>
mov    $0x1,%ebx
cmp    $0x383,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x2,%ebx
cmp    $0x1f3,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x3,%ebx
cmp    $0x18f,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x4,%ebx
cmp    $0x63,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x5,%ebx
cmp    $0x59,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x6,%ebx
cmp    $0x31,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x7,%ebx
cmp    $0x27,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x8,%ebx
cmp    $0x9,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0x9,%ebx
je     1162 <decimalToRoman+0x52>
mov    $0xa,%ebx
cmp    $0x4,%ebp
jg     1162 <decimalToRoman+0x52>
mov    $0xb,%ebx
je     1162 <decimalToRoman+0x52>
xor    %ebx,%ebx
test   %ebp,%ebp
setle  %bl
or     $0xc,%rbx
jmp    1162 <decimalToRoman+0x52>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@__const.decimalToRoman.symbols = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
@__const.decimalToRoman.value = [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 void @decimalToRoman(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [13 x [3 x i8]]
%6 = alloca [13 x i32]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i8* @strcpy(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = bitcast [13 x [3 x i8]]* %5 to i8*
%11 = bitcast [13 x i32]* %6 to i8*
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %12
store i32 0, i32* %7
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 13
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %3
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = icmp sge i32 %21, %25
br i1 %26, label %27, label %28
27: ; preds = %20
br label %32
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %16
32: ; preds = %27, %16
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %5, i64 0, i64 %35
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %36, i64 0, i64 0
%38 = call i8* @strcat(i8* %33, i8* %37)
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [13 x i32], [13 x i32]* %6, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %3
%44 = sub nsw i32 %43, %42
store i32 %44, i32* %3
br label %12
45: ; preds = %12
ret void
}

LLVM IR (-O2):
@__const.decimalToRoman.symbols = [13 x [3 x i8]] [[3 x i8] c"M\00\00", [3 x i8] c"CM\00", [3 x i8] c"D\00\00", [3 x i8] c"CD\00", [3 x i8] c"C\00\00", [3 x i8] c"XC\00", [3 x i8] c"L\00\00", [3 x i8] c"XL\00", [3 x i8] c"X\00\00", [3 x i8] c"IX\00", [3 x i8] c"V\00\00", [3 x i8] c"IV\00", [3 x i8] c"I\00\00"]
@__const.decimalToRoman.value = [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 void @decimalToRoman(i32 %0, i8* %1) {
%3 = alloca [13 x [3 x i8]]
store i8 0, i8* %1
%4 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %3, i64 0, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %42, label %6
6: ; preds = %2, %34
%7 = phi i32 [ %40, %34 ], [ %0, %2 ]
%8 = icmp slt i32 %7, 1000
br i1 %8, label %9, label %34
9: ; preds = %6
%10 = icmp slt i32 %7, 900
br i1 %10, label %11, label %34
11: ; preds = %9
%12 = icmp slt i32 %7, 500
br i1 %12, label %13, label %34
13: ; preds = %11
%14 = icmp slt i32 %7, 400
br i1 %14, label %15, label %34
15: ; preds = %13
%16 = icmp slt i32 %7, 100
br i1 %16, label %17, label %34
17: ; preds = %15
%18 = icmp slt i32 %7, 90
br i1 %18, label %19, label %34
19: ; preds = %17
%20 = icmp slt i32 %7, 50
br i1 %20, label %21, label %34
21: ; preds = %19
%22 = icmp slt i32 %7, 40
br i1 %22, label %23, label %34
23: ; preds = %21
%24 = icmp slt i32 %7, 10
br i1 %24, label %25, label %34
25: ; preds = %23
%26 = icmp eq i32 %7, 9
br i1 %26, label %34, label %27
27: ; preds = %25
%28 = icmp slt i32 %7, 5
br i1 %28, label %29, label %34
29: ; preds = %27
%30 = icmp eq i32 %7, 4
br i1 %30, label %34, label %31
31: ; preds = %29
%32 = icmp slt i32 %7, 1
%33 = select i1 %32, i64 13, i64 12
br label %34
34: ; preds = %31, %29, %27, %25, %23, %21, %19, %17, %15, %13, %11, %9, %6
%35 = phi i64 [ 0, %6 ], [ 1, %9 ], [ 2, %11 ], [ 3, %13 ], [ 4, %15 ], [ 5, %17 ], [ 6, %19 ], [ 7, %21 ], [ 8, %23 ], [ 9, %25 ], [ 10, %27 ], [ 11, %29 ], [ %33, %31 ]
%36 = getelementptr inbounds [13 x [3 x i8]], [13 x [3 x i8]]* %3, i64 0, i64 %35, i64 0
%37 = call i8* @strcat(i8* %1, i8* %36)
%38 = getelementptr inbounds [13 x i32], [13 x i32]* @__const.decimalToRoman.value, i64 0, i64 %35
%39 = load i32, i32* %38
%40 = sub nsw i32 %7, %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %6
42: ; preds = %34, %2
ret void
}