#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 main() {
  char r[10];
  int i = 0;
  int number = 0;
  scanf("%s", r);
  while (r[i]) {
    if (number < 0) {
      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++;
  }
  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    -0xe(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <scanf@plt>
movslq -0x14(%rbp),%rax
cmpb   $0x0,-0xe(%rbp,%rax,1)
je     1232 <main+0x102>
cmpl   $0x0,-0x18(%rbp)
jge    1190 <main+0x60>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <main+0x11a>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1050 <getromanv@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1050 <getromanv@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     11e3 <main+0xb3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1050 <getromanv@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1224 <main+0xf4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0xe(%rbp,%rax,1),%edi
call   1050 <getromanv@plt>
mov    %eax,-0x28(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edi
call   1050 <getromanv@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%edx
mov    -0x24(%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    115d <main+0x2d>
mov    -0x18(%rbp),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%rdi
lea    0x6(%rsp),%r14
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0x6(%rsp),%al
xor    %ebx,%ebx
test   %al,%al
je     11da <main+0x9a>
xor    %r15d,%r15d
jmp    11a4 <main+0x64>
nop
movsbl 0x6(%rsp,%rbp,1),%edi
call   1060 <getromanv@plt>
mov    %eax,%r12d
movsbl (%r14),%edi
call   1060 <getromanv@plt>
sub    %eax,%r12d
add    $0x2,%r15d
movslq %r15d,%rbp
add    %r12d,%ebx
lea    (%rsp,%rbp,1),%r14
add    $0x6,%r14
movzbl 0x6(%rsp,%rbp,1),%eax
test   %al,%al
je     11da <main+0x9a>
test   %ebx,%ebx
js     11ec <main+0xac>
movsbl %al,%edi
call   1060 <getromanv@plt>
mov    %eax,%r12d
movslq %r15d,%rbp
movsbl 0x7(%rsp,%rbp,1),%edi
add    $0x1,%rbp
call   1060 <getromanv@plt>
cmp    %eax,%r12d
jl     1170 <main+0x30>
movsbl (%r14),%edi
call   1060 <getromanv@plt>
mov    %eax,%r12d
mov    %ebp,%r15d
jmp    1190 <main+0x50>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f8 <main+0xb8>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%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\0A\00"
@.str.2 = [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 = getelementptr inbounds [10 x i8], [10 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)
br label %7
7: ; preds = %56, %0
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %59
13: ; preds = %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = 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 %62
18: ; preds = %13
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @getromanv(i8 signext %22)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @getromanv(i8 signext %28)
%30 = icmp sge i32 %23, %29
br i1 %30, label %31, label %39
31: ; preds = %18
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @getromanv(i8 signext %36)
%38 = add nsw i32 %32, %37
store i32 %38, i32* %4
br label %56
39: ; preds = %18
%40 = load i32, i32* %4
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
%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 = 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 @getromanv(i8 signext %50)
%52 = sub nsw i32 %46, %51
%53 = add nsw i32 %40, %52
store i32 %53, i32* %4
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %56
56: ; preds = %39, %31
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %7
59: ; preds = %7
%60 = load i32, i32* %4
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %60)
store i32 0, i32* %1
br label %62
62: ; preds = %59, %16
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [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 = 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 = icmp eq i8 %4, 0
br i1 %5, label %41, label %6
6: ; preds = %0, %33
%7 = phi i8 [ %39, %33 ], [ %4, %0 ]
%8 = phi i8* [ %38, %33 ], [ %2, %0 ]
%9 = phi i32 [ %37, %33 ], [ 0, %0 ]
%10 = phi i32 [ %35, %33 ], [ 0, %0 ]
%11 = icmp slt i32 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %44
14: ; preds = %6
%15 = call i32 @getromanv(i8 signext %7)
%16 = add nsw i32 %10, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @getromanv(i8 signext %19)
%21 = icmp slt i32 %15, %20
br i1 %21, label %25, label %22
22: ; preds = %14
%23 = load i8, i8* %8
%24 = call i32 @getromanv(i8 signext %23)
br label %33
25: ; preds = %14
%26 = load i8, i8* %18
%27 = call i32 @getromanv(i8 signext %26)
%28 = load i8, i8* %8
%29 = call i32 @getromanv(i8 signext %28)
%30 = sub nsw i32 %27, %29
%31 = add nsw i32 %10, 2
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %25, %22
%34 = phi i64 [ %32, %25 ], [ %17, %22 ]
%35 = phi i32 [ %31, %25 ], [ %16, %22 ]
%36 = phi i32 [ %30, %25 ], [ %24, %22 ]
%37 = add nsw i32 %36, %9
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %34
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 0
br i1 %40, label %41, label %6
41: ; preds = %33, %0
%42 = phi i32 [ 0, %0 ], [ %37, %33 ]
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %12
ret i32 0
}