#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int roman_to_int(char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
char toupper(char);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "No Roman string was passed as an argument.\n");
    return 1;
  }
  if (argc > 2) {
    fprintf(stderr, "Too many command-line arguments.\n");
    return 1;
  }
  int arg_len = strlen(argv[1]);
  char *arg_str = (char *)malloc(arg_len + 1);
  if (arg_str == NULL) {
    fprintf(stderr, "Couldn't allocate memory.\n");
    return 1;
  }
  memset(arg_str, 0, (arg_len + 1) * sizeof(char));
  for (int i = 0; i < arg_len; ++i)
    arg_str[i] = toupper(argv[1][i]);
  int value = roman_to_int(arg_str);
  if (value == -1) {
    fprintf(stderr, "Invalid roman numeral.\n");
    return -1;
  }
  printf("%d\n", value);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b1 <main+0x41>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
cmpl   $0x2,-0x8(%rbp)
jle    11dc <main+0x6c>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1227 <main+0xb7>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1283 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1247 <main+0xd7>
mov    -0x20(%rbp),%rdi
call   1090 <roman_to_int@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12ba <main+0x14a>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x28(%rbp),%esi
lea    0xdbd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     1192 <main+0x22>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
jmp    122b <main+0xbb>
cmp    $0x2,%edi
jne    1209 <main+0x99>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     121b <main+0xab>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
test   %r15d,%r15d
jle    11ea <main+0x7a>
mov    %r15d,%ebp
xor    %ebx,%ebx
nop
mov    0x8(%r14),%rax
movsbl (%rax,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <main+0x60>
mov    %r12,%rdi
call   1090 <roman_to_int@plt>
cmp    $0xffffffff,%eax
je     123e <main+0xce>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
jmp    1235 <main+0xc5>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
jmp    122b <main+0xbb>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1235 <main+0xc5>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"No Roman string was passed as an argument.\0A\00"
@.str.1 = [34 x i8] c"Too many command-line arguments.\0A\00"
@.str.2 = [27 x i8] c"Couldn't allocate memory.\0A\00"
@.str.3 = [24 x i8] c"Invalid roman numeral.\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %74
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %74
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %74
35: ; preds = %21
%36 = load i8*, i8** %7
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i32 @memset(i8* %36, i32 0, i32 %41)
store i32 0, i32* %8
br label %43
43: ; preds = %60, %35
%44 = load i32, i32* %8
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %63
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call signext i8 @toupper(i8 signext %54)
%56 = load i8*, i8** %7
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %47
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %43
63: ; preds = %43
%64 = load i8*, i8** %7
%65 = call i32 @roman_to_int(i8* %64)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %74
71: ; preds = %63
%72 = load i32, i32* %9
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %72)
store i32 0, i32* %3
br label %74
74: ; preds = %71, %68, %32, %18, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"No Roman string was passed as an argument.\0A\00"
@.str.1 = [34 x i8] c"Too many command-line arguments.\0A\00"
@.str.2 = [27 x i8] c"Couldn't allocate memory.\0A\00"
@.str.3 = [24 x i8] c"Invalid roman numeral.\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %45
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %45
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = tail call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %45
23: ; preds = %12
%24 = tail call i32 @memset(i8* %18, i32 0, i32 %16)
%25 = icmp sgt i32 %15, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = zext i32 %15 to i64
br label %31
28: ; preds = %31, %23
%29 = tail call i32 @roman_to_int(i8* %18)
%30 = icmp eq i32 %29, -1
br i1 %30, label %40, label %43
31: ; preds = %26, %31
%32 = phi i64 [ 0, %26 ], [ %38, %31 ]
%33 = load i8*, i8** %13
%34 = getelementptr inbounds i8, i8* %33, i64 %32
%35 = load i8, i8* %34
%36 = tail call signext i8 @toupper(i8 signext %35)
%37 = getelementptr inbounds i8, i8* %18, i64 %32
store i8 %36, i8* %37
%38 = add nuw nsw i64 %32, 1
%39 = icmp eq i64 %38, %27
br i1 %39, label %28, label %31
40: ; preds = %28
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %45
43: ; preds = %28
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %45
45: ; preds = %20, %43, %40, %9, %4
%46 = phi i32 [ 1, %4 ], [ 1, %9 ], [ 1, %20 ], [ -1, %40 ], [ 0, %43 ]
ret i32 %46
}