#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 */

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
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;
  fd = open(filename, O_WRONLY | O_CREAT | O_APPEND,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  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    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2eb8(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
or     (%rax),%esi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    0x2e85(%rip),%rax
or     (%rax),%edx
mov    0x2e6c(%rip),%rax
or     (%rax),%edx
mov    0x2e5b(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118c <start_trace_file+0x6c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <start_trace_file+0x86>
mov    -0x14(%rbp),%edi
lea    0xe6a(%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    0x2e88(%rip),%rax
mov    0x2ec9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6e(%rip),%rax
or     (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7b(%rip),%rax
or     (%rax),%edx
mov    0x2e6a(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     117e <start_trace_file+0x5e>
lea    0xe8e(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = 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
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @O_APPEND
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %5, i32 %10, i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %27
23: ; preds = %1
%24 = load i32, i32* %4
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %21
%28 = load i32, i32* %2
ret i32 %28
}

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