#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_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ write(int, char *, int);
void profil_write(int type, char *buffer, int len) {
  static int des = -1;
  if (des < 0) {
    des = open("gmon.out", O_WRONLY | O_CREAT | O_TRUNC, 0644);
  }
  if (len == 0) {
    close(des);
  } else {
    write(des, buffer, len);
  }
}


x86 assembly (clang, -O0):
<profil_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,0x2eef(%rip)
jge    1181 <profil_write+0x51>
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,0x2eb7(%rip)
cmpl   $0x0,-0x14(%rbp)
jne    119b <profil_write+0x6b>
mov    0x2ea7(%rip),%edi
call   1040 <close@plt>
jmp    11ad <profil_write+0x7d>
mov    0x2e97(%rip),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<profil_write>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    0x2ef9(%rip),%edi
test   %edi,%edi
js     1158 <profil_write+0x28>
test   %ebx,%ebx
je     1190 <profil_write+0x60>
mov    %r14,%rsi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <write@plt>
mov    0x2e69(%rip),%rax
mov    0x2e92(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
lea    0xe86(%rip),%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,%edi
mov    %eax,0x2eac(%rip)
test   %ebx,%ebx
jne    1147 <profil_write+0x17>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <close@plt>

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

LLVM IR (-O2):
@profil_write.des = internal unnamed_addr global i32 -1
@.str = [9 x i8] c"gmon.out\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @profil_write(i32 %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @profil_write.des
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 420)
store i32 %12, i32* @profil_write.des
br label %13
13: ; preds = %6, %3
%14 = phi i32 [ %12, %6 ], [ %4, %3 ]
%15 = icmp eq i32 %2, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @close(i32 %14)
br label %20
18: ; preds = %13
%19 = tail call i32 @write(i32 %14, i8* %1, i32 %2)
br label %20
20: ; preds = %18, %16
ret void
}