#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 SIGALRM;
scalar_t__ alarm(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void sigalrm_handler(int signum) {
  if (signum != SIGALRM) {
    fprintf(stderr, "Internal error: Called for signum %d, not SIGALRM\n",
            signum);
    exit(1);
  }
  printf("ALARM! %d seconds have passed.\n", 2);
  if (alarm(2) < 0) {
    perror("alarm");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<sigalrm_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%eax
je     118f <sigalrm_handler+0x3f>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe9d(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <alarm@plt>
cmp    $0x0,%rax
jge    11ca <sigalrm_handler+0x7a>
lea    0xe98(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigalrm_handler>:
push   %rax
mov    0x2e90(%rip),%rax
cmp    %edi,(%rax)
jne    117e <sigalrm_handler+0x2e>
lea    0xed0(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <alarm@plt>
test   %rax,%rax
js     119f <sigalrm_handler+0x4f>
pop    %rax
ret
mov    %edi,%edx
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xead(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGALRM = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"Internal error: Called for signum %d, not SIGALRM\0A\00"
@.str.1 = [32 x i8] c"ALARM! %d seconds have passed.\0A\00"
@.str.2 = [6 x i8] c"alarm\00"
define void @sigalrm_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGALRM
%5 = icmp ne i32 %3, %4
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* %2
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 2)
%13 = call i64 @alarm(i32 2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
ret void
}

LLVM IR (-O2):
@SIGALRM = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"Internal error: Called for signum %d, not SIGALRM\0A\00"
@.str.1 = [32 x i8] c"ALARM! %d seconds have passed.\0A\00"
@.str.2 = [6 x i8] c"alarm\00"
define void @sigalrm_handler(i32 %0) {
%2 = load i32, i32* @SIGALRM
%3 = icmp eq i32 %2, %0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = tail call i64 @alarm(i32 2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
ret void
}