#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 */
unsigned int encode_instruction_data(char *, char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_line(char const *, unsigned int *, char *, char *);
int /*<<< orphan*/ stderr;
int load(const char *filename, unsigned int *table, int size) {
  char *unused __attribute__((unused));
  FILE *fp;
  fp = fopen(filename, "r");
  if (!fp) {
    fprintf(stderr, "Can not open the file\n");
    return -1;
  }
  char line[200];
  unsigned int address;
  char instruction_name[8], instruction_args[64];
  int result;
  while (!feof(fp)) {
    unused = fgets(line, 200, fp);
    result = parse_line((const char *)line, &address, instruction_name,
                        instruction_args);
    if (result == 0) {
      table[address >> 1] =
          encode_instruction_data(instruction_name, instruction_args);
    } else {
    }
  }
  if (fclose(fp) != 0) {
    fprintf(stderr, "Can not close the file\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c6 <load+0x56>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <load+0x137>
jmp    11cb <load+0x5b>
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e9 <load+0x79>
jmp    126c <load+0xfc>
lea    -0x100(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
lea    -0x100(%rbp),%rdi
lea    -0x10c(%rbp),%rdx
lea    -0x150(%rbp),%rcx
lea    -0x104(%rbp),%rsi
call   1080 <parse_line@plt>
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jne    1262 <load+0xf2>
lea    -0x10c(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1040 <encode_instruction_data@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x104(%rbp),%ecx
shr    $0x1,%ecx
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
jmp    1267 <load+0xf7>
jmp    1267 <load+0xf7>
jmp    11cb <load+0x5b>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     12a0 <load+0x130>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <load+0x137>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11c7 <load+0x57>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11e3 <load+0x73>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     1249 <load+0xd9>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
jmp    11d7 <load+0x67>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    124b <load+0xdb>
lea    0x50(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbp
jmp    120c <load+0x9c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11a4 <load+0x34>
mov    %r15,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1080 <parse_line@plt>
test   %eax,%eax
jne    1200 <load+0x90>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <encode_instruction_data@plt>
mov    0x4(%rsp),%ecx
and    $0xfffffffe,%ecx
mov    %eax,(%r14,%rcx,2)
jmp    1200 <load+0x90>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can not open the file\0A\00"
@.str.2 = [24 x i8] c"Can not close the file\0A\00"
define i32 @load(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca [200 x i8]
%11 = alloca i32
%12 = alloca [8 x i8]
%13 = alloca [64 x i8]
%14 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %57
22: ; preds = %3
br label %23
23: ; preds = %48, %22
%24 = load i32*, i32** %9
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %49
28: ; preds = %23
%29 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%30 = load i32*, i32** %9
%31 = call i8* @fgets(i8* %29, i32 200, i32* %30)
store i8* %31, i8** %8
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%35 = call i32 @parse_line(i8* %32, i32* %11, i8* %33, i8* %34)
store i32 %35, i32* %14
%36 = load i32, i32* %14
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %28
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%41 = call i32 @encode_instruction_data(i8* %39, i8* %40)
%42 = load i32*, i32** %6
%43 = load i32, i32* %11
%44 = lshr i32 %43, 1
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
store i32 %41, i32* %46
br label %48
47: ; preds = %28
br label %48
48: ; preds = %47, %38
br label %23
49: ; preds = %23
%50 = load i32*, i32** %9
%51 = call i64 @fclose(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %57
56: ; preds = %49
store i32 0, i32* %4
br label %57
57: ; preds = %56, %53, %19
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can not open the file\0A\00"
@.str.2 = [24 x i8] c"Can not close the file\0A\00"
define i32 @load(i8* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca [200 x i8]
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca [64 x i8]
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %41
13: ; preds = %3
%14 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%15 = bitcast i32* %5 to i8*
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%18 = call i32 @feof(i32* %8)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %13, %30
%21 = call i8* @fgets(i8* %14, i32 200, i32* %8)
%22 = call i32 @parse_line(i8* %14, i32* %5, i8* %16, i8* %17)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = call i32 @encode_instruction_data(i8* %16, i8* %17)
%26 = load i32, i32* %5
%27 = lshr i32 %26, 1
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %1, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %20, %24
%31 = call i32 @feof(i32* %8)
%32 = icmp eq i32 %31, 0
br i1 %32, label %20, label %33
33: ; preds = %30, %13
%34 = call i64 @fclose(i32* %8)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %33, %36
%40 = phi i32 [ -1, %36 ], [ 0, %33 ]
br label %41
41: ; preds = %39, %10
%42 = phi i32 [ %40, %39 ], [ -1, %10 ]
ret i32 %42
}