#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) {
    if (write(fd, "9\n", 2) != 2)
      panic("write(printk)");
    close(fd);
  }
  fd = open("/proc/sys/debug/exception-trace", O_WRONLY);
  if (fd >= 0) {
    if (write(fd, "1\n", 2) != 2)
      panic("write(exception-trace)");
    close(fd);
  }
  fd = open("/proc/sys/kernel/panic_on_warn", O_WRONLY);
  if (fd >= 0) {
    if (write(fd, "1\n", 2) != 2)
      panic("write(panic_on_warn)");
    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)
jl     11b7 <enable_logging+0x67>
mov    -0x4(%rbp),%edi
lea    0xead(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11af <enable_logging+0x5f>
lea    0xe96(%rip),%rdi
call   1050 <panic@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     120a <enable_logging+0xba>
mov    -0x4(%rbp),%edi
lea    0xe8b(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     1202 <enable_logging+0xb2>
lea    0xe74(%rip),%rdi
call   1050 <panic@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     125d <enable_logging+0x10d>
mov    -0x4(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     1255 <enable_logging+0x105>
lea    0xe57(%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   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e71(%rip),%r14
mov    (%r14),%esi
lea    0xeb4(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11a7 <enable_logging+0x57>
mov    %eax,%ebx
lea    0xeba(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11a0 <enable_logging+0x50>
lea    0xea5(%rip),%rdi
call   1050 <panic@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    (%r14),%esi
lea    0xe9d(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11e7 <enable_logging+0x97>
mov    %eax,%ebx
lea    0xeab(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11e0 <enable_logging+0x90>
lea    0xe96(%rip),%rdi
call   1050 <panic@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    (%r14),%esi
lea    0xe97(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     122e <enable_logging+0xde>
mov    %eax,%ebx
lea    0xe6b(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     1220 <enable_logging+0xd0>
lea    0xe8c(%rip),%rdi
call   1050 <panic@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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 = [3 x i8] c"9\0A\00"
@.str.3 = [14 x i8] c"write(printk)\00"
@.str.4 = [32 x i8] c"/proc/sys/debug/exception-trace\00"
@.str.5 = [3 x i8] c"1\0A\00"
@.str.6 = [23 x i8] c"write(exception-trace)\00"
@.str.7 = [31 x i8] c"/proc/sys/kernel/panic_on_warn\00"
@.str.8 = [21 x i8] c"write(panic_on_warn)\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 sge i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i32 @write(i32 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = load i32, i32* %1
%15 = call i32 @close(i32 %14)
br label %16
16: ; preds = %13, %0
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %17)
store i32 %18, i32* %1
%19 = load i32, i32* %1
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32, i32* %1
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %16
%31 = load i32, i32* @O_WRONLY
%32 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %31)
store i32 %32, i32* %1
%33 = load i32, i32* %1
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = load i32, i32* %1
%37 = call i32 @write(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%38 = icmp ne i32 %37, 2
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = load i32, i32* %1
%43 = call i32 @close(i32 %42)
br label %44
44: ; preds = %41, %30
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 = [3 x i8] c"9\0A\00"
@.str.3 = [14 x i8] c"write(printk)\00"
@.str.4 = [32 x i8] c"/proc/sys/debug/exception-trace\00"
@.str.5 = [3 x i8] c"1\0A\00"
@.str.6 = [23 x i8] c"write(exception-trace)\00"
@.str.7 = [31 x i8] c"/proc/sys/kernel/panic_on_warn\00"
@.str.8 = [21 x i8] c"write(panic_on_warn)\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 sgt i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%7 = icmp eq i32 %6, 2
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @close(i32 %3)
br label %12
12: ; preds = %10, %0
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = tail call i32 @write(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%18 = icmp eq i32 %17, 2
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = tail call i32 @close(i32 %14)
br label %23
23: ; preds = %21, %12
%24 = load i32, i32* @O_WRONLY
%25 = tail call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %24)
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = tail call i32 @write(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%29 = icmp eq i32 %28, 2
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @close(i32 %25)
br label %34
34: ; preds = %32, %23
ret void
}