#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*/ panic(char *);
int /*<<< orphan*/ puts(char *);
int write(int, char *, int);
void enable_logging(void) {
  int fd;
  puts("\x1b[32m\x1b[1m"
       "[+] Enabling logging..."
       "\x1b[0m");
  fd = open("/proc/sys/kernel/printk", O_WRONLY);
  if (fd < 0)
    panic("open(printk)");
  if (write(fd, "9\n", 2) != 2)
    panic("write(printk)");
  close(fd);
}


x86 assembly (clang, -O0):
<enable_logging>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1192 <enable_logging+0x42>
lea    0xeb0(%rip),%rdi
call   1050 <panic@plt>
mov    -0x4(%rbp),%edi
lea    0xeae(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11bb <enable_logging+0x6b>
lea    0xe97(%rip),%rdi
call   1050 <panic@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_logging>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1184 <enable_logging+0x34>
lea    0xebe(%rip),%rdi
call   1050 <panic@plt>
lea    0xebf(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11a8 <enable_logging+0x58>
lea    0xeaa(%rip),%rdi
call   1050 <panic@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1060 <close@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"\1B[32m\1B[1m[+] Enabling logging...\1B[0m\00"
@.str.1 = [24 x i8] c"/proc/sys/kernel/printk\00"
@O_WRONLY = global i32 0
@.str.2 = [13 x i8] c"open(printk)\00"
@.str.3 = [3 x i8] c"9\0A\00"
@.str.4 = [14 x i8] c"write(printk)\00"
define void @enable_logging() {
%1 = alloca i32
%2 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %3)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @panic(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* %1
%11 = call i32 @write(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* %1
%17 = call i32 @close(i32 %16)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"\1B[32m\1B[1m[+] Enabling logging...\1B[0m\00"
@.str.1 = [24 x i8] c"/proc/sys/kernel/printk\00"
@O_WRONLY = global i32 0
@.str.2 = [13 x i8] c"open(printk)\00"
@.str.3 = [3 x i8] c"9\0A\00"
@.str.4 = [14 x i8] c"write(printk)\00"
define void @enable_logging() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @panic(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%9 = icmp eq i32 %8, 2
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @close(i32 %3)
ret void
}