#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*/ uint8_t;
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ semantic_analyze(int /*<<< orphan*/ *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ syntax_check(int /*<<< orphan*/ *);
int process_file(char *filename) {
  struct stat st;
  stat(filename, &st);
  if (!st.st_size)
    return 1;
  uint8_t *file_buf = (uint8_t *)malloc(st.st_size);
  if (!file_buf)
    return 1;
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    free(file_buf);
    return 1;
  }
  size_t len = fread(file_buf, sizeof(char), st.st_size, fp);
  if (!len) {
    printf("%s couldn't be read.\n", filename);
    free(file_buf);
    return 1;
  }
  syntax_check(file_buf);
  semantic_analyze(file_buf);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11af <process_file+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1261 <process_file+0xe1>
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <process_file+0x52>
movl   $0x1,-0x4(%rbp)
jmp    1261 <process_file+0xe1>
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1206 <process_file+0x86>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1261 <process_file+0xe1>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124f <process_file+0xcf>
mov    -0x10(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1261 <process_file+0xe1>
mov    -0x20(%rbp),%rdi
call   1090 <syntax_check@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <semantic_analyze@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
mov    0x8(%rsp),%ebp
test   %ebp,%ebp
je     1200 <process_file+0x80>
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1200 <process_file+0x80>
mov    %rax,%r14
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f8 <process_file+0x78>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     11e9 <process_file+0x69>
mov    %r14,%rdi
call   1090 <syntax_check@plt>
mov    %r14,%rdi
call   10a0 <semantic_analyze@plt>
jmp    1200 <process_file+0x80>
lea    0xe12(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"%s couldn't be read.\0A\00"
define i32 @process_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @stat(i8* %8, %struct.stat* %4)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %1
store i32 1, i32* %2
br label %48
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %14
store i32 1, i32* %2
br label %48
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i32*, i32** %5
%29 = call i32 @free(i32* %28)
store i32 1, i32* %2
br label %48
30: ; preds = %22
%31 = load i32*, i32** %5
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32*, i32** %6
%35 = call i64 @fread(i32* %31, i32 1, i32 %33, i32* %34)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = icmp ne i64 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %30
%39 = load i8*, i8** %3
%40 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %5
%42 = call i32 @free(i32* %41)
store i32 1, i32* %2
br label %48
43: ; preds = %30
%44 = load i32*, i32** %5
%45 = call i32 @syntax_check(i32* %44)
%46 = load i32*, i32** %5
%47 = call i32 @semantic_analyze(i32* %46)
br label %48
48: ; preds = %43, %38, %27, %21, %13
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"%s couldn't be read.\0A\00"
define i32 @process_file(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %1
%9 = tail call i64 @malloc(i32 %6)
%10 = inttoptr i64 %9 to i32*
%11 = icmp eq i64 %9, 0
br i1 %11, label %26, label %12
12: ; preds = %8
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @free(i32* %10)
br label %26
17: ; preds = %12
%18 = tail call i64 @fread(i32* %10, i32 1, i32 %6, i32* %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%22 = tail call i32 @free(i32* %10)
br label %26
23: ; preds = %17
%24 = tail call i32 @syntax_check(i32* %10)
%25 = tail call i32 @semantic_analyze(i32* %10)
br label %26
26: ; preds = %8, %20, %23, %15, %1
ret i32 1
}