#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*/ LINUX_REBOOT_CMD_RESTART;
int SIGINT;
void SIG_IGN(int);
int /*<<< orphan*/ call_reboot(int /*<<< orphan*/);
int /*<<< orphan*/ debug(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ signal(int, void (*)(int));
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void sighandler(int sig) {
  signal(sig, SIG_IGN);
  if (sig == SIGINT) {
    debug("Caught SIGINT, rebooting");
    call_reboot(LINUX_REBOOT_CMD_RESTART);
    debug("Reboot failed: %s", strerror(errno));
  }
  signal(sig, &sighandler);
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e83(%rip),%rsi
call   1040 <signal@plt>
mov    -0x4(%rbp),%eax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%eax
jne    11a6 <sighandler+0x66>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <debug@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <call_reboot@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <debug@plt>
mov    -0x4(%rbp),%edi
mov    0x2e38(%rip),%rsi
call   1040 <signal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rbx
mov    %edi,%ebx
mov    0x2e8e(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e8a(%rip),%rax
cmp    %ebx,(%rax)
jne    1194 <sighandler+0x54>
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1030 <debug@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1050 <call_reboot@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <debug@plt>
mov    0x2e4d(%rip),%rsi
mov    %ebx,%edi
pop    %rbx
jmp    1040 <signal@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [25 x i8] c"Caught SIGINT, rebooting\00"
@LINUX_REBOOT_CMD_RESTART = global i32 0
@.str.1 = [18 x i8] c"Reboot failed: %s\00"
@errno = global i32 0
define void @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @signal(i32 %3, void (i32)* @SIG_IGN)
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGINT
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%11 = call i32 @call_reboot(i32 %10)
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %8, %1
%16 = load i32, i32* %2
%17 = call i32 @signal(i32 %16, void (i32)* @sighandler)
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [25 x i8] c"Caught SIGINT, rebooting\00"
@LINUX_REBOOT_CMD_RESTART = global i32 0
@.str.1 = [18 x i8] c"Reboot failed: %s\00"
@errno = global i32 0
define void @sighandler(i32 %0) {
%2 = tail call i32 @signal(i32 %0, void (i32)* @SIG_IGN)
%3 = load i32, i32* @SIGINT
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @LINUX_REBOOT_CMD_RESTART
%8 = tail call i32 @call_reboot(i32 %7)
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 (i8*, ...) @debug(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %5, %1
%13 = tail call i32 @signal(i32 %0, void (i32)* @sighandler)
ret void
}