#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int check_bpf_jit() {
  const char *bpf_jit_enable = "/proc/sys/net/core/bpf_jit_enable";
  int mode;
  FILE *f = fopen(bpf_jit_enable, "r");
  if (!f || (fscanf(f, "%d", &mode) < 1))
    do {
      printf("[-] "
             "could not read %s"
             "\n",
             bpf_jit_enable);
      exit(57);
    } while (0);
  fclose(f);
  if (mode <= 0)
    do {
      printf("[-] "
             "BPF JIT is disabled"
             "\n");
      exit(57);
    } while (0);
  if (mode == 1) {
    printf("[+] "
           "BPF JIT debug is disabled: will guess payload address"
           "\n");
    return 0;
  } else {
    printf("[+] "
           "BPF JIT debug is enabled: will have exact payload address"
           "\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<check_bpf_jit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119f <check_bpf_jit+0x4f>
mov    -0x20(%rbp),%rdi
lea    0xe97(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jge    11c0 <check_bpf_jit+0x70>
jmp    11a4 <check_bpf_jit+0x54>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x39,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x14(%rbp)
jg     11f0 <check_bpf_jit+0xa0>
jmp    11d8 <check_bpf_jit+0x88>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x39,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x14(%rbp)
jne    1214 <check_bpf_jit+0xc4>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <check_bpf_jit+0xd9>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bpf_jit>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11cf <check_bpf_jit+0x6f>
mov    %rax,%rbx
lea    0xe9d(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
test   %eax,%eax
jle    11cf <check_bpf_jit+0x6f>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11ee <check_bpf_jit+0x8e>
xor    %ebx,%ebx
cmp    $0x1,%eax
setne  %bl
lea    0xec5(%rip),%rax
lea    0xe80(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe51(%rip),%rdi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x39,%edi
call   1080 <exit@plt>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x39,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"/proc/sys/net/core/bpf_jit_enable\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"[-] could not read %s\0A\00"
@.str.4 = [25 x i8] c"[-] BPF JIT is disabled\0A\00"
@.str.5 = [59 x i8] c"[+] BPF JIT debug is disabled: will guess payload address\0A\00"
@.str.6 = [63 x i8] c"[+] BPF JIT debug is enabled: will have exact payload address\0A\00"
define i32 @check_bpf_jit() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32*, i32** %4
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %9, %0
br label %14
14: ; preds = %13
%15 = load i8*, i8** %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 57)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %9
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %3
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
br label %25
25: ; preds = %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @exit(i32 57)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %19
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %36
34: ; preds = %29
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %36
36: ; preds = %34, %32
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [34 x i8] c"/proc/sys/net/core/bpf_jit_enable\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"[-] could not read %s\0A\00"
@str = [62 x i8] c"[+] BPF JIT debug is enabled: will have exact payload address\00"
@str.7 = [58 x i8] c"[+] BPF JIT debug is disabled: will guess payload address\00"
@str.8 = [24 x i8] c"[-] BPF JIT is disabled\00"
define i32 @check_bpf_jit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %0, %5
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 57)
unreachable
11: ; preds = %5
%12 = call i32 @fclose(i32* %3)
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%17 = call i32 @exit(i32 57)
unreachable
18: ; preds = %11
%19 = icmp eq i32 %13, 1
%20 = select i1 %19, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0)
%21 = xor i1 %19, true
%22 = zext i1 %21 to i32
%23 = call i32 @puts(i8* dereferenceable(1) %20)
ret i32 %22
}