#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 */
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
scalar_t__ EINTR;
unsigned int RB_AUTOBOOT;
unsigned int RB_HALT_SYSTEM;
unsigned int RB_POWER_OFF;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ _exit(int);
scalar_t__ call_reboot(unsigned int);
scalar_t__ do_shutdown(unsigned int, int /*<<< orphan*/);
scalar_t__ errno;
char getopt(int, char **, char *);
scalar_t__ kill(int, int /*<<< orphan*/);
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ request_shutdown(unsigned int);
int /*<<< orphan*/ shutdown_fallback(unsigned int);
int /*<<< orphan*/ sig_setup();
char *strerror(scalar_t__);
int /*<<< orphan*/ sync();
int main(int argc, char **argv) {
  unsigned int rb_action = RB_POWER_OFF;
  int should_reboot = 0;
  int should_halt = 0;
  int immediate = 0;
  int stealth = 0;
  int force = 0;
  char c = 0;
  sig_setup();
  while ((c = getopt(argc, argv, "prhfZs")) != -1) {
    switch (c) {
    case 'p':
      break;
    case 'r':
      should_reboot = 1;
      break;
    case 'h':
      should_halt = 1;
      break;
    case 'f':
      force = 1;
      break;
    case 's':
      stealth = 1;
      force = 1;
      break;
    case 'Z':
      immediate = 1;
      break;
    default:
      printf("usage:\n");
      printf("shutdown -p power off\n");
      printf("shutdown -h halt\n");
      printf("shutdown -r reboot\n");
      printf("shutdown -f force (dont signal, use direct syscall\n");
      printf("shutdown -s stealth, no sigterm (implies -f)");
      printf("shutdown -Z immediate dangerous shutdown");
      _exit(1);
      break;
    }
  }
  rb_action = RB_POWER_OFF;
  if (should_reboot) {
    rb_action = RB_AUTOBOOT;
  }
  if (should_halt) {
    rb_action = RB_HALT_SYSTEM;
  }
  if (immediate) {
    if (call_reboot(rb_action)) {
      printf("reboot: %s\n", strerror(errno));
    }
    _exit(-1);
  }
  sync();
  if (force) {
    struct timespec request, remain;
    int sec;
    if (!stealth) {
      if (kill(-1, SIGTERM)) {
        printf("kill(-1, SIGTERM): %s\n", strerror(errno));
      }
      sec = ((int)10);
      while (--sec >= 0) {
        request.tv_sec = 1;
        request.tv_nsec = 0;
        remain.tv_sec = 0;
        remain.tv_nsec = 0;
      re_sleep:
        errno = 0;
        if (nanosleep(&request, &remain)) {
          if (errno == EINTR) {
            request.tv_sec = remain.tv_sec;
            request.tv_nsec = remain.tv_nsec;
            goto re_sleep;
          }
        }
      }
    }
    if (do_shutdown(rb_action, 0)) {
      shutdown_fallback(rb_action);
      _exit(-1);
    }
  } else {
    if (request_shutdown(rb_action)) {
      _exit(-1);
    }
  }
  _exit(-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
mov    $0x0,%al
call   1080 <sig_setup@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4a(%rip),%rdx
call   10d0 <getopt@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1315 <main+0x155>
movsbl -0x29(%rbp),%eax
add    $0xffffffa6,%eax
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x19,%eax
ja     12a4 <main+0xe4>
mov    -0x60(%rbp),%rax
lea    0xdad(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1310 <main+0x150>
movl   $0x1,-0x18(%rbp)
jmp    1310 <main+0x150>
movl   $0x1,-0x1c(%rbp)
jmp    1310 <main+0x150>
movl   $0x1,-0x28(%rbp)
jmp    1310 <main+0x150>
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1310 <main+0x150>
movl   $0x1,-0x20(%rbp)
jmp    1310 <main+0x150>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    1210 <main+0x50>
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1337 <main+0x177>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     134d <main+0x18d>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1393 <main+0x1d3>
mov    -0x14(%rbp),%edi
call   10c0 <call_reboot@plt>
cmp    $0x0,%rax
je     1389 <main+0x1c9>
mov    0x2c60(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    %rax,%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
mov    $0x0,%al
call   10b0 <sync@plt>
cmpl   $0x0,-0x28(%rbp)
je     14ae <main+0x2ee>
cmpl   $0x0,-0x24(%rbp)
jne    1483 <main+0x2c3>
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   1090 <kill@plt>
cmp    $0x0,%rax
je     13eb <main+0x22b>
mov    0x2bfe(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    %rax,%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xa,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jl     147e <main+0x2be>
movl   $0x1,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    0x2ba7(%rip),%rax
movq   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1070 <nanosleep@plt>
cmp    $0x0,%rax
je     1479 <main+0x2b9>
mov    0x2b82(%rip),%rax
mov    (%rax),%rax
mov    0x2b68(%rip),%rcx
cmp    (%rcx),%rax
jne    1474 <main+0x2b4>
mov    -0x50(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1422 <main+0x262>
jmp    1479 <main+0x2b9>
jmp    13f2 <main+0x232>
jmp    1483 <main+0x2c3>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   10a0 <do_shutdown@plt>
cmp    $0x0,%rax
je     14a9 <main+0x2e9>
mov    -0x14(%rbp),%edi
call   1060 <shutdown_fallback@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
jmp    14cf <main+0x30f>
mov    -0x14(%rbp),%edi
call   1040 <request_shutdown@plt>
cmp    $0x0,%rax
je     14ca <main+0x30a>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
jmp    14cf <main+0x30f>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <sig_setup@plt>
lea    0xe74(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <getopt@plt>
mov    $0x1,%cl
mov    $0x0,%r12d
mov    $0x0,%edx
cmp    $0xff,%al
je     12bd <main+0xed>
xor    %r15d,%r15d
lea    0xde3(%rip),%r12
lea    0xe44(%rip),%r14
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r13d,%r13d
movl   $0x0,0x14(%rsp)
jmp    1261 <main+0x91>
movl   $0x1,0x14(%rsp)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getopt@plt>
cmp    $0xff,%al
je     12a3 <main+0xd3>
movsbl %al,%eax
add    $0xffffffa6,%eax
cmp    $0x19,%eax
ja     143c <main+0x26c>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
movl   $0x1,0xc(%rsp)
jmp    1250 <main+0x80>
mov    $0x1,%r15d
jmp    1250 <main+0x80>
mov    $0x1,%r13d
jmp    1250 <main+0x80>
movl   $0x1,0x10(%rsp)
mov    $0x1,%r15d
jmp    1250 <main+0x80>
test   %r13d,%r13d
sete   %cl
cmpl   $0x0,0x14(%rsp)
jne    140d <main+0x23d>
mov    0x10(%rsp),%r12d
mov    0xc(%rsp),%edx
mov    0x2d2c(%rip),%rax
test   %cl,%cl
jne    12cf <main+0xff>
mov    0x2cf9(%rip),%rax
mov    (%rax),%r14d
test   %edx,%edx
jne    12f7 <main+0x127>
xor    %eax,%eax
call   10c0 <sync@plt>
test   %r15d,%r15d
jne    132d <main+0x15d>
mov    %r14d,%edi
call   1050 <request_shutdown@plt>
test   %rax,%rax
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
mov    %r14d,%edi
call   10d0 <call_reboot@plt>
test   %rax,%rax
je     1403 <main+0x233>
mov    0x2cc1(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xda7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1403 <main+0x233>
test   %r12d,%r12d
jne    13f4 <main+0x224>
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
call   10a0 <kill@plt>
test   %rax,%rax
je     136e <main+0x19e>
mov    0x2c7b(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xd6d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x9,%ebp
mov    0x2c56(%rip),%rbx
lea    0x28(%rsp),%r15
lea    0x18(%rsp),%r12
mov    0x2c35(%rip),%r13
jmp    1395 <main+0x1c5>
nopl   (%rax)
sub    $0x1,%ebp
jb     13f4 <main+0x224>
movl   $0x1,0x28(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movq   $0x0,(%rbx)
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <nanosleep@plt>
test   %rax,%rax
je     1390 <main+0x1c0>
mov    (%rbx),%rax
cmp    0x0(%r13),%rax
jne    1390 <main+0x1c0>
mov    0x18(%rsp),%eax
mov    %eax,0x28(%rsp)
mov    0x20(%rsp),%rax
mov    %rax,0x30(%rsp)
jmp    13c0 <main+0x1f0>
mov    %r14d,%edi
xor    %esi,%esi
call   10b0 <do_shutdown@plt>
test   %rax,%rax
jne    142a <main+0x25a>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
mov    0x2ba4(%rip),%rax
mov    0x10(%rsp),%r12d
mov    0xc(%rsp),%edx
test   %cl,%cl
je     12c8 <main+0xf8>
jmp    12cf <main+0xff>
mov    %r14d,%edi
call   1070 <shutdown_fallback@plt>
mov    $0xffffffff,%edi
call   1030 <_exit@plt>
lea    0xca5(%rip),%rdi
call   1040 <puts@plt>
lea    0xca0(%rip),%rdi
call   1040 <puts@plt>
lea    0xcaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xcaf(%rip),%rdi
call   1040 <puts@plt>
lea    0xcb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xbf0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc0f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@RB_POWER_OFF = global i32 0
@.str = [7 x i8] c"prhfZs\00"
@.str.1 = [8 x i8] c"usage:\0A\00"
@.str.2 = [23 x i8] c"shutdown -p power off\0A\00"
@.str.3 = [18 x i8] c"shutdown -h halt\0A\00"
@.str.4 = [20 x i8] c"shutdown -r reboot\0A\00"
@.str.5 = [52 x i8] c"shutdown -f force (dont signal, use direct syscall\0A\00"
@.str.6 = [45 x i8] c"shutdown -s stealth, no sigterm (implies -f)\00"
@.str.7 = [41 x i8] c"shutdown -Z immediate dangerous shutdown\00"
@RB_AUTOBOOT = global i32 0
@RB_HALT_SYSTEM = global i32 0
@.str.8 = [12 x i8] c"reboot: %s\0A\00"
@errno = global i64 0
@SIGTERM = global i32 0
@.str.9 = [23 x i8] c"kill(-1, SIGTERM): %s\0A\00"
@EINTR = global i64 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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca %struct.timespec
%14 = alloca %struct.timespec
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @RB_POWER_OFF
store i32 %16, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i8 0, i8* %12
%17 = call i32 (...) @sig_setup()
br label %18
18: ; preds = %42, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call signext i8 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 %21, i8* %12
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %43
24: ; preds = %18
%25 = load i8, i8* %12
%26 = sext i8 %25 to i32
switch i32 %26, label %33 [
i32 112, label %27
i32 114, label %28
i32 104, label %29
i32 102, label %30
i32 115, label %31
i32 90, label %32
]
27: ; preds = %24
br label %42
28: ; preds = %24
store i32 1, i32* %7
br label %42
29: ; preds = %24
store i32 1, i32* %8
br label %42
30: ; preds = %24
store i32 1, i32* %11
br label %42
31: ; preds = %24
store i32 1, i32* %10
store i32 1, i32* %11
br label %42
32: ; preds = %24
store i32 1, i32* %9
br label %42
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @_exit(i32 1)
unreachable
42: ; preds = %32, %31, %30, %29, %28, %27
br label %18
43: ; preds = %18
%44 = load i32, i32* @RB_POWER_OFF
store i32 %44, i32* %6
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i32, i32* @RB_AUTOBOOT
store i32 %48, i32* %6
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = load i32, i32* @RB_HALT_SYSTEM
store i32 %53, i32* %6
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* %9
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = load i32, i32* %6
%59 = call i64 @call_reboot(i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i64, i64* @errno
%63 = call i8* @strerror(i64 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %61, %57
%66 = call i32 @_exit(i32 -1)
unreachable
67: ; preds = %54
%68 = call i32 (...) @sync()
%69 = load i32, i32* %11
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %118
71: ; preds = %67
%72 = load i32, i32* %10
%73 = icmp ne i32 %72, 0
br i1 %73, label %109, label %74
74: ; preds = %71
%75 = load i32, i32* @SIGTERM
%76 = call i64 @kill(i32 -1, i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = load i64, i64* @errno
%80 = call i8* @strerror(i64 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %78, %74
store i32 10, i32* %15
br label %83
83: ; preds = %107, %82
%84 = load i32, i32* %15
%85 = add nsw i32 %84, -1
store i32 %85, i32* %15
%86 = icmp sge i32 %85, 0
br i1 %86, label %87, label %108
87: ; preds = %83
%88 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
store i32 1, i32* %88
%89 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
store i64 0, i64* %89
%90 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
store i32 0, i32* %90
%91 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
store i64 0, i64* %91
br label %92
92: ; preds = %99, %87
store i64 0, i64* @errno
%93 = call i64 @nanosleep(%struct.timespec* %13, %struct.timespec* %14)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %107
95: ; preds = %92
%96 = load i64, i64* @errno
%97 = load i64, i64* @EINTR
%98 = icmp eq i64 %96, %97
br i1 %98, label %99, label %106
99: ; preds = %95
%100 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%101 = load i32, i32* %100
%102 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
store i32 %101, i32* %102
%103 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
%104 = load i64, i64* %103
%105 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
store i64 %104, i64* %105
br label %92
106: ; preds = %95
br label %107
107: ; preds = %106, %92
br label %83
108: ; preds = %83
br label %109
109: ; preds = %108, %71
%110 = load i32, i32* %6
%111 = call i64 @do_shutdown(i32 %110, i32 0)
%112 = icmp ne i64 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %109
%114 = load i32, i32* %6
%115 = call i32 @shutdown_fallback(i32 %114)
%116 = call i32 @_exit(i32 -1)
unreachable
117: ; preds = %109
br label %125
118: ; preds = %67
%119 = load i32, i32* %6
%120 = call i64 @request_shutdown(i32 %119)
%121 = icmp ne i64 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %118
%123 = call i32 @_exit(i32 -1)
unreachable
124: ; preds = %118
br label %125
125: ; preds = %124, %117
%126 = call i32 @_exit(i32 -1)
unreachable
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@RB_POWER_OFF = global i32 0
@.str = [7 x i8] c"prhfZs\00"
@.str.6 = [45 x i8] c"shutdown -s stealth, no sigterm (implies -f)\00"
@.str.7 = [41 x i8] c"shutdown -Z immediate dangerous shutdown\00"
@RB_AUTOBOOT = global i32 0
@RB_HALT_SYSTEM = global i32 0
@.str.8 = [12 x i8] c"reboot: %s\0A\00"
@errno = global i64 0
@SIGTERM = global i32 0
@.str.9 = [23 x i8] c"kill(-1, SIGTERM): %s\0A\00"
@EINTR = global i64 0
@str = [7 x i8] c"usage:\00"
@str.10 = [22 x i8] c"shutdown -p power off\00"
@str.11 = [17 x i8] c"shutdown -h halt\00"
@str.12 = [19 x i8] c"shutdown -r reboot\00"
@str.13 = [51 x i8] c"shutdown -f force (dont signal, use direct syscall\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = tail call i32 (...) @sig_setup()
%6 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8 %6, -1
br i1 %7, label %41, label %8
8: ; preds = %2, %30
%9 = phi i8 [ %36, %30 ], [ %6, %2 ]
%10 = phi i32 [ %35, %30 ], [ 0, %2 ]
%11 = phi i32 [ %34, %30 ], [ 0, %2 ]
%12 = phi i32 [ %33, %30 ], [ 0, %2 ]
%13 = phi i32 [ %32, %30 ], [ 0, %2 ]
%14 = phi i32 [ %31, %30 ], [ 0, %2 ]
%15 = sext i8 %9 to i32
switch i32 %15, label %21 [
i32 112, label %30
i32 114, label %16
i32 104, label %17
i32 102, label %18
i32 115, label %19
i32 90, label %20
]
16: ; preds = %8
br label %30
17: ; preds = %8
br label %30
18: ; preds = %8
br label %30
19: ; preds = %8
br label %30
20: ; preds = %8
br label %30
21: ; preds = %8
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.11, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.12, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.13, i64 0, i64 0))
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
%29 = tail call i32 @_exit(i32 1)
unreachable
30: ; preds = %20, %19, %18, %17, %16, %8
%31 = phi i32 [ %14, %20 ], [ %14, %19 ], [ %14, %18 ], [ %14, %17 ], [ 1, %16 ], [ %14, %8 ]
%32 = phi i32 [ %13, %20 ], [ %13, %19 ], [ %13, %18 ], [ 1, %17 ], [ %13, %16 ], [ %13, %8 ]
%33 = phi i32 [ 1, %20 ], [ %12, %19 ], [ %12, %18 ], [ %12, %17 ], [ %12, %16 ], [ %12, %8 ]
%34 = phi i32 [ %11, %20 ], [ 1, %19 ], [ %11, %18 ], [ %11, %17 ], [ %11, %16 ], [ %11, %8 ]
%35 = phi i32 [ %10, %20 ], [ 1, %19 ], [ 1, %18 ], [ %10, %17 ], [ %10, %16 ], [ %10, %8 ]
%36 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i8 %36, -1
br i1 %37, label %38, label %8
38: ; preds = %30
%39 = icmp eq i32 %31, 0
%40 = icmp eq i32 %32, 0
br i1 %39, label %41, label %46
41: ; preds = %2, %38
%42 = phi i1 [ %40, %38 ], [ true, %2 ]
%43 = phi i32 [ %35, %38 ], [ 0, %2 ]
%44 = phi i32 [ %34, %38 ], [ 0, %2 ]
%45 = phi i32 [ %33, %38 ], [ 0, %2 ]
br label %46
46: ; preds = %38, %41
%47 = phi i1 [ %42, %41 ], [ %40, %38 ]
%48 = phi i32 [ %43, %41 ], [ %35, %38 ]
%49 = phi i32 [ %44, %41 ], [ %34, %38 ]
%50 = phi i32 [ %45, %41 ], [ %33, %38 ]
%51 = phi i32* [ @RB_POWER_OFF, %41 ], [ @RB_AUTOBOOT, %38 ]
%52 = load i32, i32* %51
%53 = load i32, i32* @RB_HALT_SYSTEM
%54 = select i1 %47, i32 %52, i32 %53
%55 = icmp eq i32 %50, 0
br i1 %55, label %65, label %56
56: ; preds = %46
%57 = tail call i64 @call_reboot(i32 %54)
%58 = icmp eq i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %56
%60 = load i64, i64* @errno
%61 = tail call i8* @strerror(i64 %60)
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %59, %56
%64 = tail call i32 @_exit(i32 -1)
unreachable
65: ; preds = %46
%66 = tail call i32 (...) @sync()
%67 = icmp eq i32 %48, 0
br i1 %67, label %108, label %68
68: ; preds = %65
%69 = bitcast %struct.timespec* %3 to i8*
%70 = bitcast %struct.timespec* %4 to i8*
%71 = icmp eq i32 %49, 0
br i1 %71, label %72, label %101
72: ; preds = %68
%73 = load i32, i32* @SIGTERM
%74 = tail call i64 @kill(i32 -1, i32 %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %80, label %76
76: ; preds = %72
%77 = load i64, i64* @errno
%78 = tail call i8* @strerror(i64 %77)
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %76, %72
%81 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%82 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%83 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%84 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
br label %85
85: ; preds = %80, %98
%86 = phi i32 [ 9, %80 ], [ %99, %98 ]
store i32 1, i32* %81
store i64 0, i64* %82
store i32 0, i32* %83
store i64 0, i64* %84
store i64 0, i64* @errno
%87 = call i64 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%88 = icmp eq i64 %87, 0
br i1 %88, label %98, label %89
89: ; preds = %85, %93
%90 = load i64, i64* @errno
%91 = load i64, i64* @EINTR
%92 = icmp eq i64 %90, %91
br i1 %92, label %93, label %98
93: ; preds = %89
%94 = load i32, i32* %83
store i32 %94, i32* %81
%95 = load i64, i64* %84
store i64 %95, i64* %82
store i64 0, i64* @errno
%96 = call i64 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %89
98: ; preds = %93, %89, %85
%99 = add nsw i32 %86, -1
%100 = icmp eq i32 %86, 0
br i1 %100, label %101, label %85
101: ; preds = %98, %68
%102 = call i64 @do_shutdown(i32 %54, i32 0)
%103 = icmp eq i64 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %101
%105 = call i32 @shutdown_fallback(i32 %54)
%106 = call i32 @_exit(i32 -1)
unreachable
107: ; preds = %101
br label %113
108: ; preds = %65
%109 = tail call i64 @request_shutdown(i32 %54)
%110 = icmp eq i64 %109, 0
br i1 %110, label %113, label %111
111: ; preds = %108
%112 = tail call i32 @_exit(i32 -1)
unreachable
113: ; preds = %108, %107
%114 = call i32 @_exit(i32 -1)
unreachable
}