#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*/ pid_t;

/* Variables and functions */
int LOG_DAEMON;
int LOG_ERR;
int LOG_NOTICE;
#define SIGINT 129
int /*<<< orphan*/ SIGKILL;
#define SIGTERM 128
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int, char *, ...);
void doExit(int signum) {
  pid_t pid = getpid();
  syslog(LOG_DAEMON | LOG_NOTICE, "caught signal %d in process %d\n", signum,
         pid);
  switch (signum) {
  case SIGTERM:
  case SIGINT:
    syslog(LOG_DAEMON | LOG_NOTICE, "Exiting ADC daemon\n");
    closelog();
    kill(pid, SIGKILL);
    break;
  default:
    syslog(LOG_DAEMON | LOG_ERR, "unexpected signal received\n");
  }
}


x86 assembly (clang, -O0):
<doExit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %al,-0x9(%rbp)
call   1040 <getpid@plt>
mov    %eax,%ecx
mov    -0x9(%rbp),%al
mov    %ecx,-0x8(%rbp)
mov    0x2e84(%rip),%rcx
mov    (%rcx),%edi
mov    0x2e63(%rip),%rcx
mov    (%rcx),%ecx
or     %ecx,%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe82(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     11d4 <doExit+0x94>
jmp    1197 <doExit+0x57>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
or     (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
mov    -0x8(%rbp),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
jmp    11f4 <doExit+0xb4>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%rip),%rax
or     (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doExit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
mov    0x2e8f(%rip),%r15
mov    0x2e70(%rip),%r14
mov    (%r14),%edi
or     (%r15),%edi
lea    0xe93(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <syslog@plt>
and    $0xfffffffe,%ebp
mov    (%r15),%edi
cmp    $0x80,%ebp
jne    11b8 <doExit+0x78>
or     (%r14),%edi
lea    0xe90(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <kill@plt>
mov    0x2e01(%rip),%rax
or     (%rax),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <syslog@plt>

LLVM IR (-O0):
@LOG_DAEMON = global i32 0
@LOG_NOTICE = global i32 0
@.str = [32 x i8] c"caught signal %d in process %d\0A\00"
@.str.1 = [20 x i8] c"Exiting ADC daemon\0A\00"
@SIGKILL = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [28 x i8] c"unexpected signal received\0A\00"
define void @doExit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @getpid()
store i32 %4, i32* %3
%5 = load i32, i32* @LOG_DAEMON
%6 = load i32, i32* @LOG_NOTICE
%7 = or i32 %5, %6
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = call i32 (i32, i8*, ...) @syslog(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %2
switch i32 %11, label %21 [
i32 128, label %12
i32 129, label %12
]
12: ; preds = %1, %1
%13 = load i32, i32* @LOG_DAEMON
%14 = load i32, i32* @LOG_NOTICE
%15 = or i32 %13, %14
%16 = call i32 (i32, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @closelog()
%18 = load i32, i32* %3
%19 = load i32, i32* @SIGKILL
%20 = call i32 @kill(i32 %18, i32 %19)
br label %26
21: ; preds = %1
%22 = load i32, i32* @LOG_DAEMON
%23 = load i32, i32* @LOG_ERR
%24 = or i32 %22, %23
%25 = call i32 (i32, i8*, ...) @syslog(i32 %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %21, %12
ret void
}

LLVM IR (-O2):
@LOG_DAEMON = global i32 0
@LOG_NOTICE = global i32 0
@.str = [32 x i8] c"caught signal %d in process %d\0A\00"
@.str.1 = [20 x i8] c"Exiting ADC daemon\0A\00"
@SIGKILL = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [28 x i8] c"unexpected signal received\0A\00"
define void @doExit(i32 %0) {
%2 = tail call i32 (...) @getpid()
%3 = load i32, i32* @LOG_DAEMON
%4 = load i32, i32* @LOG_NOTICE
%5 = or i32 %4, %3
%6 = tail call i32 (i32, i8*, ...) @syslog(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2)
%7 = and i32 %0, -2
%8 = icmp eq i32 %7, 128
%9 = load i32, i32* @LOG_DAEMON
br i1 %8, label %10, label %17
10: ; preds = %1
%11 = load i32, i32* @LOG_NOTICE
%12 = or i32 %11, %9
%13 = tail call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 (...) @closelog()
%15 = load i32, i32* @SIGKILL
%16 = tail call i32 @kill(i32 %2, i32 %15)
br label %21
17: ; preds = %1
%18 = load i32, i32* @LOG_ERR
%19 = or i32 %18, %9
%20 = tail call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %17, %10
ret void
}