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

/* Variables and functions */
char *abbreviate(char *);
int /*<<< orphan*/ abs(int);
int /*<<< orphan*/ free(char *);
char *int_to_char(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *int_to_roman(int arabic) {
  char *prefix = arabic < 0 ? "-" : "";
  char *expanded = int_to_char(abs(arabic));
  char *postfix = abbreviate(expanded);
  char *result = malloc(sizeof(prefix) + sizeof(postfix));
  strcpy(result, prefix);
  strcat(result, postfix);
  free(expanded);
  free(postfix);
  return result;
}


x86 assembly (clang, -O0):
<int_to_roman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
lea    0xe7c(%rip),%rax
lea    0xe74(%rip),%rcx
cmp    $0x0,%edx
cmovl  %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <abs@plt>
mov    %eax,%edi
call   1090 <int_to_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <abbreviate@plt>
mov    %rax,-0x20(%rbp)
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_roman>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
lea    0xe8f(%rip),%rax
lea    0xe89(%rip),%r12
cmovs  %rax,%r12
mov    %edi,%eax
neg    %eax
cmovns %eax,%edi
call   1080 <int_to_char@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <abbreviate@plt>
mov    %rax,%r15
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @int_to_roman(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
store i8* %10, i8** %3
%11 = load i32, i32* %2
%12 = call i32 @abs(i32 %11)
%13 = call i8* @int_to_char(i32 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i8* @abbreviate(i8* %14)
store i8* %15, i8** %5
%16 = call i8* @malloc(i32 16)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %6
ret i8* %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @int_to_roman(i32 %0) {
%2 = icmp slt i32 %0, 0
%3 = select i1 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%5 = tail call i8* @int_to_char(i32 %4)
%6 = tail call i8* @abbreviate(i8* %5)
%7 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%8 = tail call i32 @strcpy(i8* %7, i8* %3)
%9 = tail call i32 @strcat(i8* %7, i8* %6)
%10 = tail call i32 @free(i8* %5)
%11 = tail call i32 @free(i8* %6)
ret i8* %7
}