#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;
scalar_t__ count_in_roman(int);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int to_arabic_numeral(char *);
int main() {
  FILE *file = fopen("dataset.txt\0", "r");
  if (file != NULL) {
    char *roman_numeral = (char *)malloc(64 * sizeof(char));
    int number, saved_characters = 0;
    while (fscanf(file, "%s", roman_numeral) != EOF) {
      number = to_arabic_numeral(roman_numeral);
      saved_characters += strlen(roman_numeral) - count_in_roman(number);
    }
    printf("%d characters saved\n\n", saved_characters);
  } else {
    printf("The file couldn't be found.\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1227 <main+0xb7>
mov    $0x40,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1060 <fscanf@plt>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
je     1211 <main+0xa1>
mov    -0x18(%rbp),%rdi
call   1070 <to_arabic_numeral@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <count_in_roman@plt>
mov    -0x28(%rbp),%rcx
sub    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
jmp    11b6 <main+0x46>
mov    -0x20(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1235 <main+0xc5>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe6e(%rip),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     122b <main+0xab>
mov    %rax,%r14
mov    $0x40,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1070 <fscanf@plt>
mov    0x2e18(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%rax
je     1219 <main+0x99>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
call   1080 <to_arabic_numeral@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r13d,%edi
call   1030 <count_in_roman@plt>
sub    %eax,%ebx
add    %ebx,%ebp
mov    %r14,%rdi
lea    0xe03(%rip),%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
cmp    (%r15),%rax
jne    11e0 <main+0x60>
lea    0xdf2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1237 <main+0xb7>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"dataset.txt\00\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.3 = [22 x i8] c"%d characters saved\0A\0A\00"
@.str.4 = [30 x i8] c"The file couldn't be found.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %33
9: ; preds = %0
%10 = call i64 @malloc(i32 64)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
store i32 0, i32* %5
br label %12
12: ; preds = %18, %9
%13 = load i32*, i32** %2
%14 = load i8*, i8** %3
%15 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i64, i64* @EOF
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = call i32 @to_arabic_numeral(i8* %19)
store i32 %20, i32* %4
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = load i32, i32* %4
%24 = call i64 @count_in_roman(i32 %23)
%25 = sub nsw i64 %22, %24
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %5
br label %12
30: ; preds = %12
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %35
33: ; preds = %0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"dataset.txt\00\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.3 = [22 x i8] c"%d characters saved\0A\0A\00"
@str = [29 x i8] c"The file couldn't be found.\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %23, label %3
3: ; preds = %0
%4 = tail call i64 @malloc(i32 64)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i64 @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %20, label %9
9: ; preds = %3, %9
%10 = phi i32 [ %16, %9 ], [ 0, %3 ]
%11 = tail call i32 @to_arabic_numeral(i8* %5)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%13 = tail call i64 @count_in_roman(i32 %11)
%14 = sub nsw i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = add i32 %10, %15
%17 = tail call i64 @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %9
20: ; preds = %9, %3
%21 = phi i32 [ 0, %3 ], [ %16, %9 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %0
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret i32 0
}