#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*/ LINUX_REBOOT_CMD_CAD_ON;
int /*<<< orphan*/ LINUX_REBOOT_CMD_HALT;
int /*<<< orphan*/ LINUX_REBOOT_CMD_POWER_OFF;
int /*<<< orphan*/ LINUX_REBOOT_CMD_RESTART;
int /*<<< orphan*/ LINUX_REBOOT_CMD_RESTART2;
int SIGHUP;
int SIGINT;
scalar_t__ getuid();
int have_reboot_patch();
int /*<<< orphan*/ printf(char *);
int test_reboot(int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int status;
  if (getuid() != 0) {
    printf("Must run as root.\n");
    return 1;
  }
  status = have_reboot_patch();
  if (status != 0) {
    printf("Your kernel does not have the container reboot patch\n");
    return 1;
  }
  status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1);
  if (status >= 0) {
    printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n");
    return 1;
  }
  printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n");
  status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP);
  if (status < 0)
    return 1;
  printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n");
  status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP);
  if (status < 0)
    return 1;
  printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n");
  status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT);
  if (status < 0)
    return 1;
  printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n");
  status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT);
  if (status < 0)
    return 1;
  printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n");
  printf("All tests passed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     117f <main+0x3f>
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
mov    $0x0,%al
call   1060 <have_reboot_patch@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ab <main+0x6b>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1030 <test_reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11e3 <main+0xa3>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1030 <test_reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    121f <main+0xdf>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
lea    0xe8f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
call   1030 <test_reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    125b <main+0x11b>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
lea    0xe7d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1030 <test_reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1297 <main+0x157>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
call   1030 <test_reboot@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d3 <main+0x193>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <main+0x1b2>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getuid@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     115e <main+0x1e>
lea    0xff9(%rip),%rdi
jmp    1190 <main+0x50>
xor    %eax,%eax
call   1060 <have_reboot_patch@plt>
test   %eax,%eax
je     1172 <main+0x32>
lea    0xfb0(%rip),%rdi
jmp    1190 <main+0x50>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1030 <test_reboot@plt>
test   %eax,%eax
js     119f <main+0x5f>
lea    0xf5d(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e35(%rip),%r14
mov    (%r14),%esi
call   1030 <test_reboot@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     1195 <main+0x55>
lea    0xe64(%rip),%rdi
call   1040 <puts@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1030 <test_reboot@plt>
test   %eax,%eax
js     1195 <main+0x55>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%r14
mov    (%r14),%esi
call   1030 <test_reboot@plt>
test   %eax,%eax
js     1195 <main+0x55>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1030 <test_reboot@plt>
test   %eax,%eax
js     1195 <main+0x55>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
lea    0xe8d(%rip),%rdi
jmp    1190 <main+0x50>

LLVM IR (-O0):
@.str = [19 x i8] c"Must run as root.\0A\00"
@.str.1 = [54 x i8] c"Your kernel does not have the container reboot patch\0A\00"
@LINUX_REBOOT_CMD_CAD_ON = global i32 0
@.str.2 = [52 x i8] c"reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\0A\00"
@.str.3 = [56 x i8] c"reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\0A\00"
@LINUX_REBOOT_CMD_RESTART = global i32 0
@SIGHUP = global i32 0
@.str.4 = [42 x i8] c"reboot(LINUX_REBOOT_CMD_RESTART) succeed\0A\00"
@LINUX_REBOOT_CMD_RESTART2 = global i32 0
@.str.5 = [43 x i8] c"reboot(LINUX_REBOOT_CMD_RESTART2) succeed\0A\00"
@LINUX_REBOOT_CMD_HALT = global i32 0
@SIGINT = global i32 0
@.str.6 = [39 x i8] c"reboot(LINUX_REBOOT_CMD_HALT) succeed\0A\00"
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
@.str.7 = [45 x i8] c"reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\0A\00"
@.str.8 = [18 x i8] c"All tests passed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @getuid()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %59
11: ; preds = %2
%12 = call i32 (...) @have_reboot_patch()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %59
17: ; preds = %11
%18 = load i32, i32* @LINUX_REBOOT_CMD_CAD_ON
%19 = call i32 @test_reboot(i32 %18, i32 -1)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %59
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%27 = load i32, i32* @SIGHUP
%28 = call i32 @test_reboot(i32 %26, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 1, i32* %3
br label %59
32: ; preds = %24
%33 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @LINUX_REBOOT_CMD_RESTART2
%35 = load i32, i32* @SIGHUP
%36 = call i32 @test_reboot(i32 %34, i32 %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 1, i32* %3
br label %59
40: ; preds = %32
%41 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* @LINUX_REBOOT_CMD_HALT
%43 = load i32, i32* @SIGINT
%44 = call i32 @test_reboot(i32 %42, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 1, i32* %3
br label %59
48: ; preds = %40
%49 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%50 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
%51 = load i32, i32* @SIGINT
%52 = call i32 @test_reboot(i32 %50, i32 %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %48
store i32 1, i32* %3
br label %59
56: ; preds = %48
%57 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %59
59: ; preds = %56, %55, %47, %39, %31, %22, %15, %9
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@LINUX_REBOOT_CMD_CAD_ON = global i32 0
@LINUX_REBOOT_CMD_RESTART = global i32 0
@SIGHUP = global i32 0
@LINUX_REBOOT_CMD_RESTART2 = global i32 0
@LINUX_REBOOT_CMD_HALT = global i32 0
@SIGINT = global i32 0
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
@str = [55 x i8] c"reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\00"
@str.9 = [41 x i8] c"reboot(LINUX_REBOOT_CMD_RESTART) succeed\00"
@str.10 = [42 x i8] c"reboot(LINUX_REBOOT_CMD_RESTART2) succeed\00"
@str.11 = [38 x i8] c"reboot(LINUX_REBOOT_CMD_HALT) succeed\00"
@str.12 = [44 x i8] c"reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\00"
@str.13 = [17 x i8] c"All tests passed\00"
@str.14 = [51 x i8] c"reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\00"
@str.15 = [53 x i8] c"Your kernel does not have the container reboot patch\00"
@str.16 = [18 x i8] c"Must run as root.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %38
5: ; preds = %2
%6 = tail call i32 (...) @have_reboot_patch()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %38
8: ; preds = %5
%9 = load i32, i32* @LINUX_REBOOT_CMD_CAD_ON
%10 = tail call i32 @test_reboot(i32 %9, i32 -1)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %38, label %12
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%15 = load i32, i32* @SIGHUP
%16 = tail call i32 @test_reboot(i32 %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %42, label %18
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.9, i64 0, i64 0))
%20 = load i32, i32* @LINUX_REBOOT_CMD_RESTART2
%21 = load i32, i32* @SIGHUP
%22 = tail call i32 @test_reboot(i32 %20, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %42, label %24
24: ; preds = %18
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.10, i64 0, i64 0))
%26 = load i32, i32* @LINUX_REBOOT_CMD_HALT
%27 = load i32, i32* @SIGINT
%28 = tail call i32 @test_reboot(i32 %26, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %24
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.11, i64 0, i64 0))
%32 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
%33 = load i32, i32* @SIGINT
%34 = tail call i32 @test_reboot(i32 %32, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %30
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.12, i64 0, i64 0))
br label %38
38: ; preds = %8, %5, %2, %36
%39 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0), %36 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.16, i64 0, i64 0), %2 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @str.15, i64 0, i64 0), %5 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @str.14, i64 0, i64 0), %8 ]
%40 = phi i32 [ 0, %36 ], [ 1, %2 ], [ 1, %5 ], [ 1, %8 ]
%41 = tail call i32 @puts(i8* dereferenceable(1) %39)
br label %42
42: ; preds = %38, %30, %24, %18, %12
%43 = phi i32 [ 1, %12 ], [ 1, %18 ], [ 1, %24 ], [ 1, %30 ], [ %40, %38 ]
ret i32 %43
}