#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 /*<<< orphan*/ RB_POWER_OFF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ reboot(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void signal_handler(int sig) {
  fprintf(stderr, "\nSignal received: %d...\n", sig);
  switch (sig) {
  case 12:
    fprintf(stderr, "Powering off...\n");
    reboot(RB_POWER_OFF);
    break;
  };
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xec2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
sub    $0xc,%eax
jne    117b <signal_handler+0x5b>
jmp    1156 <signal_handler+0x36>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1040 <reboot@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eab(%rip),%r14
mov    (%r14),%edi
lea    0xec9(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0xc,%ebx
jne    116b <signal_handler+0x4b>
mov    (%r14),%edi
lea    0xeca(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <reboot@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"\0ASignal received: %d...\0A\00"
@.str.1 = [17 x i8] c"Powering off...\0A\00"
@RB_POWER_OFF = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @stderr
%4 = load i32, i32* %2
%5 = call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %2
switch i32 %6, label %12 [
i32 12, label %7
]
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @RB_POWER_OFF
%11 = call i32 @reboot(i32 %10)
br label %12
12: ; preds = %1, %7
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"\0ASignal received: %d...\0A\00"
@.str.1 = [17 x i8] c"Powering off...\0A\00"
@RB_POWER_OFF = global i32 0
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp eq i32 %0, 12
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @RB_POWER_OFF
%9 = tail call i32 @reboot(i32 %8)
br label %10
10: ; preds = %1, %5
ret void
}