#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[1000];
  int i = 0;
  int number = 0;
  printf("Enter Roman number=");
  scanf("%s", r);
  while (r[i]) {
    if (n(r[i]) < 0) {
      printf("Invalid number %s.", &r[i]);
      return 0;
    }
    if (n(r[i]) > 256) {
      printf("Invalid number %s.", &r[i]);
    }
    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++;
    }
    i++;
  }
  printf("%d", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3f4(%rbp)
movl   $0x0,-0x3f8(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1060 <scanf@plt>
movslq -0x3f4(%rbp),%rax
cmpb   $0x0,-0x3f0(%rbp,%rax,1)
je     138e <main+0x24e>
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
cmp    $0x0,%eax
jge    11e4 <main+0xa4>
movslq -0x3f4(%rbp),%rax
lea    -0x3f0(%rbp),%rsi
add    %rax,%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a9 <main+0x269>
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
cmp    $0x100,%eax
jle    1222 <main+0xe2>
movslq -0x3f4(%rbp),%rax
lea    -0x3f0(%rbp),%rsi
add    %rax,%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x3f4(%rbp),%eax
cmp    $0x2,%eax
jle    129e <main+0x15e>
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,-0x3fc(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0x2,%eax
cltq
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x3fc(%rbp),%eax
cmp    %ecx,%eax
jge    1299 <main+0x159>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a9 <main+0x269>
jmp    129e <main+0x15e>
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,-0x400(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x400(%rbp),%eax
cmp    %ecx,%eax
jl     1315 <main+0x1d5>
mov    -0x3f8(%rbp),%eax
mov    %eax,-0x404(%rbp)
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,%ecx
mov    -0x404(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x3f8(%rbp)
jmp    137a <main+0x23a>
mov    -0x3f8(%rbp),%eax
mov    %eax,-0x408(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    %eax,-0x40c(%rbp)
movslq -0x3f4(%rbp),%rax
movsbl -0x3f0(%rbp,%rax,1),%edi
ff
call   1030 <n@plt>
mov    -0x40c(%rbp),%ecx
mov    %eax,%edx
mov    -0x408(%rbp),%eax
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x3f8(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    1187 <main+0x47>
mov    -0x3f8(%rbp),%esi
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
lea    0xea8(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeab(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%al
test   %al,%al
je     1250 <main+0x110>
mov    %r14,%rbx
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    11c1 <main+0x81>
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%r15,1),%edi
call   1030 <n@plt>
mov    %eax,%ebp
movsbl (%rbx),%edi
call   1030 <n@plt>
sub    %eax,%ebp
add    $0x2,%r13d
movslq %r13d,%r15
add    %ebp,%r12d
lea    (%rsp,%r15,1),%rbx
movzbl (%rsp,%r15,1),%eax
test   %al,%al
je     1250 <main+0x110>
movsbl %al,%edi
call   1030 <n@plt>
test   %eax,%eax
js     1263 <main+0x123>
movsbl (%rbx),%edi
call   1030 <n@plt>
cmp    $0x101,%eax
jl     11f1 <main+0xb1>
lea    0xe30(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %r13d,%eax
movslq %r13d,%r15
cmp    $0x3,%eax
jl     121d <main+0xdd>
movsbl (%rbx),%edi
call   1030 <n@plt>
mov    %eax,%ebp
movsbl 0x2(%r15,%r14,1),%edi
call   1030 <n@plt>
cmp    %eax,%ebp
jl     1276 <main+0x136>
movsbl (%rbx),%edi
call   1030 <n@plt>
mov    %eax,%ebp
movsbl 0x1(%rsp,%r15,1),%edi
add    $0x1,%r15
call   1030 <n@plt>
cmp    %eax,%ebp
jl     1190 <main+0x50>
movsbl (%rbx),%edi
call   1030 <n@plt>
mov    %eax,%ebp
mov    %r15d,%r13d
jmp    11ad <main+0x6d>
lea    0xde3(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1284 <main+0x144>
lea    0xdad(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1284 <main+0x144>
lea    0xdad(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter Roman number=\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"Invalid number %s.\00"
@.str.3 = [16 x i8] c"Invalid number.\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1000 x i8], [1000 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 = %98, %0
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %101
14: ; preds = %8
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @n(i8 signext %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 0, i32* %1
br label %104
26: ; preds = %14
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @n(i8 signext %30)
%32 = icmp sgt i32 %31, 256
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %33, %26
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = load i32, i32* %3
%42 = sub nsw i32 %40, %41
%43 = icmp sgt i32 %42, 2
br i1 %43, label %44, label %60
44: ; preds = %38
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = call i32 @n(i8 signext %48)
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @n(i8 signext %54)
%56 = icmp slt i32 %49, %55
br i1 %56, label %57, label %59
57: ; preds = %44
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %104
59: ; preds = %44
br label %60
60: ; preds = %59, %38
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = call i32 @n(i8 signext %64)
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = call i32 @n(i8 signext %70)
%72 = icmp sge i32 %65, %71
br i1 %72, label %73, label %81
73: ; preds = %60
%74 = load i32, i32* %4
%75 = load i32, i32* %3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = call i32 @n(i8 signext %78)
%80 = add nsw i32 %74, %79
store i32 %80, i32* %4
br label %98
81: ; preds = %60
%82 = load i32, i32* %4
%83 = load i32, i32* %3
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = call i32 @n(i8 signext %87)
%89 = load i32, i32* %3
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = call i32 @n(i8 signext %92)
%94 = sub nsw i32 %88, %93
%95 = add nsw i32 %82, %94
store i32 %95, i32* %4
%96 = load i32, i32* %3
%97 = add nsw i32 %96, 1
store i32 %97, i32* %3
br label %98
98: ; preds = %81, %73
%99 = load i32, i32* %3
%100 = add nsw i32 %99, 1
store i32 %100, i32* %3
br label %8
101: ; preds = %8
%102 = load i32, i32* %4
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %102)
store i32 0, i32* %1
br label %104
104: ; preds = %101, %57, %21
%105 = load i32, i32* %1
ret i32 %105
}

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