#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 mode_t;

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int start_trace_file(char *filename) {
  int fd;
  mode_t mode = S_IRUSR | S_IWUSR;
  fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, mode);
  if (fd < 0)
    return fd;
  write(fd, "\x7fTRACE0\n", 8);
  return fd;
}


x86 assembly (clang, -O0):
<start_trace_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    0x2ea4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    0x2ea3(%rip),%rax
or     (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    -0x18(%rbp),%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1180 <start_trace_file+0x60>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <start_trace_file+0x7a>
mov    -0x14(%rbp),%edi
lea    0xe76(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_trace_file>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
mov    0x2eb7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     116c <start_trace_file+0x4c>
lea    0xea0(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str = [9 x i8] c"\7FTRACE0\0A\00"
define i32 @start_trace_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_APPEND
%14 = or i32 %12, %13
%15 = load i32, i32* %5
%16 = call i32 @open(i8* %9, i32 %14, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %25
21: ; preds = %1
%22 = load i32, i32* %4
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %21, %19
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str = [9 x i8] c"\7FTRACE0\0A\00"
define i32 @start_trace_file(i8* nocapture %0) {
%2 = load i32, i32* @S_IRUSR
%3 = load i32, i32* @S_IWUSR
%4 = or i32 %3, %2
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_APPEND
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* %0, i32 %9, i32 %4)
%11 = icmp slt i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
br label %14
14: ; preds = %1, %12
ret i32 %10
}