#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*/ getRomanDigit(char *, char, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *decimal2Roman(char *rslt, unsigned x) {
  unsigned char power;
  char buf[10];
  char oldRslt[20];
  for (*rslt = '\0', power = 0; x > 0; power++, x /= 10) {
    getRomanDigit(buf, (char)(x % 10), power);
    strcpy(oldRslt, rslt);
    strcpy(rslt, buf);
    strcat(rslt, oldRslt);
  }
  return rslt;
}


x86 assembly (clang, -O0):
<decimal2Roman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movb   $0x0,-0xd(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    11b5 <decimal2Roman+0x85>
lea    -0x17(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%al
movsbl %al,%esi
movzbl -0xd(%rbp),%edx
call   1050 <getRomanDigit@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x17(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
jmp    114a <decimal2Roman+0x1a>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decimal2Roman>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movb   $0x0,(%rdi)
test   %esi,%esi
je     11b8 <decimal2Roman+0x88>
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0x6(%rsp),%r15
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%r13d
mov    $0xcccccccd,%eax
imul   %rax,%r13
shr    $0x23,%r13
lea    0x0(%r13,%r13,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
movsbl %cl,%esi
movzbl %bl,%ebx
mov    %r15,%rdi
mov    %ebx,%edx
call   1050 <getRomanDigit@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strcat@plt>
add    $0x1,%bl
cmp    $0x9,%ebp
mov    %r13d,%ebp
ja     1160 <decimal2Roman+0x30>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @decimal2Roman(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca [10 x i8]
%7 = alloca [20 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8 0, i8* %8
store i8 0, i8* %5
br label %9
9: ; preds = %28, %2
%10 = load i32, i32* %4
%11 = icmp ugt i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* %4
%15 = urem i32 %14, 10
%16 = trunc i32 %15 to i8
%17 = load i8, i8* %5
%18 = call i32 @getRomanDigit(i8* %13, i8 signext %16, i8 zeroext %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%27 = call i32 @strcat(i8* %25, i8* %26)
br label %28
28: ; preds = %12
%29 = load i8, i8* %5
%30 = add i8 %29, 1
store i8 %30, i8* %5
%31 = load i32, i32* %4
%32 = udiv i32 %31, 10
store i32 %32, i32* %4
br label %9
33: ; preds = %9
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
define i8* @decimal2Roman(i8* returned %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
store i8 0, i8* %0
%7 = icmp eq i32 %1, 0
br i1 %7, label %20, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %17, %8 ], [ 0, %2 ]
%10 = phi i32 [ %18, %8 ], [ %1, %2 ]
%11 = urem i32 %10, 10
%12 = trunc i32 %11 to i8
%13 = call i32 @getRomanDigit(i8* %5, i8 signext %12, i8 zeroext %9)
%14 = call i32 @strcpy(i8* %6, i8* %0)
%15 = call i32 @strcpy(i8* %0, i8* %5)
%16 = call i32 @strcat(i8* %0, i8* %6)
%17 = add i8 %9, 1
%18 = udiv i32 %10, 10
%19 = icmp ult i32 %10, 10
br i1 %19, label %20, label %8
20: ; preds = %8, %2
ret i8* %0
}