#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
unsigned int read_rome_char(char);
int /*<<< orphan*/ scanf(char *, char **);
int strlen(char *);
int main() {
  char *value_in = 0, *value_in_ptr;
  scanf("%ms", &value_in);
  value_in_ptr = value_in + strlen(value_in);
  unsigned long value = 0;
  unsigned last_digit = 0;
  do {
    --value_in_ptr;
    unsigned digit = read_rome_char(*value_in_ptr);
    if (digit < last_digit) {
      value -= digit;
    } else {
      value += digit;
    }
    last_digit = digit;
  } while (value_in_ptr != value_in);
  printf("%lu\n", value);
  free(value_in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1060 <read_rome_char@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11e3 <main+0x93>
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11ee <main+0x9e>
mov    -0x28(%rbp),%eax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11a7 <main+0x57>
mov    -0x20(%rbp),%rsi
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe98(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
xor    %r14d,%r14d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1060 <read_rome_char@plt>
mov    %eax,%ecx
mov    %rcx,%rdx
neg    %rdx
cmp    %ebp,%eax
cmovae %rcx,%rdx
add    %rdx,%r14
mov    %eax,%ebp
cmp    0x8(%rsp),%rbx
jne    1190 <main+0x40>
lea    0xe46(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ms\00"
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2)
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8* %12, i8** %3
store i64 0, i64* %4
store i32 0, i32* %5
br label %13
13: ; preds = %34, %0
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = call i32 @read_rome_char(i8 signext %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = load i64, i64* %4
%26 = sub i64 %25, %24
store i64 %26, i64* %4
br label %32
27: ; preds = %13
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = load i64, i64* %4
%31 = add i64 %30, %29
store i64 %31, i64* %4
br label %32
32: ; preds = %27, %22
%33 = load i32, i32* %6
store i32 %33, i32* %5
br label %34
34: ; preds = %32
%35 = load i8*, i8** %3
%36 = load i8*, i8** %2
%37 = icmp ne i8* %35, %36
br i1 %37, label %13, label %38
38: ; preds = %34
%39 = load i64, i64* %4
%40 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %39)
%41 = load i8*, i8** %2
%42 = call i32 @free(i8* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ms\00"
@.str.1 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %1)
%4 = load i8*, i8** %1
%5 = call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ 0, %0 ], [ %19, %8 ]
%10 = phi i32 [ 0, %0 ], [ %14, %8 ]
%11 = phi i8* [ %7, %0 ], [ %12, %8 ]
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = call i32 @read_rome_char(i8 signext %13)
%15 = icmp ult i32 %14, %10
%16 = zext i32 %14 to i64
%17 = sub nsw i64 0, %16
%18 = select i1 %15, i64 %17, i64 %16
%19 = add i64 %18, %9
%20 = load i8*, i8** %1
%21 = icmp eq i8* %12, %20
br i1 %21, label %22, label %8
22: ; preds = %8
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%24 = load i8*, i8** %1
%25 = call i32 @free(i8* %24)
ret i32 0
}