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

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int write_headers(int, struct wav_file_headers *);
int fp_write_headers(FILE *fp, struct wav_file_headers *h) {
  int fd = fileno(fp);
  if (fd == -1) {
    fprintf(stderr, "fp_write_headers: Could not get file descriptor\n");
    return 0;
  }
  return write_headers(fd, h);
}


x86 assembly (clang, -O0):
<fp_write_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fileno@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1177 <fp_write_headers+0x47>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1186 <fp_write_headers+0x56>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <write_headers@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_write_headers>:
push   %rbx
mov    %rsi,%rbx
call   1050 <fileno@plt>
cmp    $0xffffffff,%eax
je     1149 <fp_write_headers+0x19>
mov    %eax,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <write_headers@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.wav_file_headers = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"fp_write_headers: Could not get file descriptor\0A\00"
define i32 @fp_write_headers(i32* %0, %struct.wav_file_headers* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.wav_file_headers*
%6 = alloca i32
store i32* %0, i32** %4
store %struct.wav_file_headers* %1, %struct.wav_file_headers** %5
%7 = load i32*, i32** %4
%8 = call i32 @fileno(i32* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %18
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load %struct.wav_file_headers*, %struct.wav_file_headers** %5
%17 = call i32 @write_headers(i32 %15, %struct.wav_file_headers* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %14, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.wav_file_headers = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"fp_write_headers: Could not get file descriptor\0A\00"
define i32 @fp_write_headers(i32* nocapture %0, %struct.wav_file_headers* %1) {
%3 = tail call i32 @fileno(i32* %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @write_headers(i32 %3, %struct.wav_file_headers* %1)
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ 0, %5 ], [ %9, %8 ]
ret i32 %11
}