#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;
  printf("Enter Roman number:");
  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    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xeab(%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     119f <main+0x6f>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129a <main+0x16a>
jmp    11a4 <main+0x74>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Roman_Value@plt>
cmp    $0x0,%eax
je     125b <main+0x12b>
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    1229 <main+0xf9>
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    124d <main+0x11d>
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    11a4 <main+0x74>
cmpl   $0x100,-0x78(%rbp)
jle    1282 <main+0x152>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129a <main+0x16a>
mov    -0x78(%rbp),%esi
lea    0xd9b(%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
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
mov    %rsp,%r12
mov    %r12,%rsi
call   1050 <scanf@plt>
movsbl (%rsp),%edi
call   1040 <Roman_Value@plt>
test   %eax,%eax
jle    11fd <main+0xcd>
movsbl (%rsp),%edi
call   1040 <Roman_Value@plt>
test   %eax,%eax
je     120d <main+0xdd>
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11b3 <main+0x83>
nopl   0x0(%rax)
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     11f4 <main+0xc4>
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    1190 <main+0x60>
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    119f <main+0x6f>
cmp    $0x101,%r14d
jl     120d <main+0xdd>
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    121e <main+0xee>
lea    0xe13(%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 = [20 x i8] c"Enter Roman number:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"Invalid number.\00"
@.str.3 = [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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 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)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = call i32 @Roman_Value(i8 signext %11)
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = 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 %73
16: ; preds = %0
br label %17
17: ; preds = %62, %16
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @Roman_Value(i8 signext %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %65
24: ; preds = %17
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @Roman_Value(i8 signext %28)
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @Roman_Value(i8 signext %34)
%36 = icmp slt i32 %29, %35
br i1 %36, label %37, label %54
37: ; preds = %24
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @Roman_Value(i8 signext %42)
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @Roman_Value(i8 signext %47)
%49 = sub nsw i32 %43, %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, %49
store i32 %51, i32* %4
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %62
54: ; preds = %24
%55 = load i32, i32* %4
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = call i32 @Roman_Value(i8 signext %59)
%61 = add nsw i32 %55, %60
store i32 %61, i32* %4
br label %62
62: ; preds = %54, %37
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %17
65: ; preds = %17
%66 = load i32, i32* %4
%67 = icmp sgt i32 %66, 256
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = 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 %73
70: ; preds = %65
%71 = load i32, i32* %4
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %71)
store i32 0, i32* %1
br label %73
73: ; preds = %70, %68, %14
%74 = load i32, i32* %1
ret i32 %74
}

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