#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;
int SIGINT;
int /*<<< orphan*/ alarm(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
void catch_sig(int signo) {
  if (signo == SIGINT) {
    alarm(0);
    write(1, "CAUGTH SIGINT!\n", 15);
  } else if (signo == SIGALRM) {
    write(1, "CAUGHT SIGALRM.\n", 16);
  }
}


x86 assembly (clang, -O0):
<catch_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eab(%rip),%rcx
cmp    (%rcx),%eax
jne    115f <catch_sig+0x3f>
xor    %edi,%edi
call   1040 <alarm@plt>
mov    $0x1,%edi
lea    0xeb0(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
jmp    118c <catch_sig+0x6c>
mov    -0x4(%rbp),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
jne    1187 <catch_sig+0x67>
mov    $0x1,%edi
lea    0xe93(%rip),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
jmp    118c <catch_sig+0x6c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catch_sig>:
push   %rax
mov    0x2eb8(%rip),%rax
cmp    %edi,(%rax)
jne    114a <catch_sig+0x2a>
xor    %edi,%edi
call   1040 <alarm@plt>
lea    0xec6(%rip),%rsi
mov    $0x1,%edi
mov    $0xf,%edx
pop    %rax
jmp    1030 <write@plt>
mov    0x2e97(%rip),%rax
cmp    %edi,(%rax)
jne    116c <catch_sig+0x4c>
lea    0xeb4(%rip),%rsi
mov    $0x1,%edi
mov    $0x10,%edx
pop    %rax
jmp    1030 <write@plt>
pop    %rax
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [16 x i8] c"CAUGTH SIGINT!\0A\00"
@SIGALRM = global i32 0
@.str.1 = [17 x i8] c"CAUGHT SIGALRM.\0A\00"
define void @catch_sig(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGINT
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @alarm(i32 0)
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 15)
br label %16
9: ; preds = %1
%10 = load i32, i32* %2
%11 = load i32, i32* @SIGALRM
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @write(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 16)
br label %15
15: ; preds = %13, %9
br label %16
16: ; preds = %15, %6
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [16 x i8] c"CAUGTH SIGINT!\0A\00"
@SIGALRM = global i32 0
@.str.1 = [17 x i8] c"CAUGHT SIGALRM.\0A\00"
define void @catch_sig(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @alarm(i32 0)
%6 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 15)
br label %12
7: ; preds = %1
%8 = load i32, i32* @SIGALRM
%9 = icmp eq i32 %8, %0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 16)
br label %12
12: ; preds = %7, %10, %4
ret void
}