#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_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ write(int, char *, int);
void clear_leaks(void) {
  int fd;
  fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
  if (fd < 0)
    return;
  puts("\x1b[32m\x1b[1m"
       "[+] Starting memory leak detection..."
       "\x1b[0m");
  write(fd, "clear\n", 5);
  close(fd);
}


x86 assembly (clang, -O0):
<clear_leaks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    116f <clear_leaks+0x2f>
jmp    1197 <clear_leaks+0x57>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    -0x4(%rbp),%edi
lea    0xec9(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_leaks>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1183 <clear_leaks+0x43>
mov    %eax,%ebx
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xedf(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1050 <close@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"/sys/kernel/debug/kmemleak\00"
@O_WRONLY = global i32 0
@.str.1 = [51 x i8] c"\1B[32m\1B[1m[+] Starting memory leak detection...\1B[0m\00"
@.str.2 = [7 x i8] c"clear\0A\00"
define void @clear_leaks() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
br label %13
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 5)
%11 = load i32, i32* %1
%12 = call i32 @close(i32 %11)
br label %13
13: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"/sys/kernel/debug/kmemleak\00"
@O_WRONLY = global i32 0
@.str.1 = [51 x i8] c"\1B[32m\1B[1m[+] Starting memory leak detection...\1B[0m\00"
@.str.2 = [7 x i8] c"clear\0A\00"
define void @clear_leaks() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 5)
%7 = tail call i32 @close(i32 %2)
br label %8
8: ; preds = %0, %4
ret void
}