#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 */
scalar_t__ checkRomanN(char *);
scalar_t__ getRomanValue(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char romanNumber[20];
  int i, curNum;
  while (1) {
    curNum = 0;
    printf("Input roman number: ");
    scanf("%s", romanNumber);
    if (checkRomanN(romanNumber) == 0) {
      printf("Input a valid roman number\n");
      continue;
    }
    for (i = 0; i < strlen(romanNumber); i++) {
      if (getRomanValue(romanNumber[i]) < getRomanValue(romanNumber[i + 1])) {
        curNum +=
            getRomanValue(romanNumber[i + 1]) - getRomanValue(romanNumber[i]);
        i++;
      } else
        curNum += getRomanValue(romanNumber[i]);
    }
    if (curNum > 256) {
      printf("Number is larger than 256\n");
      continue;
    } else {
      printf("Roman number in decimal is: %d\n", curNum);
      break;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1040 <checkRomanN@plt>
cmp    $0x0,%rax
jne    11aa <main+0x5a>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    115f <main+0xf>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1272 <main+0x122>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%edi
call   1070 <getRomanValue@plt>
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x20(%rbp,%rax,1),%edi
call   1070 <getRomanValue@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jge    1244 <main+0xf4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x20(%rbp,%rax,1),%edi
call   1070 <getRomanValue@plt>
mov    %rax,-0x40(%rbp)
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%edi
call   1070 <getRomanValue@plt>
mov    -0x40(%rbp),%rcx
sub    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125f <main+0x10f>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%edi
call   1070 <getRomanValue@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
jmp    1264 <main+0x114>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b1 <main+0x61>
cmpl   $0x100,-0x28(%rbp)
jle    1292 <main+0x142>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    115f <main+0xf>
mov    -0x28(%rbp),%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r12
lea    0xeda(%rip),%r13
jmp    1198 <main+0x38>
nopw   0x0(%rax,%rax,1)
lea    0xeb1(%rip),%rdi
cmp    $0x100,%ebp
jle    1243 <main+0xe3>
call   1030 <puts@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe68(%rip),%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    %r12,%rdi
call   1050 <checkRomanN@plt>
mov    %r13,%rdi
test   %rax,%rax
je     1193 <main+0x33>
mov    %r12,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    1243 <main+0xe3>
xor    %r14d,%r14d
jmp    11ff <main+0x9f>
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%r14,1),%edi
call   1080 <getRomanValue@plt>
mov    %rax,%rbx
mov    %r15d,%r14d
add    %ebx,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r14d
jge    1180 <main+0x20>
movslq %r14d,%r14
movsbl (%rsp,%r14,1),%edi
call   1080 <getRomanValue@plt>
mov    %rax,%rbx
lea    0x1(%r14),%r15
movsbl 0x1(%rsp,%r14,1),%edi
call   1080 <getRomanValue@plt>
cmp    %rax,%rbx
jge    11e0 <main+0x80>
movsbl (%rsp,%r15,1),%edi
call   1080 <getRomanValue@plt>
mov    %rax,%rbx
movsbl (%rsp,%r14,1),%edi
call   1080 <getRomanValue@plt>
sub    %rax,%rbx
add    $0x2,%r14d
jmp    11f0 <main+0x90>
lea    0xdce(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Input roman number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [28 x i8] c"Input a valid roman number\0A\00"
@.str.3 = [27 x i8] c"Number is larger than 256\0A\00"
@.str.4 = [32 x i8] c"Roman number in decimal is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %0, %12, %69
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = call i64 @checkRomanN(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %5
14: ; preds = %5
store i32 0, i32* %3
br label %15
15: ; preds = %63, %14
%16 = load i32, i32* %3
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %66
20: ; preds = %15
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = call i64 @getRomanValue(i8 signext %24)
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i64 @getRomanValue(i8 signext %30)
%32 = icmp slt i64 %25, %31
br i1 %32, label %33, label %52
33: ; preds = %20
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i64 @getRomanValue(i8 signext %38)
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = call i64 @getRomanValue(i8 signext %43)
%45 = sub nsw i64 %39, %44
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = add nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %4
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %62
52: ; preds = %20
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i64 @getRomanValue(i8 signext %56)
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %4
br label %62
62: ; preds = %52, %33
br label %63
63: ; preds = %62
%64 = load i32, i32* %3
%65 = add nsw i32 %64, 1
store i32 %65, i32* %3
br label %15
66: ; preds = %15
%67 = load i32, i32* %4
%68 = icmp sgt i32 %67, 256
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %5
71: ; preds = %66
%72 = load i32, i32* %4
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %72)
br label %74
74: ; preds = %71
ret i32 1
}

LLVM IR (-O2):
@.str = [21 x i8] c"Input roman number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.4 = [32 x i8] c"Roman number in decimal is: %d\0A\00"
@str = [26 x i8] c"Number is larger than 256\00"
@str.5 = [27 x i8] c"Input a valid roman number\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %11, %0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i64 @checkRomanN(i8* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i32 @strlen(i8* %2)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %14, label %46
11: ; preds = %3, %44
%12 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0), %44 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0), %3 ]
%13 = call i32 @puts(i8* dereferenceable(1) %12)
br label %3
14: ; preds = %8, %37
%15 = phi i32 [ %41, %37 ], [ 0, %8 ]
%16 = phi i32 [ %38, %37 ], [ 0, %8 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @getRomanValue(i8 signext %19)
%21 = add nsw i32 %16, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = call i64 @getRomanValue(i8 signext %24)
%26 = icmp slt i64 %20, %25
br i1 %26, label %27, label %34
27: ; preds = %14
%28 = load i8, i8* %23
%29 = call i64 @getRomanValue(i8 signext %28)
%30 = load i8, i8* %18
%31 = call i64 @getRomanValue(i8 signext %30)
%32 = sub nsw i64 %29, %31
%33 = add nsw i32 %16, 2
br label %37
34: ; preds = %14
%35 = load i8, i8* %18
%36 = call i64 @getRomanValue(i8 signext %35)
br label %37
37: ; preds = %27, %34
%38 = phi i32 [ %33, %27 ], [ %21, %34 ]
%39 = phi i64 [ %32, %27 ], [ %36, %34 ]
%40 = trunc i64 %39 to i32
%41 = add i32 %15, %40
%42 = call i32 @strlen(i8* %2)
%43 = icmp slt i32 %38, %42
br i1 %43, label %14, label %44
44: ; preds = %37
%45 = icmp sgt i32 %41, 256
br i1 %45, label %11, label %46
46: ; preds = %8, %44
%47 = phi i32 [ %41, %44 ], [ 0, %8 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %47)
ret i32 1
}