#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 SIGINT;
int SIGTERM;
int /*<<< orphan*/ close_fd();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void sig_handler(int signo) {
  if (signo == SIGINT)
    fprintf(stderr, "received SIGINT\n");
  else if (signo == SIGTERM)
    fprintf(stderr, "received SIGTERM\n");
  else
    fprintf(stderr, "received signo=%d\n", signo);
  close_fd();
  exit(signo);
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%eax
jne    1169 <sig_handler+0x39>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b6 <sig_handler+0x86>
mov    -0x4(%rbp),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
jne    1197 <sig_handler+0x67>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b1 <sig_handler+0x81>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b6 <sig_handler+0x86>
mov    $0x0,%al
call   1030 <close_fd@plt>
mov    -0x4(%rbp),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<sig_handler>:
push   %rbx
mov    %edi,%ebx
mov    0x2eae(%rip),%rax
cmp    %edi,(%rax)
jne    1150 <sig_handler+0x20>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
jmp    116b <sig_handler+0x3b>
mov    0x2e89(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%edi
cmp    %ebx,(%rax)
jne    1174 <sig_handler+0x44>
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1184 <sig_handler+0x54>
lea    0xea8(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <close_fd@plt>
mov    %ebx,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"received SIGINT\0A\00"
@SIGTERM = global i32 0
@.str.1 = [18 x i8] c"received SIGTERM\0A\00"
@.str.2 = [19 x i8] c"received signo=%d\0A\00"
define void @sig_handler(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 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %21
9: ; preds = %1
%10 = load i32, i32* %2
%11 = load i32, i32* @SIGTERM
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = load i32, i32* %2
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %13
br label %21
21: ; preds = %20, %6
%22 = call i32 (...) @close_fd()
%23 = load i32, i32* %2
%24 = call i32 @exit(i32 %23)
unreachable
}

LLVM IR (-O2):
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"received SIGINT\0A\00"
@SIGTERM = global i32 0
@.str.1 = [18 x i8] c"received SIGTERM\0A\00"
@.str.2 = [19 x i8] c"received signo=%d\0A\00"
define void @sig_handler(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = load i32, i32* @SIGTERM
%9 = icmp eq i32 %8, %0
%10 = load i32, i32* @stderr
br i1 %9, label %11, label %13
11: ; preds = %7
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %15
13: ; preds = %7
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %15
15: ; preds = %11, %13, %4
%16 = tail call i32 (...) @close_fd()
%17 = tail call i32 @exit(i32 %0)
unreachable
}