#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*/ LINUX_REBOOT_CMD_CAD_OFF;
int /*<<< orphan*/ LINUX_REBOOT_CMD_CAD_ON;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int reboot(int /*<<< orphan*/);
int have_reboot_patch(void) {
  FILE *f = fopen("/proc/sys/kernel/ctrl-alt-del", "r");
  int ret;
  int v;
  if (!f)
    return 0;
  ret = fscanf(f, "%d", &v);
  fclose(f);
  if (ret != 1)
    return 0;
  ret = reboot(v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF);
  if (ret != -1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<have_reboot_patch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <have_reboot_patch+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11fb <have_reboot_patch+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x14(%rbp)
je     11ac <have_reboot_patch+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11fb <have_reboot_patch+0xbb>
cmpl   $0x0,-0x18(%rbp)
je     11c7 <have_reboot_patch+0x87>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <have_reboot_patch+0x93>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11f4 <have_reboot_patch+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    11fb <have_reboot_patch+0xbb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<have_reboot_patch>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b1 <have_reboot_patch+0x71>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%r14d
jne    11b1 <have_reboot_patch+0x71>
cmpl   $0x0,0xc(%rsp)
jne    119a <have_reboot_patch+0x5a>
mov    0x2e58(%rip),%rax
jmp    11a1 <have_reboot_patch+0x61>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/proc/sys/kernel/ctrl-alt-del\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@LINUX_REBOOT_CMD_CAD_ON = global i32 0
@LINUX_REBOOT_CMD_CAD_OFF = global i32 0
define i32 @have_reboot_patch() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 0, i32* %1
br label %31
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
store i32 %11, i32* %3
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 0, i32* %1
br label %31
17: ; preds = %9
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32, i32* @LINUX_REBOOT_CMD_CAD_ON
br label %24
22: ; preds = %17
%23 = load i32, i32* @LINUX_REBOOT_CMD_CAD_OFF
br label %24
24: ; preds = %22, %20
%25 = phi i32 [ %21, %20 ], [ %23, %22 ]
%26 = call i32 @reboot(i32 %25)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %1
br label %31
30: ; preds = %24
store i32 1, i32* %1
br label %31
31: ; preds = %30, %29, %16, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [30 x i8] c"/proc/sys/kernel/ctrl-alt-del\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@LINUX_REBOOT_CMD_CAD_ON = global i32 0
@LINUX_REBOOT_CMD_CAD_OFF = global i32 0
define i32 @have_reboot_patch() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = icmp eq i32* %2, null
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 @fclose(i32* %2)
%8 = icmp eq i32 %6, 1
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
%12 = load i32, i32* @LINUX_REBOOT_CMD_CAD_ON
%13 = load i32, i32* @LINUX_REBOOT_CMD_CAD_OFF
%14 = select i1 %11, i32 %13, i32 %12
%15 = call i32 @reboot(i32 %14)
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %9, %5, %0
%19 = phi i32 [ 0, %0 ], [ 0, %5 ], [ %17, %9 ]
ret i32 %19
}