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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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 <Values@plt>
cmp    $0x0,%eax
je     11e2 <main+0xb2>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Values@plt>
cmp    $0x0,%eax
jge    11b6 <main+0x86>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <main+0xf1>
mov    -0x78(%rbp),%eax
mov    %eax,-0x7c(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1040 <Values@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    116e <main+0x3e>
cmpl   $0x100,-0x78(%rbp)
jle    1209 <main+0xd9>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <main+0xf1>
mov    -0x78(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
lea    0xec3(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
movsbl (%rsp),%edi
call   1040 <Values@plt>
test   %eax,%eax
je     11af <main+0x7f>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <Values@plt>
test   %eax,%eax
js     119f <main+0x6f>
movsbl (%rbx),%edi
call   1040 <Values@plt>
add    %eax,%ebp
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <Values@plt>
test   %eax,%eax
jne    1170 <main+0x40>
cmp    $0x101,%ebp
jl     11af <main+0x7f>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11bf <main+0x8f>
lea    0xe71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
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)
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @Values(i8 signext %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %8
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @Values(i8 signext %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = 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 %42
24: ; preds = %15
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @Values(i8 signext %29)
%31 = add nsw i32 %25, %30
store i32 %31, i32* %4
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %8
34: ; preds = %8
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 256
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = 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 %42
39: ; preds = %34
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %40)
store i32 0, i32* %1
br label %42
42: ; preds = %39, %37, %22
%43 = load i32, i32* %1
ret i32 %43
}

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 @Values(i8 signext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %0, %17
%9 = phi i64 [ %21, %17 ], [ 0, %0 ]
%10 = phi i8* [ %22, %17 ], [ %2, %0 ]
%11 = phi i32 [ %20, %17 ], [ 0, %0 ]
%12 = load i8, i8* %10
%13 = call i32 @Values(i8 signext %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %33
17: ; preds = %8
%18 = load i8, i8* %10
%19 = call i32 @Values(i8 signext %18)
%20 = add nsw i32 %19, %11
%21 = add nuw i64 %9, 1
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @Values(i8 signext %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %8
26: ; preds = %17
%27 = icmp sgt i32 %20, 256
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %33
30: ; preds = %0, %26
%31 = phi i32 [ %20, %26 ], [ 0, %0 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %28, %15
ret i32 0
}