#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 */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *stderr;
scalar_t__ upOrDown(int);
int main(int argc, char *argv[]) {
  int floor = 0;
  int instruction;
  FILE *inputFile;
  inputFile = fopen(argv[1], "r");
  if (inputFile == NULL) {
    printf(stderr, "File not valid for reading you christmas toad.\n");
    exit(-1);
  }
  while ((instruction = fgetc(inputFile)) != EOF) {
    floor += upOrDown(instruction);
  }
  fclose(inputFile);
  printf("\nThe final floor for delivery is:  %i\n", floor);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <main+0x62>
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11c7 <main+0x67>
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%eax
je     11fc <main+0x9c>
mov    -0x18(%rbp),%edi
call   1050 <upOrDown@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11c7 <main+0x67>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d5 <main+0x75>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e5d(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     11b6 <main+0x56>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edi
call   1050 <upOrDown@plt>
add    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe6d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%rdi
lea    0xe1c(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i8* null
@.str.1 = [48 x i8] c"File not valid for reading you christmas toad.\0A\00"
@EOF = global i32 0
@.str.2 = [39 x i8] c"\0AThe final floor for delivery is: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** @stderr
%17 = call i32 (i8*, ...) @printf(i8* %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
br label %20
20: ; preds = %25, %19
%21 = load i32*, i32** %8
%22 = call i32 @fgetc(i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32, i32* %7
%27 = call i64 @upOrDown(i32 %26)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %6
br label %20
32: ; preds = %20
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i8* null
@.str.1 = [48 x i8] c"File not valid for reading you christmas toad.\0A\00"
@EOF = global i32 0
@.str.2 = [39 x i8] c"\0AThe final floor for delivery is: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @fgetc(i32* %5)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %24, label %15
11: ; preds = %2
%12 = load i8*, i8** @stderr
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %7, %15
%16 = phi i32 [ %21, %15 ], [ %8, %7 ]
%17 = phi i32 [ %20, %15 ], [ 0, %7 ]
%18 = tail call i64 @upOrDown(i32 %16)
%19 = trunc i64 %18 to i32
%20 = add i32 %17, %19
%21 = tail call i32 @fgetc(i32* %5)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %15
24: ; preds = %15, %7
%25 = phi i32 [ 0, %7 ], [ %20, %15 ]
%26 = tail call i32 @fclose(i32* %5)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %25)
ret i32 0
}