#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 EX_USAGE;
int /*<<< orphan*/ RB_AUTOBOOT;
int /*<<< orphan*/ RB_HALT_SYSTEM;
int /*<<< orphan*/ RB_KEXEC;
int /*<<< orphan*/ RB_POWER_OFF;
int /*<<< orphan*/ RB_SW_SUSPEND;
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int pause();
int reboot(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc == 2 && !strcmp(argv[1], "halt"))
    return reboot(RB_HALT_SYSTEM);
  else if (argc == 2 && !strcmp(argv[1], "kexec"))
    return reboot(RB_KEXEC);
  else if (argc == 2 && !strcmp(argv[1], "poweroff"))
    return fork() > 0 ? pause() : reboot(RB_POWER_OFF);
  else if (argc == 2 && !strcmp(argv[1], "reboot"))
    return reboot(RB_AUTOBOOT);
  else if (argc == 2 && !strcmp(argv[1], "suspend"))
    return reboot(RB_SW_SUSPEND);
  fprintf(stderr,
          "Usage: %s ACTION\nActions:\n  halt      halt the machine\n  kexec   "
          "  jump to a new kernel loaded for kexec\n  poweroff  switch off the "
          "machine\n  reboot    restart the machine\n  suspend   hibernate the "
          "machine to disk\nAll actions are performed immediately without "
          "flushing buffers or a\ngraceful shutdown. Data may be lost on "
          "unsynced mounted filesystems.\n",
          argv[0]);
  return EX_USAGE;
}


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)
cmpl   $0x2,-0x8(%rbp)
jne    11a3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11a3 <main+0x53>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
mov    %eax,-0x4(%rbp)
jmp    12f9 <main+0x1a9>
cmpl   $0x2,-0x8(%rbp)
jne    11e0 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11e0 <main+0x90>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
mov    %eax,-0x4(%rbp)
jmp    12f9 <main+0x1a9>
cmpl   $0x2,-0x8(%rbp)
jne    1243 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe12(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1243 <main+0xf3>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jle    1227 <main+0xd7>
mov    $0x0,%al
call   1050 <pause@plt>
mov    %eax,-0x14(%rbp)
jmp    1238 <main+0xe8>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f9 <main+0x1a9>
cmpl   $0x2,-0x8(%rbp)
jne    1280 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1280 <main+0x130>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
mov    %eax,-0x4(%rbp)
jmp    12f9 <main+0x1a9>
cmpl   $0x2,-0x8(%rbp)
jne    12bd <main+0x16d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd82(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    12bd <main+0x16d>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
mov    %eax,-0x4(%rbp)
jmp    12f9 <main+0x1a9>
jmp    12c2 <main+0x172>
jmp    12c7 <main+0x177>
jmp    12cc <main+0x17c>
jmp    12d1 <main+0x181>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd3b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11bf <main+0x6f>
mov    0x8(%r14),%rbx
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11e8 <main+0x98>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11f1 <main+0xa1>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11fa <main+0xaa>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1214 <main+0xc4>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     121d <main+0xcd>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd1(%rip),%rax
jmp    122d <main+0xdd>
mov    0x2de0(%rip),%rax
jmp    122d <main+0xdd>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1226 <main+0xd6>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <pause@plt>
mov    0x2d9d(%rip),%rax
jmp    122d <main+0xdd>
mov    0x2d84(%rip),%rax
jmp    122d <main+0xdd>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <reboot@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"halt\00"
@RB_HALT_SYSTEM = global i32 0
@.str.1 = [6 x i8] c"kexec\00"
@RB_KEXEC = global i32 0
@.str.2 = [9 x i8] c"poweroff\00"
@RB_POWER_OFF = global i32 0
@.str.3 = [7 x i8] c"reboot\00"
@RB_AUTOBOOT = global i32 0
@.str.4 = [8 x i8] c"suspend\00"
@RB_SW_SUSPEND = global i32 0
@stderr = global i32 0
@.str.5 = [352 x i8] c"Usage: %s ACTION\0AActions:\0A halt halt the machine\0A kexec jump to a new kernel loaded for kexec\0A poweroff switch off the machine\0A reboot restart the machine\0A suspend hibernate the machine to disk\0AAll actions are performed immediately without flushing buffers or a\0Agraceful shutdown. Data may be lost on unsynced mounted filesystems.\0A\00"
@EX_USAGE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* @RB_HALT_SYSTEM
%16 = call i32 @reboot(i32 %15)
store i32 %16, i32* %3
br label %83
17: ; preds = %8, %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* @RB_KEXEC
%28 = call i32 @reboot(i32 %27)
store i32 %28, i32* %3
br label %83
29: ; preds = %20, %17
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %32
%39 = call i64 (...) @fork()
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (...) @pause()
br label %46
43: ; preds = %38
%44 = load i32, i32* @RB_POWER_OFF
%45 = call i32 @reboot(i32 %44)
br label %46
46: ; preds = %43, %41
%47 = phi i32 [ %42, %41 ], [ %45, %43 ]
store i32 %47, i32* %3
br label %83
48: ; preds = %32, %29
%49 = load i32, i32* %4
%50 = icmp eq i32 %49, 2
br i1 %50, label %51, label %60
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %51
%58 = load i32, i32* @RB_AUTOBOOT
%59 = call i32 @reboot(i32 %58)
store i32 %59, i32* %3
br label %83
60: ; preds = %51, %48
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, 2
br i1 %62, label %63, label %72
63: ; preds = %60
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32 @strcmp(i8* %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%68 = icmp ne i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %63
%70 = load i32, i32* @RB_SW_SUSPEND
%71 = call i32 @reboot(i32 %70)
store i32 %71, i32* %3
br label %83
72: ; preds = %63, %60
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
%77 = load i32, i32* @stderr
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([352 x i8], [352 x i8]* @.str.5, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EX_USAGE
store i32 %82, i32* %3
br label %83
83: ; preds = %76, %69, %57, %46, %26, %14
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [5 x i8] c"halt\00"
@RB_HALT_SYSTEM = global i32 0
@.str.1 = [6 x i8] c"kexec\00"
@RB_KEXEC = global i32 0
@.str.2 = [9 x i8] c"poweroff\00"
@RB_POWER_OFF = global i32 0
@.str.3 = [7 x i8] c"reboot\00"
@RB_AUTOBOOT = global i32 0
@.str.4 = [8 x i8] c"suspend\00"
@RB_SW_SUSPEND = global i32 0
@stderr = global i32 0
@.str.5 = [352 x i8] c"Usage: %s ACTION\0AActions:\0A halt halt the machine\0A kexec jump to a new kernel loaded for kexec\0A poweroff switch off the machine\0A reboot restart the machine\0A suspend hibernate the machine to disk\0AAll actions are performed immediately without flushing buffers or a\0Agraceful shutdown. Data may be lost on unsynced mounted filesystems.\0A\00"
@EX_USAGE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %41
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @RB_HALT_SYSTEM
%11 = tail call i32 @reboot(i32 %10)
br label %46
12: ; preds = %4
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @RB_KEXEC
%17 = tail call i32 @reboot(i32 %16)
br label %46
18: ; preds = %12
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (...) @pause()
br label %46
26: ; preds = %21
%27 = load i32, i32* @RB_POWER_OFF
%28 = tail call i32 @reboot(i32 %27)
br label %46
29: ; preds = %18
%30 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @RB_AUTOBOOT
%34 = tail call i32 @reboot(i32 %33)
br label %46
35: ; preds = %29
%36 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @RB_SW_SUSPEND
%40 = tail call i32 @reboot(i32 %39)
br label %46
41: ; preds = %2, %35
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %1
%44 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([352 x i8], [352 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EX_USAGE
br label %46
46: ; preds = %24, %26, %41, %38, %32, %15, %9
%47 = phi i32 [ %45, %41 ], [ %40, %38 ], [ %34, %32 ], [ %17, %15 ], [ %11, %9 ], [ %25, %24 ], [ %28, %26 ]
ret i32 %47
}