#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 n(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char r[10];
  int i = 0;
  int number = 0;
  printf("Enter roman number:\n");
  scanf("%s", r);
  while (r[i]) {
    if (number < 0) {
      printf("Invalid number");
      return 0;
    }
    if (number > 256) {
      printf("The number is above 256");
      return 0;
    }
    if ((strlen(r) - i) > 2) {
      if (n(r[i]) < n(r[i + 2])) {
        printf("Invalid number");
        return 0;
      }
    }
    if (n(r[i]) >= n(r[i + 1]))
      number = number + n(r[i]);
    else {
      number = number + (n(r[i + 1]) - n(r[i]));
      i++;
      printf("Invalid number");
    }
    i++;
  }
  printf("%d", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1060 <scanf@plt>
movslq -0x14(%rbp),%rax
cmpb   $0x0,-0xe(%rbp,%rax,1)
je     12e9 <main+0x1a9>
cmpl   $0x0,-0x18(%rbp)
jge    11ae <main+0x6e>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1301 <main+0x1c1>
cmpl   $0x100,-0x18(%rbp)
jle    11d5 <main+0x95>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1301 <main+0x1c1>
lea    -0xe(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x14(%rbp),%eax
cmp    $0x2,%eax
jle    1239 <main+0xf9>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1234 <main+0xf4>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1301 <main+0x1c1>
jmp    1239 <main+0xf9>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jl     128c <main+0x14c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    12db <main+0x19b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1030 <n@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%edx
mov    -0x28(%rbp),%eax
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <main+0x3b>
mov    -0x18(%rbp),%esi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
lea    0xe(%rsp),%r15
mov    %r15,%rsi
call   1070 <scanf@plt>
cmpb   $0x0,0xe(%rsp)
je     124e <main+0xfe>
mov    %r15,%r13
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    11e0 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0xe(%rsp,%r14,1),%edi
call   1040 <n@plt>
mov    %eax,%ebx
movsbl 0x0(%r13),%edi
call   1040 <n@plt>
sub    %eax,%ebx
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x2,%r12d
movslq %r12d,%r14
add    %ebx,%ebp
lea    (%rsp,%r14,1),%r13
add    $0xe,%r13
cmpb   $0x0,0xe(%rsp,%r14,1)
je     1250 <main+0x100>
test   %ebp,%ebp
js     1262 <main+0x112>
cmp    $0x101,%ebp
jae    126b <main+0x11b>
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %r12d,%eax
movslq %r12d,%r14
cmp    $0x3,%eax
jl     121a <main+0xca>
movsbl 0x0(%r13),%edi
call   1040 <n@plt>
mov    %eax,%ebx
movsbl 0x2(%r14,%r15,1),%edi
call   1040 <n@plt>
cmp    %eax,%ebx
jl     1262 <main+0x112>
movsbl 0x0(%r13),%edi
call   1040 <n@plt>
mov    %eax,%ebx
movsbl 0xf(%rsp,%r14,1),%edi
add    $0x1,%r14
call   1040 <n@plt>
cmp    %eax,%ebx
jl     11a0 <main+0x50>
movsbl 0x0(%r13),%edi
call   1040 <n@plt>
mov    %eax,%ebx
mov    %r14d,%r12d
jmp    11ce <main+0x7e>
xor    %ebp,%ebp
lea    0xdd3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1279 <main+0x129>
lea    0xd9a(%rip),%rdi
jmp    1272 <main+0x122>
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%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"Enter roman number:\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"Invalid number\00"
@.str.3 = [24 x i8] c"The number is above 256\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %8
8: ; preds = %85, %0
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %88
14: ; preds = %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %91
19: ; preds = %14
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 256
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %91
24: ; preds = %19
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = load i32, i32* %3
%28 = sub nsw i32 %26, %27
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %46
30: ; preds = %24
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @n(i8 signext %34)
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @n(i8 signext %40)
%42 = icmp slt i32 %35, %41
br i1 %42, label %43, label %45
43: ; preds = %30
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %91
45: ; preds = %30
br label %46
46: ; preds = %45, %24
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = call i32 @n(i8 signext %50)
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @n(i8 signext %56)
%58 = icmp sge i32 %51, %57
br i1 %58, label %59, label %67
59: ; preds = %46
%60 = load i32, i32* %4
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = call i32 @n(i8 signext %64)
%66 = add nsw i32 %60, %65
store i32 %66, i32* %4
br label %85
67: ; preds = %46
%68 = load i32, i32* %4
%69 = load i32, i32* %3
%70 = add nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = call i32 @n(i8 signext %73)
%75 = load i32, i32* %3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = call i32 @n(i8 signext %78)
%80 = sub nsw i32 %74, %79
%81 = add nsw i32 %68, %80
store i32 %81, i32* %4
%82 = load i32, i32* %3
%83 = add nsw i32 %82, 1
store i32 %83, i32* %3
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %85
85: ; preds = %67, %59
%86 = load i32, i32* %3
%87 = add nsw i32 %86, 1
store i32 %87, i32* %3
br label %8
88: ; preds = %8
%89 = load i32, i32* %4
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %89)
store i32 0, i32* %1
br label %91
91: ; preds = %88, %43, %22, %17
%92 = load i32, i32* %1
ret i32 %92
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"Invalid number\00"
@.str.3 = [24 x i8] c"The number is above 256\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [20 x i8] c"Enter roman number:\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %62, label %7
7: ; preds = %0, %54
%8 = phi i8* [ %59, %54 ], [ %2, %0 ]
%9 = phi i32 [ %58, %54 ], [ 0, %0 ]
%10 = phi i32 [ %56, %54 ], [ 0, %0 ]
%11 = icmp slt i32 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %65
14: ; preds = %7
%15 = icmp ugt i32 %9, 256
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %65
18: ; preds = %14
%19 = call i32 @strlen(i8* %2)
%20 = sub nsw i32 %19, %10
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8, i8* %8
%24 = call i32 @n(i8 signext %23)
%25 = add nsw i32 %10, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @n(i8 signext %28)
%30 = icmp slt i32 %24, %29
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %65
33: ; preds = %22, %18
%34 = load i8, i8* %8
%35 = call i32 @n(i8 signext %34)
%36 = add nsw i32 %10, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @n(i8 signext %39)
%41 = icmp slt i32 %35, %40
br i1 %41, label %45, label %42
42: ; preds = %33
%43 = load i8, i8* %8
%44 = call i32 @n(i8 signext %43)
br label %54
45: ; preds = %33
%46 = load i8, i8* %38
%47 = call i32 @n(i8 signext %46)
%48 = load i8, i8* %8
%49 = call i32 @n(i8 signext %48)
%50 = sub nsw i32 %47, %49
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%52 = add nsw i32 %10, 2
%53 = sext i32 %52 to i64
br label %54
54: ; preds = %45, %42
%55 = phi i64 [ %53, %45 ], [ %37, %42 ]
%56 = phi i32 [ %52, %45 ], [ %36, %42 ]
%57 = phi i32 [ %50, %45 ], [ %44, %42 ]
%58 = add nsw i32 %57, %9
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %55
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 0
br i1 %61, label %62, label %7
62: ; preds = %54, %0
%63 = phi i32 [ 0, %0 ], [ %58, %54 ]
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %31, %16, %12
ret i32 0
}