#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ get_token(char *, char *);
int /*<<< orphan*/ insert_token_order(char *, char *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read_file(char *filename) {
  FILE *fp;
  char *line, *token;
  line = malloc(1024);
  token = malloc(1024);
  memset(line, 0, 1024);
  memset(token, 0, 1024);
  printf("Open Filename: %s\n", filename);
  if ((fp = fopen(filename, "rb")) == NULL) {
    printf("can't open file.\n");
    free(line);
    free(token);
    exit(1);
  }
  while (1) {
    get_line(line, fp);
    get_token(line, token);
    if (*token == '\0')
      break;
    insert_token_order(line, token, fp);
  }
  fclose(fp);
  free(line);
  free(token);
  return 0;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1242 <read_file+0xa2>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1247 <read_file+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <get_line@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <get_token@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1276 <read_file+0xd6>
jmp    128c <read_file+0xec>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <insert_token_order@plt>
jmp    1247 <read_file+0xa7>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
lea    0xe09(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     126c <read_file+0xbc>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <get_line@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10d0 <get_token@plt>
cmpb   $0x0,(%r14)
je     124c <read_file+0x9c>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <insert_token_order@plt>
jmp    1220 <read_file+0x70>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xda3(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Open Filename: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"can't open file.\0A\00"
define i32 @read_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 1024)
store i8* %6, i8** %4
%7 = call i8* @malloc(i32 1024)
store i8* %7, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @memset(i8* %8, i32 0, i32 1024)
%10 = load i8*, i8** %5
%11 = call i32 @memset(i8* %10, i32 0, i32 1024)
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %1
br label %25
25: ; preds = %24, %37
%26 = load i8*, i8** %4
%27 = load i32*, i32** %3
%28 = call i32 @get_line(i8* %26, i32* %27)
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 @get_token(i8* %29, i8* %30)
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %25
br label %42
37: ; preds = %25
%38 = load i8*, i8** %4
%39 = load i8*, i8** %5
%40 = load i32*, i32** %3
%41 = call i32 @insert_token_order(i8* %38, i8* %39, i32* %40)
br label %25
42: ; preds = %36
%43 = load i32*, i32** %3
%44 = call i32 @fclose(i32* %43)
%45 = load i8*, i8** %4
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %5
%48 = call i32 @free(i8* %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Open Filename: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@str = [17 x i8] c"can't open file.\00"
define i32 @read_file(i8* %0) {
%2 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i32 @memset(i8* %2, i32 0, i32 1024)
%5 = tail call i32 @memset(i8* %3, i32 0, i32 1024)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = tail call i32 @get_line(i8* %2, i32* %7)
%11 = tail call i32 @get_token(i8* %2, i8* %3)
%12 = load i8, i8* %3
%13 = icmp eq i8 %12, 0
br i1 %13, label %25, label %19
14: ; preds = %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @free(i8* %2)
%17 = tail call i32 @free(i8* %3)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9, %19
%20 = tail call i32 @insert_token_order(i8* %2, i8* %3, i32* %7)
%21 = tail call i32 @get_line(i8* %2, i32* %7)
%22 = tail call i32 @get_token(i8* %2, i8* %3)
%23 = load i8, i8* %3
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %19
25: ; preds = %19, %9
%26 = tail call i32 @fclose(i32* %7)
%27 = tail call i32 @free(i8* %2)
%28 = tail call i32 @free(i8* %3)
ret i32 0
}