#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;
scalar_t__ call_reboot(unsigned int);
scalar_t__ errno;
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setenv(char *, char *, int);
char *strerror(scalar_t__);
int /*<<< orphan*/ sync();
int /*<<< orphan*/ system(char *);
void shutdown_fallback(unsigned int rb_action) {
  struct timespec request, remain;
  setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1);
  printf("\n\n");
  printf("*********************************************\n");
  printf("         FALLBACK SHUTDOWN TRIGGERED         \n");
  printf("*********************************************\n");
  system("swapoff -a");
  printf("unmounting filesystems\n");
  sync();
  system("umount -v -a -r -t no,proc,sysfs");
  system("mount -v -n -o remount,ro /");
  printf("synchronizing storage devices\n");
  sync();
  request.tv_sec = 8;
  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 (rb_action == RB_AUTOBOOT) {
    if (call_reboot(RB_AUTOBOOT)) {
      printf("reboot: %s\n", strerror(errno));
    }
  } else if (rb_action == RB_HALT_SYSTEM) {
    if (call_reboot(RB_HALT_SYSTEM)) {
      printf("halt: %s\n", strerror(errno));
    }
  } else {
    if (call_reboot(RB_POWER_OFF)) {
      printf("shutdown: %s\n", strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<shutdown_fallback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe7e(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb2(%rip),%rdi
call   1040 <system@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <sync@plt>
lea    0xeb4(%rip),%rdi
call   1040 <system@plt>
lea    0xec9(%rip),%rdi
call   1040 <system@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <sync@plt>
movl   $0x8,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2d9a(%rip),%rax
movq   $0x0,(%rax)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <nanosleep@plt>
cmp    $0x0,%rax
je     128e <shutdown_fallback+0x11e>
mov    0x2d75(%rip),%rax
mov    (%rax),%rax
mov    0x2d5b(%rip),%rcx
cmp    (%rcx),%rax
jne    1289 <shutdown_fallback+0x119>
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1237 <shutdown_fallback+0xc7>
jmp    128e <shutdown_fallback+0x11e>
mov    -0x4(%rbp),%eax
mov    0x2d28(%rip),%rcx
cmp    (%rcx),%eax
jne    12dd <shutdown_fallback+0x16d>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1080 <call_reboot@plt>
cmp    $0x0,%rax
je     12d8 <shutdown_fallback+0x168>
mov    0x2d19(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    136e <shutdown_fallback+0x1fe>
mov    -0x4(%rbp),%eax
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%eax
jne    132c <shutdown_fallback+0x1bc>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1080 <call_reboot@plt>
cmp    $0x0,%rax
je     1327 <shutdown_fallback+0x1b7>
mov    0x2cca(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1369 <shutdown_fallback+0x1f9>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   1080 <call_reboot@plt>
cmp    $0x0,%rax
je     1364 <shutdown_fallback+0x1f4>
mov    0x2c8d(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1369 <shutdown_fallback+0x1f9>
jmp    136e <shutdown_fallback+0x1fe>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shutdown_fallback>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
lea    0xe6a(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
lea    0xf03(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe46(%rip),%rdi
call   1050 <system@plt>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <sync@plt>
lea    0xe32(%rip),%rdi
call   1050 <system@plt>
lea    0xe47(%rip),%rdi
call   1050 <system@plt>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <sync@plt>
movl   $0x8,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2d90(%rip),%r15
movq   $0x0,(%r15)
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   1070 <nanosleep@plt>
test   %rax,%rax
je     12a0 <shutdown_fallback+0x120>
mov    0x2d60(%rip),%rbx
lea    0x10(%rsp),%r12
mov    %rsp,%rbp
mov    (%r15),%rax
cmp    (%rbx),%rax
jne    12a0 <shutdown_fallback+0x120>
mov    (%rsp),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,(%r15)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <nanosleep@plt>
test   %rax,%rax
jne    1270 <shutdown_fallback+0xf0>
mov    0x2d19(%rip),%rax
cmp    %r14d,(%rax)
jne    12c2 <shutdown_fallback+0x142>
mov    %r14d,%edi
call   1090 <call_reboot@plt>
test   %rax,%rax
je     1313 <shutdown_fallback+0x193>
lea    0xdab(%rip),%rbx
jmp    12fe <shutdown_fallback+0x17e>
mov    0x2d07(%rip),%rax
cmp    %r14d,(%rax)
jne    12e4 <shutdown_fallback+0x164>
mov    %r14d,%edi
call   1090 <call_reboot@plt>
test   %rax,%rax
je     1313 <shutdown_fallback+0x193>
lea    0xd95(%rip),%rbx
jmp    12fe <shutdown_fallback+0x17e>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <call_reboot@plt>
test   %rax,%rax
je     1313 <shutdown_fallback+0x193>
lea    0xd83(%rip),%rbx
mov    (%r15),%rdi
call   10a0 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [5 x i8] c"PATH\00"
@.str.1 = [30 x i8] c"/sbin:/bin:/usr/sbin:/usr/bin\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [47 x i8] c"*********************************************\0A\00"
@.str.4 = [47 x i8] c" FALLBACK SHUTDOWN TRIGGERED \0A\00"
@.str.5 = [11 x i8] c"swapoff -a\00"
@.str.6 = [24 x i8] c"unmounting filesystems\0A\00"
@.str.7 = [33 x i8] c"umount -v -a -r -t no,proc,sysfs\00"
@.str.8 = [28 x i8] c"mount -v -n -o remount,ro /\00"
@.str.9 = [31 x i8] c"synchronizing storage devices\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@RB_AUTOBOOT = global i32 0
@.str.10 = [12 x i8] c"reboot: %s\0A\00"
@RB_HALT_SYSTEM = global i32 0
@.str.11 = [10 x i8] c"halt: %s\0A\00"
@RB_POWER_OFF = global i32 0
@.str.12 = [14 x i8] c"shutdown: %s\0A\00"
define void @shutdown_fallback(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
store i32 %0, i32* %2
%5 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%12 = call i32 (...) @sync()
%13 = call i32 @system(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%14 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%16 = call i32 (...) @sync()
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 8, i32* %17
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 0, i64* %18
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %20
br label %21
21: ; preds = %28, %1
store i64 0, i64* @errno
%22 = call i64 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %33, i64* %34
br label %21
35: ; preds = %24
br label %36
36: ; preds = %35, %21
%37 = load i32, i32* %2
%38 = load i32, i32* @RB_AUTOBOOT
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32, i32* @RB_AUTOBOOT
%42 = call i64 @call_reboot(i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %44, %40
br label %72
49: ; preds = %36
%50 = load i32, i32* %2
%51 = load i32, i32* @RB_HALT_SYSTEM
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %62
53: ; preds = %49
%54 = load i32, i32* @RB_HALT_SYSTEM
%55 = call i64 @call_reboot(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i64, i64* @errno
%59 = call i8* @strerror(i64 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %57, %53
br label %71
62: ; preds = %49
%63 = load i32, i32* @RB_POWER_OFF
%64 = call i64 @call_reboot(i32 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i64, i64* @errno
%68 = call i8* @strerror(i64 %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %66, %62
br label %71
71: ; preds = %70, %61
br label %72
72: ; preds = %71, %48
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [5 x i8] c"PATH\00"
@.str.1 = [30 x i8] c"/sbin:/bin:/usr/sbin:/usr/bin\00"
@.str.5 = [11 x i8] c"swapoff -a\00"
@.str.7 = [33 x i8] c"umount -v -a -r -t no,proc,sysfs\00"
@.str.8 = [28 x i8] c"mount -v -n -o remount,ro /\00"
@errno = global i64 0
@EINTR = global i64 0
@RB_AUTOBOOT = global i32 0
@.str.10 = [12 x i8] c"reboot: %s\0A\00"
@RB_HALT_SYSTEM = global i32 0
@.str.11 = [10 x i8] c"halt: %s\0A\00"
@RB_POWER_OFF = global i32 0
@.str.12 = [14 x i8] c"shutdown: %s\0A\00"
@str = [2 x i8] c"\0A\00"
@str.14 = [46 x i8] c" FALLBACK SHUTDOWN TRIGGERED \00"
@str.15 = [46 x i8] c"*********************************************\00"
@str.16 = [23 x i8] c"unmounting filesystems\00"
@str.17 = [30 x i8] c"synchronizing storage devices\00"
define void @shutdown_fallback(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.15, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.16, i64 0, i64 0))
%13 = tail call i32 (...) @sync()
%14 = tail call i32 @system(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%15 = tail call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.17, i64 0, i64 0))
%17 = tail call i32 (...) @sync()
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 8, i32* %18
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 0, i64* %21
store i64 0, i64* @errno
%22 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %1, %28
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* %20
store i32 %29, i32* %18
%30 = load i64, i64* %21
store i64 %30, i64* %19
store i64 0, i64* @errno
%31 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %24
33: ; preds = %28, %24, %1
%34 = load i32, i32* @RB_AUTOBOOT
%35 = icmp eq i32 %34, %0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i64 @call_reboot(i32 %0)
%38 = icmp eq i64 %37, 0
br i1 %38, label %54, label %49
39: ; preds = %33
%40 = load i32, i32* @RB_HALT_SYSTEM
%41 = icmp eq i32 %40, %0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i64 @call_reboot(i32 %0)
%44 = icmp eq i64 %43, 0
br i1 %44, label %54, label %49
45: ; preds = %39
%46 = load i32, i32* @RB_POWER_OFF
%47 = call i64 @call_reboot(i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %54, label %49
49: ; preds = %45, %42, %36
%50 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), %36 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), %42 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0), %45 ]
%51 = load i64, i64* @errno
%52 = call i8* @strerror(i64 %51)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %50, i8* %52)
br label %54
54: ; preds = %49, %42, %45, %36
ret void
}