#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 getromanv(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\n");
      return 0;
    }
    if ((strlen(r) - i) > 2) {
      if (getromanv(r[i]) < getromanv(r[i + 2])) {
        printf("Invalid number\n");
        return 0;
      }
    }
    if (getromanv(r[i]) >= getromanv(r[i + 1])) {
      number = number + getromanv(r[i]);
    } else {
      number = number + (getromanv(r[i + 1]) - getromanv(r[i]));
      i++;
    }
    i++;
  }
  if (number > 256) {
    printf("The number is above 256\n");
    return 0;
  }
  printf("%d\n", 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   1040 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xe9f(%rip),%rdi
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
cmpb   $0x0,-0xe(%rbp,%rax,1)
je     12b4 <main+0x174>
cmpl   $0x0,-0x18(%rbp)
jge    11ae <main+0x6e>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f3 <main+0x1b3>
lea    -0xe(%rbp),%rdi
call   1030 <strlen@plt>
sub    -0x14(%rbp),%eax
cmp    $0x2,%eax
jle    1212 <main+0xd2>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    120d <main+0xcd>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f3 <main+0x1b3>
jmp    1212 <main+0xd2>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jl     1265 <main+0x125>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    12a6 <main+0x166>
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1060 <getromanv@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)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <main+0x3b>
cmpl   $0x100,-0x18(%rbp)
jle    12db <main+0x19b>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f3 <main+0x1b3>
mov    -0x18(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <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    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rdi
lea    0xe(%rsp),%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
cmpb   $0x0,0xe(%rsp)
je     1237 <main+0xe7>
xor    %r12d,%r12d
mov    %r14,%r13
xor    %r15d,%r15d
jmp    11d1 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0xe(%rsp,%rbx,1),%edi
call   1070 <getromanv@plt>
mov    %eax,%ebp
movsbl 0x0(%r13),%edi
call   1070 <getromanv@plt>
sub    %eax,%ebp
add    $0x2,%r15d
movslq %r15d,%rbx
add    %ebp,%r12d
lea    (%rsp,%rbx,1),%r13
add    $0xe,%r13
cmpb   $0x0,0xe(%rsp,%rbx,1)
je     1245 <main+0xf5>
test   %r12d,%r12d
js     123c <main+0xec>
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %r15d,%eax
movslq %r15d,%rbx
cmp    $0x3,%eax
jl     1204 <main+0xb4>
movsbl 0x0(%r13),%edi
call   1070 <getromanv@plt>
mov    %eax,%ebp
movsbl 0x2(%rbx,%r14,1),%edi
call   1070 <getromanv@plt>
cmp    %eax,%ebp
jl     123c <main+0xec>
movsbl 0x0(%r13),%edi
call   1070 <getromanv@plt>
mov    %eax,%ebp
movsbl 0xf(%rsp,%rbx,1),%edi
add    $0x1,%rbx
call   1070 <getromanv@plt>
cmp    %eax,%ebp
jl     11a0 <main+0x50>
movsbl 0x0(%r13),%edi
call   1070 <getromanv@plt>
mov    %eax,%ebp
mov    %ebx,%r15d
jmp    11bf <main+0x6f>
xor    %r12d,%r12d
jmp    125c <main+0x10c>
lea    0xdf0(%rip),%rdi
jmp    1255 <main+0x105>
cmp    $0x101,%r12d
jl     125c <main+0x10c>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
jmp    126d <main+0x11d>
lea    0xda0(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <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 = [16 x i8] c"Invalid number\0A\00"
@.str.3 = [25 x i8] c"The number is above 256\0A\00"
@.str.4 = [4 x i8] c"%d\0A\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 = %79, %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 %82
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 ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %90
19: ; preds = %14
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = load i32, i32* %3
%23 = sub nsw i32 %21, %22
%24 = icmp sgt i32 %23, 2
br i1 %24, label %25, label %41
25: ; preds = %19
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @getromanv(i8 signext %29)
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @getromanv(i8 signext %35)
%37 = icmp slt i32 %30, %36
br i1 %37, label %38, label %40
38: ; preds = %25
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %90
40: ; preds = %25
br label %41
41: ; preds = %40, %19
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @getromanv(i8 signext %45)
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = call i32 @getromanv(i8 signext %51)
%53 = icmp sge i32 %46, %52
br i1 %53, label %54, label %62
54: ; preds = %41
%55 = load i32, i32* %4
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = call i32 @getromanv(i8 signext %59)
%61 = add nsw i32 %55, %60
store i32 %61, i32* %4
br label %79
62: ; preds = %41
%63 = load i32, i32* %4
%64 = load i32, i32* %3
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = call i32 @getromanv(i8 signext %68)
%70 = load i32, i32* %3
%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 @getromanv(i8 signext %73)
%75 = sub nsw i32 %69, %74
%76 = add nsw i32 %63, %75
store i32 %76, i32* %4
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
br label %79
79: ; preds = %62, %54
%80 = load i32, i32* %3
%81 = add nsw i32 %80, 1
store i32 %81, i32* %3
br label %8
82: ; preds = %8
%83 = load i32, i32* %4
%84 = icmp sgt i32 %83, 256
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %90
87: ; preds = %82
%88 = load i32, i32* %4
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %88)
store i32 0, i32* %1
br label %90
90: ; preds = %87, %85, %38, %17
%91 = load i32, i32* %1
ret i32 %91
}

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