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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct book_node *load_books_from_fp(int /*<<< orphan*/ *);
struct book_node *import_books(char *filename) {
  struct book_node *head;
  FILE *fp = fopen(filename, "r");
  if (fp == NULL) {
    return NULL;
  }
  head = load_books_from_fp(fp);
  fclose(fp);
  return head;
}


x86 assembly (clang, -O0):
<import_books>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1168 <import_books+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1186 <import_books+0x56>
mov    -0x20(%rbp),%rdi
call   1040 <load_books_from_fp@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<import_books>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1160 <import_books+0x30>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <load_books_from_fp@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
jmp    1162 <import_books+0x32>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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