#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 Roman_Value(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char string[100];
  int counter = 0, number = 0;
  scanf("%s", string);
  if (Roman_Value(string[counter]) <= 0) {
    printf("Invalid number.");
    return 0;
  }
  while (Roman_Value(string[counter]) != 0) {
    if (Roman_Value(string[counter]) < Roman_Value(string[counter + 1])) {
      number += Roman_Value(string[counter + 1]) - Roman_Value(string[counter]);
      counter++;
    } else
      number = number + Roman_Value(string[counter]);
    counter++;
  }
  if (number > 256) {
    printf("Invalid number.");
    return 0;
  }
  printf("%d", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1050 <scanf@plt>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
cmp    $0x0,%eax
jg     1191 <main+0x61>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128c <main+0x15c>
jmp    1196 <main+0x66>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
cmp    $0x0,%eax
je     124d <main+0x11d>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
jge    121b <main+0xeb>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,-0x80(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
sub    %ecx,%eax
add    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    123f <main+0x10f>
mov    -0x78(%rbp),%eax
mov    %eax,-0x84(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1196 <main+0x66>
cmpl   $0x100,-0x78(%rbp)
jle    1274 <main+0x144>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128c <main+0x15c>
mov    -0x78(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xebd(%rip),%rdi
mov    %rsp,%r12
mov    %r12,%rsi
call   1050 <scanf@plt>
movsbl (%rsp),%edi
call   1040 <Roman_Value@plt>
test   %eax,%eax
jle    11ed <main+0xbd>
movsbl (%rsp),%edi
call   1040 <Roman_Value@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11fd <main+0xcd>
xor    %r15d,%r15d
jmp    11a3 <main+0x73>
nopl   0x0(%rax,%rax,1)
movsbl (%r12),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ebp
mov    %ebx,%r15d
add    %ebp,%r14d
lea    (%rsp,%rbx,1),%r12
movsbl (%rsp,%rbx,1),%edi
call   1040 <Roman_Value@plt>
test   %eax,%eax
je     11e4 <main+0xb4>
movsbl (%r12),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ebp
movslq %r15d,%rbx
movsbl 0x1(%rsp,%rbx,1),%edi
add    $0x1,%rbx
call   1040 <Roman_Value@plt>
cmp    %eax,%ebp
jge    1180 <main+0x50>
movsbl (%rsp,%rbx,1),%edi
call   1040 <Roman_Value@plt>
mov    %eax,%ebp
movsbl (%r12),%edi
call   1040 <Roman_Value@plt>
sub    %eax,%ebp
add    $0x2,%r15d
movslq %r15d,%rbx
jmp    118f <main+0x5f>
cmp    $0x101,%r14d
jl     11fd <main+0xcd>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    120e <main+0xde>
lea    0xe0f(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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