#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 */
unsigned int RB_AUTOBOOT;
unsigned int RB_HALT_SYSTEM;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ errno;
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int request_shutdown(unsigned int rb_action) {
  if (rb_action == RB_AUTOBOOT) {
    if (kill(1, SIGUSR2) == 0) {
      return 0;
    }
  } else if (rb_action == RB_HALT_SYSTEM) {
    if (kill(1, SIGUSR1) == 0) {
      return 0;
    }
  } else {
    if (kill(1, SIGHUP) == 0) {
      return 0;
    }
  }
  printf("shutdown request failed, kill: %s\n", strerror(errno));
  return -1;
}


x86 assembly (clang, -O0):
<request_shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
jne    117b <request_shutdown+0x4b>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
call   1040 <kill@plt>
cmp    $0x0,%rax
jne    1176 <request_shutdown+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1212 <request_shutdown+0xe2>
jmp    11ee <request_shutdown+0xbe>
mov    -0x8(%rbp),%eax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
jne    11bb <request_shutdown+0x8b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
call   1040 <kill@plt>
cmp    $0x0,%rax
jne    11b6 <request_shutdown+0x86>
movl   $0x0,-0x4(%rbp)
jmp    1212 <request_shutdown+0xe2>
jmp    11e9 <request_shutdown+0xb9>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
call   1040 <kill@plt>
cmp    $0x0,%rax
jne    11e4 <request_shutdown+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    1212 <request_shutdown+0xe2>
jmp    11e9 <request_shutdown+0xb9>
jmp    11ee <request_shutdown+0xbe>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xdfa(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<request_shutdown>:
push   %rax
mov    0x2e80(%rip),%rax
cmp    %edi,(%rax)
jne    1145 <request_shutdown+0x15>
mov    0x2e8d(%rip),%rax
jmp    1160 <request_shutdown+0x30>
mov    0x2e74(%rip),%rax
cmp    %edi,(%rax)
jne    1159 <request_shutdown+0x29>
mov    0x2e89(%rip),%rax
jmp    1160 <request_shutdown+0x30>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
call   1040 <kill@plt>
test   %rax,%rax
je     1195 <request_shutdown+0x65>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@RB_AUTOBOOT = global i32 0
@SIGUSR2 = global i32 0
@RB_HALT_SYSTEM = global i32 0
@SIGUSR1 = global i32 0
@SIGHUP = global i32 0
@.str = [35 x i8] c"shutdown request failed, kill: %s\0A\00"
@errno = global i32 0
define i32 @request_shutdown(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @RB_AUTOBOOT
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @SIGUSR2
%9 = call i64 @kill(i32 1, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 0, i32* %2
br label %34
12: ; preds = %7
br label %30
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @RB_HALT_SYSTEM
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @SIGUSR1
%19 = call i64 @kill(i32 1, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %2
br label %34
22: ; preds = %17
br label %29
23: ; preds = %13
%24 = load i32, i32* @SIGHUP
%25 = call i64 @kill(i32 1, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 0, i32* %2
br label %34
28: ; preds = %23
br label %29
29: ; preds = %28, %22
br label %30
30: ; preds = %29, %12
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 -1, i32* %2
br label %34
34: ; preds = %30, %27, %21, %11
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@RB_AUTOBOOT = global i32 0
@SIGUSR2 = global i32 0
@RB_HALT_SYSTEM = global i32 0
@SIGUSR1 = global i32 0
@SIGHUP = global i32 0
@.str = [35 x i8] c"shutdown request failed, kill: %s\0A\00"
@errno = global i32 0
define i32 @request_shutdown(i32 %0) {
%2 = load i32, i32* @RB_AUTOBOOT
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @SIGUSR2
%6 = tail call i64 @kill(i32 1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %23, label %19
8: ; preds = %1
%9 = load i32, i32* @RB_HALT_SYSTEM
%10 = icmp eq i32 %9, %0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @SIGUSR1
%13 = tail call i64 @kill(i32 1, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %19
15: ; preds = %8
%16 = load i32, i32* @SIGHUP
%17 = tail call i64 @kill(i32 1, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %11, %15, %4
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %15, %11, %4, %19
%24 = phi i32 [ -1, %19 ], [ 0, %4 ], [ 0, %11 ], [ 0, %15 ]
ret i32 %24
}