#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 EXIT_FAILURE;
int LINUX_REBOOT_CMD_CAD_OFF;
unsigned int LINUX_REBOOT_CMD_HALT;
unsigned int LINUX_REBOOT_CMD_POWER_OFF;
unsigned int LINUX_REBOOT_CMD_RESTART;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ reboot(int);
int /*<<< orphan*/ sync();
int /*<<< orphan*/ usage();
int write(int, char *, int);
int main(int argc __attribute__((__unused__)), char *argv[]) {
  unsigned int cmd = 0;
  int do_sync = 1;
  char *ptr, *ptr2;
  ptr2 = ptr = argv[0];
  while (*ptr2)
    if (*ptr2++ == '/')
      ptr = ptr2;
  if (*ptr == 'r')
    cmd = LINUX_REBOOT_CMD_RESTART;
  else if (*ptr == 'h')
    cmd = LINUX_REBOOT_CMD_HALT;
  else if (*ptr == 'p')
    cmd = LINUX_REBOOT_CMD_POWER_OFF;
  else
    usage();
  while (*++argv && **argv == '-') {
    switch (*++*argv) {
    case 'f':
      break;
    case 'n':
      do_sync = 0;
      break;
    default:
      usage();
    }
  }
  if (*argv)
    usage();
  if (do_sync)
    sync();
  reboot(LINUX_REBOOT_CMD_CAD_OFF);
  if (!reboot((int)cmd)) {
    kill(getpid(), SIGSTOP);
  }
  if (write(2, "failed.\n", 8) == -1)
    return EXIT_FAILURE;
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c8 <main+0x68>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11c3 <main+0x63>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1193 <main+0x33>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    11e9 <main+0x89>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    123c <main+0xdc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    120a <main+0xaa>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1237 <main+0xd7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
jne    122b <main+0xcb>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1232 <main+0xd2>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    1237 <main+0xd7>
jmp    123c <main+0xdc>
jmp    1241 <main+0xe1>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,0x8(%rcx)
mov    %al,-0x29(%rbp)
je     1273 <main+0x113>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1283 <main+0x123>
jmp    12d7 <main+0x177>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movsbl 0x1(%rax),%eax
mov    %eax,-0x30(%rbp)
sub    $0x66,%eax
je     12ba <main+0x15a>
jmp    12a9 <main+0x149>
mov    -0x30(%rbp),%eax
sub    $0x6e,%eax
je     12bf <main+0x15f>
jmp    12cb <main+0x16b>
jmp    12d2 <main+0x172>
movl   $0x0,-0x18(%rbp)
jmp    12d2 <main+0x172>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    1241 <main+0xe1>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12ec <main+0x18c>
mov    $0x0,%al
call   1070 <usage@plt>
cmpl   $0x0,-0x18(%rbp)
je     12fd <main+0x19d>
mov    $0x0,%al
call   1060 <sync@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   1080 <reboot@plt>
mov    -0x14(%rbp),%edi
call   1080 <reboot@plt>
cmp    $0x0,%eax
jne    1333 <main+0x1d3>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2c8c(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    $0x2,%edi
lea    0xcc1(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x203>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136f <main+0x20f>
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%rax
mov    (%rax),%cl
test   %cl,%cl
je     11a9 <main+0x49>
lea    0x1(%rax),%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x2f,%cl
cmove  %rdx,%rax
movzbl (%rdx),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1180 <main+0x20>
mov    (%rax),%al
cmp    $0x68,%al
je     11b5 <main+0x55>
cmp    $0x70,%al
je     11be <main+0x5e>
cmp    $0x72,%al
jne    11a9 <main+0x49>
mov    0x2e39(%rip),%rax
jmp    11c5 <main+0x65>
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <usage@plt>
jmp    11c8 <main+0x68>
mov    0x2e04(%rip),%rax
jmp    11c5 <main+0x65>
mov    0x2e0b(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rbx),%rax
test   %rax,%rax
je     121d <main+0xbd>
add    $0x10,%rbx
mov    $0x1,%ebp
jmp    11f3 <main+0x93>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <usage@plt>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
je     1219 <main+0xb9>
cmpb   $0x2d,(%rax)
jne    1212 <main+0xb2>
lea    0x1(%rax),%rcx
mov    %rcx,-0x8(%rbx)
movsbl 0x1(%rax),%eax
cmp    $0x66,%eax
je     11e7 <main+0x87>
cmp    $0x6e,%eax
jne    11e0 <main+0x80>
xor    %ebp,%ebp
jmp    11e7 <main+0x87>
xor    %eax,%eax
call   1070 <usage@plt>
test   %ebp,%ebp
je     1224 <main+0xc4>
xor    %eax,%eax
call   1060 <sync@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <reboot@plt>
mov    %r14d,%edi
call   1080 <reboot@plt>
test   %eax,%eax
jne    1255 <main+0xf5>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x2d6c(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <kill@plt>
lea    0xda4(%rip),%rsi
mov    $0x2,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LINUX_REBOOT_CMD_RESTART = global i32 0
@LINUX_REBOOT_CMD_HALT = global i32 0
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
@LINUX_REBOOT_CMD_CAD_OFF = global i32 0
@SIGSTOP = global i32 0
@.str = [9 x i8] c"failed.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
store i8* %12, i8** %8
store i8* %12, i8** %9
br label %13
13: ; preds = %25, %2
%14 = load i8*, i8** %9
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %9
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i8*, i8** %9
store i8* %24, i8** %8
br label %25
25: ; preds = %23, %17
br label %13
26: ; preds = %13
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 114
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
store i32 %32, i32* %6
br label %51
33: ; preds = %26
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 104
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i32, i32* @LINUX_REBOOT_CMD_HALT
store i32 %39, i32* %6
br label %50
40: ; preds = %33
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 112
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
store i32 %46, i32* %6
br label %49
47: ; preds = %40
%48 = call i32 (...) @usage()
br label %49
49: ; preds = %47, %45
br label %50
50: ; preds = %49, %38
br label %51
51: ; preds = %50, %31
br label %52
52: ; preds = %75, %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i32 1
store i8** %54, i8*** %5
%55 = load i8*, i8** %54
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %63
57: ; preds = %52
%58 = load i8**, i8*** %5
%59 = load i8*, i8** %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 45
br label %63
63: ; preds = %57, %52
%64 = phi i1 [ false, %52 ], [ %62, %57 ]
br i1 %64, label %65, label %76
65: ; preds = %63
%66 = load i8**, i8*** %5
%67 = load i8*, i8** %66
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %66
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
switch i32 %70, label %73 [
i32 102, label %71
i32 110, label %72
]
71: ; preds = %65
br label %75
72: ; preds = %65
store i32 0, i32* %7
br label %75
73: ; preds = %65
%74 = call i32 (...) @usage()
br label %75
75: ; preds = %73, %72, %71
br label %52
76: ; preds = %63
%77 = load i8**, i8*** %5
%78 = load i8*, i8** %77
%79 = icmp ne i8* %78, null
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 (...) @usage()
br label %82
82: ; preds = %80, %76
%83 = load i32, i32* %7
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 (...) @sync()
br label %87
87: ; preds = %85, %82
%88 = load i32, i32* @LINUX_REBOOT_CMD_CAD_OFF
%89 = call i32 @reboot(i32 %88)
%90 = load i32, i32* %6
%91 = call i32 @reboot(i32 %90)
%92 = icmp ne i32 %91, 0
br i1 %92, label %97, label %93
93: ; preds = %87
%94 = call i32 (...) @getpid()
%95 = load i32, i32* @SIGSTOP
%96 = call i32 @kill(i32 %94, i32 %95)
br label %97
97: ; preds = %93, %87
%98 = call i32 @write(i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %102
100: ; preds = %97
%101 = load i32, i32* @EXIT_FAILURE
store i32 %101, i32* %3
br label %104
102: ; preds = %97
%103 = load i32, i32* @EXIT_FAILURE
store i32 %103, i32* %3
br label %104
104: ; preds = %102, %100
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
@LINUX_REBOOT_CMD_RESTART = global i32 0
@LINUX_REBOOT_CMD_HALT = global i32 0
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
@LINUX_REBOOT_CMD_CAD_OFF = global i32 0
@SIGSTOP = global i32 0
@.str = [9 x i8] c"failed.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %2, %6
%7 = phi i8 [ %13, %6 ], [ %4, %2 ]
%8 = phi i8* [ %10, %6 ], [ %3, %2 ]
%9 = phi i8* [ %12, %6 ], [ %3, %2 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = icmp eq i8 %7, 47
%12 = select i1 %11, i8* %10, i8* %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = load i8, i8* %12
switch i8 %16, label %23 [
i8 114, label %17
i8 104, label %19
i8 112, label %21
]
17: ; preds = %15
%18 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
br label %25
19: ; preds = %15
%20 = load i32, i32* @LINUX_REBOOT_CMD_HALT
br label %25
21: ; preds = %15
%22 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
br label %25
23: ; preds = %2, %15
%24 = tail call i32 (...) @usage()
br label %25
25: ; preds = %19, %23, %21, %17
%26 = phi i32 [ %18, %17 ], [ %20, %19 ], [ %22, %21 ], [ 0, %23 ]
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %53, label %30
30: ; preds = %25, %43
%31 = phi i8* [ %46, %43 ], [ %28, %25 ]
%32 = phi i8** [ %45, %43 ], [ %27, %25 ]
%33 = phi i32 [ %44, %43 ], [ 1, %25 ]
%34 = load i8, i8* %31
%35 = icmp eq i8 %34, 45
br i1 %35, label %36, label %48
36: ; preds = %30
%37 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %37, i8** %32
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
switch i32 %39, label %41 [
i32 102, label %43
i32 110, label %40
]
40: ; preds = %36
br label %43
41: ; preds = %36
%42 = tail call i32 (...) @usage()
br label %43
43: ; preds = %41, %40, %36
%44 = phi i32 [ %33, %41 ], [ 0, %40 ], [ %33, %36 ]
%45 = getelementptr inbounds i8*, i8** %32, i64 1
%46 = load i8*, i8** %45
%47 = icmp eq i8* %46, null
br i1 %47, label %50, label %30
48: ; preds = %30
%49 = tail call i32 (...) @usage()
br label %50
50: ; preds = %43, %48
%51 = phi i32 [ %33, %48 ], [ %44, %43 ]
%52 = icmp eq i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %25, %50
%54 = tail call i32 (...) @sync()
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* @LINUX_REBOOT_CMD_CAD_OFF
%57 = tail call i32 @reboot(i32 %56)
%58 = tail call i32 @reboot(i32 %26)
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = tail call i32 (...) @getpid()
%62 = load i32, i32* @SIGSTOP
%63 = tail call i32 @kill(i32 %61, i32 %62)
br label %64
64: ; preds = %60, %55
%65 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%66 = load i32, i32* @EXIT_FAILURE
ret i32 %66
}