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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
struct ts_node *ts_load_file(int /*<<< orphan*/ *);
struct ts_node *ts_load(const char *fname) {
  FILE *fp;
  struct ts_node *root;
  if (!(fp = fopen(fname, "rb"))) {
    fprintf(stderr, "ts_load: failed to open file: %s: %s\n", fname,
            strerror(errno));
    return 0;
  }
  root = ts_load_file(fp);
  fclose(fp);
  return root;
}


x86 assembly (clang, -O0):
<ts_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bf <ts_load+0x6f>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11dd <ts_load+0x8d>
mov    -0x18(%rbp),%rdi
call   1050 <ts_load_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_load>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1183 <ts_load+0x33>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <ts_load_file@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
jmp    11b0 <ts_load+0x60>
mov    0x2e56(%rip),%rax
mov    (%rax),%ebx
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe62(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.ts_node = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"ts_load: failed to open file: %s: %s\0A\00"
@errno = global i32 0
define %struct.ts_node* @ts_load(i8* %0) {
%2 = alloca %struct.ts_node*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.ts_node*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %13)
store %struct.ts_node* null, %struct.ts_node** %2
br label %21
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = call %struct.ts_node* @ts_load_file(i32* %16)
store %struct.ts_node* %17, %struct.ts_node** %5
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = load %struct.ts_node*, %struct.ts_node** %5
store %struct.ts_node* %20, %struct.ts_node** %2
br label %21
21: ; preds = %15, %9
%22 = load %struct.ts_node*, %struct.ts_node** %2
ret %struct.ts_node* %22
}

LLVM IR (-O2):
%struct.ts_node = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"ts_load: failed to open file: %s: %s\0A\00"
@errno = global i32 0
define %struct.ts_node* @ts_load(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %7)
br label %12
9: ; preds = %1
%10 = tail call %struct.ts_node* @ts_load_file(i32* %2)
%11 = tail call i32 @fclose(i32* %2)
br label %12
12: ; preds = %9, %4
%13 = phi %struct.ts_node* [ %10, %9 ], [ null, %4 ]
ret %struct.ts_node* %13
}