#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
void clearProfileBuf(void) {
  int fdProfile;
  char readBuf[10];
  if ((fdProfile = open("/proc/profile", O_RDWR)) <= 0) {
    fprintf(stderr, "Could not open file /proc/profile. Make sure you booted "
                    "with profile=2\n");
    return;
  }
  if (write(fdProfile, readBuf, 1) != 1) {
    perror("Could Not clear profile by writing to /proc/profile:");
  }
  close(fdProfile);
}


x86 assembly (clang, -O0):
<clearProfileBuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jg     1193 <clearProfileBuf+0x43>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11c1 <clearProfileBuf+0x71>
mov    -0x4(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11b9 <clearProfileBuf+0x69>
lea    0xea2(%rip),%rdi
call   1070 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clearProfileBuf>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jle    1192 <clearProfileBuf+0x42>
mov    %eax,%ebx
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11ac <clearProfileBuf+0x5c>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <close@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <fprintf@plt>
lea    0xea3(%rip),%rdi
call   1070 <perror@plt>
jmp    1186 <clearProfileBuf+0x36>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/profile\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [72 x i8] c"Could not open file /proc/profile. Make sure you booted with profile=2\0A\00"
@.str.2 = [53 x i8] c"Could Not clear profile by writing to /proc/profile:\00"
define void @clearProfileBuf() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = icmp sle i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %19
9: ; preds = %0
%10 = load i32, i32* %1
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i32 @write(i32 %10, i8* %11, i32 1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %16, %6
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/profile\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [72 x i8] c"Could not open file /proc/profile. Make sure you booted with profile=2\0A\00"
@.str.2 = [53 x i8] c"Could Not clear profile by writing to /proc/profile:\00"
define void @clearProfileBuf() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %16
9: ; preds = %0
%10 = call i32 @write(i32 %4, i8* %2, i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @close(i32 %4)
br label %16
16: ; preds = %14, %6
ret void
}