#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 *);
int save_books_to_fp(struct book_node *, int /*<<< orphan*/ *);
int export_books(struct book_node *head, char *filename) {
  FILE *fp = fopen(filename, "w");
  if ((fp) == NULL) {
    return -1;
  };
  int status = save_books_to_fp(head, fp);
  fclose(fp);
  return status;
}


x86 assembly (clang, -O0):
<export_books>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <export_books+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <export_books+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <save_books_to_fp@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_books>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xebf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     116a <export_books+0x3a>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <save_books_to_fp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    116f <export_books+0x3f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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