#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 */
struct tree_node {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
struct tree_node *parse_node(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char const *);
struct tree_node *get_tree_from_file(const char *filename) {
  FILE *file;
  assert(1024 >= 16);
  struct tree_node *root;
  file = fopen(filename, "r");
  if (file == NULL) {
    perror(filename);
    exit(1);
  }
  root = parse_node(file, NULL);
  fclose(file);
  return root;
}


x86 assembly (clang, -O0):
<get_tree_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <get_tree_from_file+0x48>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <parse_node@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tree_from_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a8 <get_tree_from_file+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <parse_node@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.tree_node* @get_tree_from_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.tree_node*
store i8* %0, i8** %2
%5 = call i32 @assert(i32 1)
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = call %struct.tree_node* @parse_node(i32* %15, i32* null)
store %struct.tree_node* %16, %struct.tree_node** %4
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
%19 = load %struct.tree_node*, %struct.tree_node** %4
ret %struct.tree_node* %19
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@.str = [2 x i8] c"r\00"
define %struct.tree_node* @get_tree_from_file(i8* nocapture %0) {
%2 = tail call i32 @assert(i32 1)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call %struct.tree_node* @parse_node(i32* %3, i32* null)
%10 = tail call i32 @fclose(i32* %3)
ret %struct.tree_node* %9
}