#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 */
char EOF;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
void load_code_from_file(int *code, char *filename) {
  FILE *fp;
  fp = fopen(filename, "r");
  char buff[255];
  char c;
  int count = 0, i = 0;
  printf("Reading from: %s\n", filename);
  while ((c = fgetc(fp)) != EOF) {
    if (c == '\n') {
      buff[count] = '\0';
      count = 0;
      code[i] = atoi(buff);
      i++;
    }
    buff[count] = c;
    count++;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<load_code_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x121(%rbp)
movsbl %al,%eax
mov    0x2e34(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     123b <load_code_from_file+0xeb>
movsbl -0x121(%rbp),%eax
cmp    $0xa,%eax
jne    1213 <load_code_from_file+0xc3>
movslq -0x128(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
movl   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x12c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
mov    -0x121(%rbp),%cl
movslq -0x128(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    119b <load_code_from_file+0x4b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_code_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe82(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    0x2e51(%rip),%r13
cmp    0x0(%r13),%al
jne    11b6 <load_code_from_file+0x66>
mov    %r12,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    %eax,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11db <load_code_from_file+0x8b>
nop
movslq %r15d,%r15
mov    %bl,(%rsp,%r15,1)
add    $0x1,%r15d
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%al
je     119d <load_code_from_file+0x4d>
cmp    $0xa,%bl
jne    11c0 <load_code_from_file+0x70>
movslq %r15d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1070 <atoi@plt>
movslq %ebp,%rbp
mov    %eax,(%r14,%rbp,4)
add    $0x1,%ebp
xor    %r15d,%r15d
jmp    11c0 <load_code_from_file+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"Reading from: %s\0A\00"
@EOF = global i8 0
define void @load_code_from_file(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [255 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
store i32 0, i32* %8
store i32 0, i32* %9
%12 = load i8*, i8** %4
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %37, %2
%15 = load i32*, i32** %5
%16 = call signext i8 @fgetc(i32* %15)
store i8 %16, i8* %7
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %44
21: ; preds = %14
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %27
store i8 0, i8* %28
store i32 0, i32* %8
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%30 = call i32 @atoi(i8* %29)
%31 = load i32*, i32** %3
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %37
37: ; preds = %25, %21
%38 = load i8, i8* %7
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %40
store i8 %38, i8* %41
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %14
44: ; preds = %14
%45 = load i32*, i32** %5
%46 = call i32 @fclose(i32* %45)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"Reading from: %s\0A\00"
@EOF = global i8 0
define void @load_code_from_file(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = tail call signext i8 @fgetc(i32* %4)
%8 = load i8, i8* @EOF
%9 = icmp eq i8 %7, %8
br i1 %9, label %31, label %10
10: ; preds = %2, %22
%11 = phi i8 [ %28, %22 ], [ %7, %2 ]
%12 = phi i32 [ %24, %22 ], [ 0, %2 ]
%13 = phi i32 [ %27, %22 ], [ 0, %2 ]
%14 = icmp eq i8 %11, 10
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @atoi(i8* %5)
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i32, i32* %0, i64 %19
store i32 %18, i32* %20
%21 = add nsw i32 %12, 1
br label %22
22: ; preds = %15, %10
%23 = phi i32 [ 0, %15 ], [ %13, %10 ]
%24 = phi i32 [ %21, %15 ], [ %12, %10 ]
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %25
store i8 %11, i8* %26
%27 = add nsw i32 %23, 1
%28 = tail call signext i8 @fgetc(i32* %4)
%29 = load i8, i8* @EOF
%30 = icmp eq i8 %28, %29
br i1 %30, label %31, label %10
31: ; preds = %22, %2
%32 = tail call i32 @fclose(i32* %4)
ret void
}