#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 */
#define SIGHUP 131
#define SIGINT 130
#define SIGPIPE 129
#define SIGTERM 128
int /*<<< orphan*/ db_close();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ zprintf(int, char *);
void signal_handler(int sig) {
  int rc;
  switch (sig) {
  case SIGHUP:
    zprintf(4, "SIGHUP: initializing adapter...\n");
    break;
  case SIGINT:
  case SIGTERM:
    zprintf(1, "SIGTERM: exiting...");
    db_close();
    exit(0);
    break;
  case SIGPIPE:
    zprintf(1, "caught SIGPIPE from main thread");
    break;
  }
  return;
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11aa <signal_handler+0x7a>
mov    -0x10(%rbp),%rax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x4,%edi
lea    0xea0(%rip),%rsi
call   1040 <zprintf@plt>
jmp    11aa <signal_handler+0x7a>
mov    $0x1,%edi
lea    0xeab(%rip),%rsi
call   1040 <zprintf@plt>
mov    $0x0,%al
call   1030 <db_close@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    $0x1,%edi
lea    0xea0(%rip),%rsi
call   1040 <zprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
add    $0xffffff80,%edi
cmp    $0x3,%edi
ja     116d <signal_handler+0x3d>
lea    0xec0(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xef5(%rip),%rsi
mov    $0x1,%edi
pop    %rax
jmp    1040 <zprintf@plt>
lea    0xeae(%rip),%rsi
mov    $0x4,%edi
pop    %rax
jmp    1040 <zprintf@plt>
pop    %rax
ret
lea    0xebb(%rip),%rsi
mov    $0x1,%edi
call   1040 <zprintf@plt>
xor    %eax,%eax
call   1030 <db_close@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"SIGHUP: initializing adapter...\0A\00"
@.str.1 = [20 x i8] c"SIGTERM: exiting...\00"
@.str.2 = [32 x i8] c"caught SIGPIPE from main thread\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %13 [
i32 131, label %5
i32 130, label %7
i32 128, label %7
i32 129, label %11
]
5: ; preds = %1
%6 = call i32 @zprintf(i32 4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
7: ; preds = %1, %1
%8 = call i32 @zprintf(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (...) @db_close()
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %1
%12 = call i32 @zprintf(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %1, %11, %5
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"SIGHUP: initializing adapter...\0A\00"
@.str.1 = [20 x i8] c"SIGTERM: exiting...\00"
@.str.2 = [32 x i8] c"caught SIGPIPE from main thread\00"
define void @signal_handler(i32 %0) {
switch i32 %0, label %10 [
i32 131, label %2
i32 130, label %4
i32 128, label %4
i32 129, label %8
]
2: ; preds = %1
%3 = tail call i32 @zprintf(i32 4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %10
4: ; preds = %1, %1
%5 = tail call i32 @zprintf(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (...) @db_close()
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = tail call i32 @zprintf(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %1, %8, %2
ret void
}