#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 */
typedef int /*<<< orphan*/ ucontext_t;

/* Variables and functions */
int SIGALRM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void sig_handler(int signal, int code, ucontext_t *ut) {
  if (signal == SIGALRM) {
    fprintf(stdout, "Test ended, success\n");
    exit(0);
  }
  fprintf(stderr, "caught signal %d -- exiting.\n", signal);
  exit(-1);
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eac(%rip),%rcx
cmp    (%rcx),%eax
jne    1162 <sig_handler+0x42>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<sig_handler>:
push   %rax
mov    0x2ec0(%rip),%rax
cmp    %edi,(%rax)
jne    114a <sig_handler+0x2a>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
mov    %edi,%edx
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@SIGALRM = global i32 0
@stdout = global i32 0
@.str = [21 x i8] c"Test ended, success\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"caught signal %d -- exiting.\0A\00"
define void @sig_handler(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %4
%8 = load i32, i32* @SIGALRM
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @stdout
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@SIGALRM = global i32 0
@stdout = global i32 0
@.str = [21 x i8] c"Test ended, success\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"caught signal %d -- exiting.\0A\00"
define void @sig_handler(i32 %0, i32 %1, i32* nocapture readnone %2) {
%4 = load i32, i32* @SIGALRM
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stdout
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%13 = tail call i32 @exit(i32 -1)
unreachable
}