#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 ssize_t;

/* Variables and functions */
char *arabic_to_roman(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ roman_to_arabic(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
int x_getline(char **, int /*<<< orphan*/);
int main(void) {
  char *line = NULL;
  ssize_t len = 0;
  int savings = 0;
  while ((len = x_getline(&line, stdin)) != -1) {
    char *minimal_representation = arabic_to_roman(roman_to_arabic(line));
    if (minimal_representation)
      savings += len - (int)strlen(minimal_representation);
    free(minimal_representation);
    free(line);
  }
  printf("%d\n", savings);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1040 <x_getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11f6 <main+0x96>
mov    -0x10(%rbp),%rdi
call   1050 <roman_to_arabic@plt>
mov    %eax,%edi
call   1080 <arabic_to_roman@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11df <main+0x7f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1185 <main+0x25>
mov    -0x18(%rbp),%esi
lea    0xe00(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e6c(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdi
call   1040 <x_getline@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0x90>
mov    %eax,%ebp
xor    %r15d,%r15d
lea    0x8(%rsp),%r14
jmp    11c5 <main+0x65>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1040 <x_getline@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11f3 <main+0x93>
mov    0x8(%rsp),%rdi
call   1050 <roman_to_arabic@plt>
mov    %eax,%edi
call   1080 <arabic_to_roman@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a0 <main+0x40>
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r15d,%ebp
sub    %eax,%ebp
mov    %ebp,%r15d
jmp    11a0 <main+0x40>
xor    %r15d,%r15d
lea    0xe06(%rip),%rdi
mov    %r15d,%esi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* @stdin
%8 = call i32 @x_getline(i8** %2, i32 %7)
store i32 %8, i32* %3
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = call i32 @roman_to_arabic(i8* %11)
%13 = call i8* @arabic_to_roman(i32 %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = load i32, i32* %3
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
%20 = trunc i64 %19 to i32
%21 = sub nsw i32 %17, %20
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %21
store i32 %23, i32* %4
br label %24
24: ; preds = %16, %10
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
br label %6
29: ; preds = %6
%30 = load i32, i32* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = load i32, i32* @stdin
%4 = call i32 @x_getline(i8** %1, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %26, label %6
6: ; preds = %0, %18
%7 = phi i32 [ %24, %18 ], [ %4, %0 ]
%8 = phi i32 [ %19, %18 ], [ 0, %0 ]
%9 = load i8*, i8** %1
%10 = call i32 @roman_to_arabic(i8* %9)
%11 = call i8* @arabic_to_roman(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = call i64 @strlen(i8* %11)
%15 = trunc i64 %14 to i32
%16 = add i32 %7, %8
%17 = sub i32 %16, %15
br label %18
18: ; preds = %13, %6
%19 = phi i32 [ %17, %13 ], [ %8, %6 ]
%20 = call i32 @free(i8* %11)
%21 = load i8*, i8** %1
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* @stdin
%24 = call i32 @x_getline(i8** %1, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %6
26: ; preds = %18, %0
%27 = phi i32 [ 0, %0 ], [ %19, %18 ]
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}