#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int ftell(int /*<<< orphan*/ *);
scalar_t__ minroman(int);
int /*<<< orphan*/ printf(char *, int);
int strtoroman(char *);
int main(void) {
  FILE *fd = fopen("../res/089.data", "r");
  int sum = 0;
  int lines = 1;
  char str[100];
  while (fscanf(fd, "%100s", str) != EOF) {
    ++lines;
    int v = strtoroman(str);
    sum -= minroman(v);
  }
  sum += (ftell(fd) - lines);
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%rax
je     11f0 <main+0x90>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
call   1060 <strtoroman@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%edi
call   1030 <minroman@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x37>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
sub    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x2e4b(%rip),%r13
cmp    0x0(%r13),%rax
jne    11ac <main+0x4c>
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
jmp    11e8 <main+0x88>
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
mov    %rsp,%r12
lea    0xe55(%rip),%r15
nopl   (%rax)
mov    %r12,%rdi
call   1060 <strtoroman@plt>
mov    %eax,%edi
call   1030 <minroman@plt>
sub    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    $0xffffffff,%ebp
cmp    0x0(%r13),%rax
jne    11c0 <main+0x60>
add    %ebx,%ebp
mov    %r14,%rdi
call   1070 <ftell@plt>
add    %eax,%ebp
lea    0xe1d(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"../res/089.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%100s\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %8
8: ; preds = %14, %0
%9 = load i32*, i32** %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i64, i64* @EOF
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%18 = call i32 @strtoroman(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i64 @minroman(i32 %19)
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = sub nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %3
br label %8
25: ; preds = %8
%26 = load i32*, i32** %2
%27 = call i32 @ftell(i32* %26)
%28 = load i32, i32* %4
%29 = sub nsw i32 %27, %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, %29
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"../res/089.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%100s\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %20, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %14, %7 ], [ 0, %0 ]
%9 = phi i32 [ %10, %7 ], [ 1, %0 ]
%10 = add nuw nsw i32 %9, 1
%11 = call i32 @strtoroman(i8* %3)
%12 = call i64 @minroman(i32 %11)
%13 = trunc i64 %12 to i32
%14 = sub i32 %8, %13
%15 = call i64 @fscanf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %7
18: ; preds = %7
%19 = xor i32 %9, -1
br label %20
20: ; preds = %18, %0
%21 = phi i32 [ -1, %0 ], [ %19, %18 ]
%22 = phi i32 [ 0, %0 ], [ %14, %18 ]
%23 = call i32 @ftell(i32* %2)
%24 = add i32 %22, %21
%25 = add i32 %24, %23
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
ret i32 0
}