#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char digit = 'a';
  int currentDigitValue = 0, previousDigitValue = 0, numberValue = 0;
  printf("Digite o numero romano:");
  while ((digit = getchar()) != '\n') {
    switch (digit) {
    case 'I':
    case 'i':
      currentDigitValue = 1;
      break;
    case 'V':
    case 'v':
      currentDigitValue = 5;
      break;
    case 'X':
    case 'x':
      currentDigitValue = 10;
      break;
    case 'L':
    case 'l':
      currentDigitValue = 50;
      break;
    case 'C':
    case 'c':
      currentDigitValue = 100;
      break;
    case 'D':
    case 'd':
      currentDigitValue = 500;
      break;
    case 'M':
    case 'm':
      currentDigitValue = 1000;
      break;
    default:
      currentDigitValue = 0;
    }
    numberValue += currentDigitValue;
    if (previousDigitValue < currentDigitValue)
      numberValue -= 2 * previousDigitValue;
    previousDigitValue = currentDigitValue;
  }
  printf("O numero em arabico:%d\n", numberValue);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x61,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xf89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     121f <main+0xff>
movsbl -0x5(%rbp),%eax
add    $0xffffffbd,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x35,%eax
ja     11ea <main+0xca>
mov    -0x20(%rbp),%rax
lea    0xe73(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x5,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0xa,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x32,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x64,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x1f4,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x3e8,-0xc(%rbp)
jmp    11f1 <main+0xd1>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1214 <main+0xf4>
mov    -0x10(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <main+0x36>
mov    -0x14(%rbp),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xfaa(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    115f <main+0x3f>
lea    0xfa7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
lea    0xe97(%rip),%r15
xor    %ebx,%ebx
xor    %ecx,%ecx
jmp    119c <main+0x7c>
mov    $0x3e8,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %ebp,%ebx
lea    (%rcx,%rcx,1),%eax
neg    %eax
cmp    %ebp,%ecx
cmovae %r14d,%eax
add    %eax,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %ebp,%ecx
cmp    $0xa,%al
je     1142 <main+0x22>
movsbl %al,%eax
add    $0xffffffbd,%eax
cmp    $0x35,%eax
ja     11d8 <main+0xb8>
mov    $0x1,%ebp
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x64,%ebp
jmp    1180 <main+0x60>
mov    $0x1f4,%ebp
jmp    1180 <main+0x60>
mov    $0x32,%ebp
jmp    1180 <main+0x60>
mov    $0x5,%ebp
jmp    1180 <main+0x60>
mov    $0xa,%ebp
jmp    1180 <main+0x60>
xor    %ebp,%ebp
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [24 x i8] c"Digite o numero romano:\00"
@.str.1 = [24 x i8] c"O numero em arabico:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8 97, i8* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %34, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %36
11: ; preds = %7
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
switch i32 %13, label %21 [
i32 73, label %14
i32 105, label %14
i32 86, label %15
i32 118, label %15
i32 88, label %16
i32 120, label %16
i32 76, label %17
i32 108, label %17
i32 67, label %18
i32 99, label %18
i32 68, label %19
i32 100, label %19
i32 77, label %20
i32 109, label %20
]
14: ; preds = %11, %11
store i32 1, i32* %3
br label %22
15: ; preds = %11, %11
store i32 5, i32* %3
br label %22
16: ; preds = %11, %11
store i32 10, i32* %3
br label %22
17: ; preds = %11, %11
store i32 50, i32* %3
br label %22
18: ; preds = %11, %11
store i32 100, i32* %3
br label %22
19: ; preds = %11, %11
store i32 500, i32* %3
br label %22
20: ; preds = %11, %11
store i32 1000, i32* %3
br label %22
21: ; preds = %11
store i32 0, i32* %3
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14
%23 = load i32, i32* %3
%24 = load i32, i32* %5
%25 = add nsw i32 %24, %23
store i32 %25, i32* %5
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i32, i32* %4
%31 = mul nsw i32 2, %30
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, %31
store i32 %33, i32* %5
br label %34
34: ; preds = %29, %22
%35 = load i32, i32* %3
store i32 %35, i32* %4
br label %7
36: ; preds = %7
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Digite o numero romano:\00"
@.str.1 = [24 x i8] c"O numero em arabico:%d\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 10
br i1 %3, label %25, label %4
4: ; preds = %0, %16
%5 = phi i8 [ %23, %16 ], [ %2, %0 ]
%6 = phi i32 [ %22, %16 ], [ 0, %0 ]
%7 = phi i32 [ %17, %16 ], [ 0, %0 ]
%8 = sext i8 %5 to i32
switch i32 %8, label %15 [
i32 73, label %16
i32 105, label %16
i32 86, label %9
i32 118, label %9
i32 88, label %10
i32 120, label %10
i32 76, label %11
i32 108, label %11
i32 67, label %12
i32 99, label %12
i32 68, label %13
i32 100, label %13
i32 77, label %14
i32 109, label %14
]
9: ; preds = %4, %4
br label %16
10: ; preds = %4, %4
br label %16
11: ; preds = %4, %4
br label %16
12: ; preds = %4, %4
br label %16
13: ; preds = %4, %4
br label %16
14: ; preds = %4, %4
br label %16
15: ; preds = %4
br label %16
16: ; preds = %4, %4, %15, %14, %13, %12, %11, %10, %9
%17 = phi i32 [ 0, %15 ], [ 1000, %14 ], [ 500, %13 ], [ 100, %12 ], [ 50, %11 ], [ 10, %10 ], [ 5, %9 ], [ 1, %4 ], [ 1, %4 ]
%18 = add nsw i32 %17, %6
%19 = icmp ult i32 %7, %17
%20 = mul nsw i32 %7, -2
%21 = select i1 %19, i32 %20, i32 0
%22 = add i32 %18, %21
%23 = tail call signext i8 (...) @getchar()
%24 = icmp eq i8 %23, 10
br i1 %24, label %25, label %4
25: ; preds = %16, %0
%26 = phi i32 [ 0, %0 ], [ %22, %16 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
}