#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 /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ is_valid_input(int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ puts(char *);
int load_asm_file(char *filename, int mem_arr[]) {
  FILE *input_file;
  if (!(input_file = fopen(filename, "r"))) {
    puts("ERROR: no input file specified");
    exit(EXIT_FAILURE);
  }
  int in_comment, save;
  char c = 'a';
  char instruction_str[5];
  int instruction;
  int line_number = 1;
  int i = 0;
  int j = 0;
  while (c != EOF) {
    if (j >= 4) {
      j = 0;
      instruction_str[4] = '\0';
      instruction = atoi(instruction_str);
      if (is_valid_input(instruction)) {
        mem_arr[i] = instruction;
        i++;
      } else {
        printf("error in file \'%s\' on line %d\n", filename, line_number);
      }
    }
    save = 1;
    c = fgetc(input_file);
    if (c == '\n') {
      line_number++;
      in_comment = 0;
      save = 0;
      line_number++;
      j = 0;
    }
    if ((c == '#') || (c == ';')) {
      in_comment = 1;
      j = 0;
    }
    if ((!in_comment) && (save)) {
      instruction_str[j] = c;
      j++;
    }
  }
  fclose(input_file);
  return i;
}


x86 assembly (clang, -O0):
<load_asm_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c8 <load_asm_file+0x48>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movb   $0x61,-0x21(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movsbl -0x21(%rbp),%eax
mov    0x2dfc(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12fa <load_asm_file+0x17a>
cmpl   $0x4,-0x38(%rbp)
jl     125e <load_asm_file+0xde>
movl   $0x0,-0x38(%rbp)
movb   $0x0,-0x22(%rbp)
lea    -0x26(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1090 <is_valid_input@plt>
cmp    $0x0,%rax
je     1246 <load_asm_file+0xc6>
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1259 <load_asm_file+0xd9>
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%edx
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
jmp    125e <load_asm_file+0xde>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    12a5 <load_asm_file+0x125>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x23,%eax
je     12bf <load_asm_file+0x13f>
movsbl -0x21(%rbp),%eax
cmp    $0x3b,%eax
jne    12cd <load_asm_file+0x14d>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12f5 <load_asm_file+0x175>
cmpl   $0x0,-0x20(%rbp)
je     12f5 <load_asm_file+0x175>
mov    -0x21(%rbp),%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x26(%rbp,%rax,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e1 <load_asm_file+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_asm_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x20(%rsp)
lea    0xe66(%rip),%rsi
mov    %rdi,0x18(%rsp)
call   1070 <fopen@plt>
test   %rax,%rax
je     12bb <load_asm_file+0x13b>
mov    %rax,%r13
mov    0x2e31(%rip),%r15
xor    %eax,%eax
mov    %rax,0x8(%rsp)
cmpb   $0x61,(%r15)
jne    11e0 <load_asm_file+0x60>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
xor    %ebx,%ebx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%ecx
jmp    1205 <load_asm_file+0x85>
cs nopw 0x0(%rax,%rax,1)
cmp    (%r15),%al
je     11c4 <load_asm_file+0x44>
mov    %ecx,%ebp
cmp    $0x4,%ebx
jl     126c <load_asm_file+0xec>
mov    %r15,%r12
mov    %r13,%r15
movb   $0x0,0x17(%rsp)
lea    0x13(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1090 <is_valid_input@plt>
test   %rax,%rax
je     124b <load_asm_file+0xcb>
mov    0x8(%rsp),%rcx
movslq %ecx,%rcx
mov    0x20(%rsp),%rax
mov    %r13d,(%rax,%rcx,4)
add    $0x1,%ecx
mov    %rcx,0x8(%rsp)
jmp    125e <load_asm_file+0xde>
lea    0xdcf(%rip),%rdi
mov    0x18(%rsp),%rsi
mov    %ebp,%edx
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %r15,%r13
mov    %r12,%r15
mov    $0x1,%r12d
mov    %r13,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%al
mov    $0x0,%esi
cmove  %esi,%r14d
cmp    $0x23,%al
sete   %cl
cmp    $0x3b,%al
sete   %dl
or     %cl,%dl
cmovne %r12d,%r14d
lea    0x2(%rbp),%ecx
cmovne %esi,%ebx
cmp    $0xa,%al
cmovne %ebp,%ecx
cmove  %esi,%ebx
je     1200 <load_asm_file+0x80>
test   %r14d,%r14d
jne    1200 <load_asm_file+0x80>
movslq %ebx,%rbx
mov    %al,0x13(%rsp,%rbx,1)
add    $0x1,%ebx
jmp    1200 <load_asm_file+0x80>
lea    0xd40(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"ERROR: no input file specified\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [31 x i8] c"error in file '%s' on line %d\0A\00"
define i32 @load_asm_file(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca [5 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
store i8 97, i8* %8
store i32 1, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %22
22: ; preds = %84, %21
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %85
28: ; preds = %22
%29 = load i32, i32* %13
%30 = icmp sge i32 %29, 4
br i1 %30, label %31, label %51
31: ; preds = %28
store i32 0, i32* %13
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 4
store i8 0, i8* %32
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = call i64 @is_valid_input(i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = load i32, i32* %10
%40 = load i32*, i32** %4
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
store i32 %45, i32* %12
br label %50
46: ; preds = %31
%47 = load i8*, i8** %3
%48 = load i32, i32* %11
%49 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %47, i32 %48)
br label %50
50: ; preds = %46, %38
br label %51
51: ; preds = %50, %28
store i32 1, i32* %7
%52 = load i32*, i32** %5
%53 = call signext i8 @fgetc(i32* %52)
store i8 %53, i8* %8
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %62
57: ; preds = %51
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
store i32 0, i32* %6
store i32 0, i32* %7
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
store i32 0, i32* %13
br label %62
62: ; preds = %57, %51
%63 = load i8, i8* %8
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 35
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i8, i8* %8
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 59
br i1 %69, label %70, label %71
70: ; preds = %66, %62
store i32 1, i32* %6
store i32 0, i32* %13
br label %71
71: ; preds = %70, %66
%72 = load i32, i32* %6
%73 = icmp ne i32 %72, 0
br i1 %73, label %84, label %74
74: ; preds = %71
%75 = load i32, i32* %7
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %74
%78 = load i8, i8* %8
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 %80
store i8 %78, i8* %81
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 1
store i32 %83, i32* %13
br label %84
84: ; preds = %77, %74, %71
br label %22
85: ; preds = %22
%86 = load i32*, i32** %5
%87 = call i32 @fclose(i32* %86)
%88 = load i32, i32* %12
ret i32 %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"ERROR: no input file specified\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [31 x i8] c"error in file '%s' on line %d\0A\00"
define i32 @load_asm_file(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [5 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %12, 97
br i1 %13, label %56, label %14
14: ; preds = %10
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
br label %16
16: ; preds = %14, %52
%17 = phi i32 [ 0, %14 ], [ %53, %52 ]
%18 = phi i32 [ 0, %14 ], [ %33, %52 ]
%19 = phi i32 [ 1, %14 ], [ %39, %52 ]
%20 = phi i32 [ undef, %14 ], [ %43, %52 ]
%21 = icmp sgt i32 %17, 3
br i1 %21, label %22, label %32
22: ; preds = %16
store i8 0, i8* %15
%23 = call i32 @atoi(i8* %11)
%24 = tail call i64 @is_valid_input(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = sext i32 %18 to i64
%28 = getelementptr inbounds i32, i32* %1, i64 %27
store i32 %23, i32* %28
%29 = add nsw i32 %18, 1
br label %32
30: ; preds = %22
%31 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %19)
br label %32
32: ; preds = %26, %30, %16
%33 = phi i32 [ %29, %26 ], [ %18, %30 ], [ %18, %16 ]
%34 = phi i32 [ 0, %26 ], [ 0, %30 ], [ %17, %16 ]
%35 = tail call signext i8 @fgetc(i32* %4)
%36 = icmp eq i8 %35, 10
%37 = add nsw i32 %19, 2
%38 = select i1 %36, i32 0, i32 %20
%39 = select i1 %36, i32 %37, i32 %19
%40 = icmp eq i8 %35, 35
%41 = icmp eq i8 %35, 59
%42 = or i1 %40, %41
%43 = select i1 %42, i32 1, i32 %38
%44 = or i1 %36, %42
%45 = select i1 %44, i32 0, i32 %34
%46 = icmp ne i32 %43, 0
%47 = or i1 %36, %46
br i1 %47, label %52, label %48
48: ; preds = %32
%49 = sext i32 %45 to i64
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %49
store i8 %35, i8* %50
%51 = add nsw i32 %45, 1
br label %52
52: ; preds = %48, %32
%53 = phi i32 [ %51, %48 ], [ %45, %32 ]
%54 = load i8, i8* @EOF
%55 = icmp eq i8 %35, %54
br i1 %55, label %56, label %16
56: ; preds = %52, %10
%57 = phi i32 [ 0, %10 ], [ %33, %52 ]
%58 = tail call i32 @fclose(i32* %4)
ret i32 %57
}