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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ writeDataHeader(int /*<<< orphan*/ *);
int /*<<< orphan*/ writeDataRecords(int /*<<< orphan*/ *);
int /*<<< orphan*/ writeKeys(int /*<<< orphan*/ *);
void writeTrace(const char *traceFileName) {
  FILE *fp = fopen(traceFileName, "w");
  if (fp == NULL) {
    perror(traceFileName);
    exit(1);
  }
  writeKeys(fp);
  writeDataHeader(fp);
  writeDataRecords(fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<writeTrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <writeTrace+0x3e>
mov    -0x8(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <writeKeys@plt>
mov    -0x10(%rbp),%rdi
call   1080 <writeDataHeader@plt>
mov    -0x10(%rbp),%rdi
call   1050 <writeDataRecords@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeTrace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <writeTrace+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <writeKeys@plt>
mov    %rbx,%rdi
call   1080 <writeDataHeader@plt>
mov    %rbx,%rdi
call   1050 <writeDataRecords@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    %r14,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define void @writeTrace(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 %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* %0)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i32 @writeKeys(i32* %2)
%9 = tail call i32 @writeDataHeader(i32* %2)
%10 = tail call i32 @writeDataRecords(i32* %2)
%11 = tail call i32 @fclose(i32* %2)
ret void
}