#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 SIGTERM;
int SIGUSR1;
int SIGUSR2;
int /*<<< orphan*/ setFlag(int);
int /*<<< orphan*/ signal(int, void (*)(int));
void signalHandler(int sig) {
  signal(sig, signalHandler);
  if (sig == SIGTERM) {
    setFlag(0);
  }
  if (sig == SIGUSR1) {
    setFlag(1);
  }
  if (sig == SIGUSR2) {
    setFlag(2);
  }
}


x86 assembly (clang, -O0):
<signalHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eab(%rip),%rsi
call   1030 <signal@plt>
mov    -0x4(%rbp),%eax
mov    0x2e94(%rip),%rcx
cmp    (%rcx),%eax
jne    1153 <signalHandler+0x33>
xor    %edi,%edi
call   1040 <setFlag@plt>
mov    -0x4(%rbp),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    116f <signalHandler+0x4f>
mov    $0x1,%edi
call   1040 <setFlag@plt>
mov    -0x4(%rbp),%eax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%eax
jne    118b <signalHandler+0x6b>
mov    $0x2,%edi
call   1040 <setFlag@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signalHandler>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rsi
call   1030 <signal@plt>
mov    0x2ea2(%rip),%rax
cmp    %ebx,(%rax)
jne    1141 <signalHandler+0x21>
xor    %edi,%edi
call   1040 <setFlag@plt>
mov    0x2ea0(%rip),%rax
cmp    %ebx,(%rax)
jne    1156 <signalHandler+0x36>
mov    $0x1,%edi
call   1040 <setFlag@plt>
mov    0x2e6b(%rip),%rax
cmp    %ebx,(%rax)
jne    116c <signalHandler+0x4c>
mov    $0x2,%edi
pop    %rbx
jmp    1040 <setFlag@plt>
pop    %rbx
ret

LLVM IR (-O0):
@SIGTERM = global i32 0
@SIGUSR1 = global i32 0
@SIGUSR2 = global i32 0
define void @signalHandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @signal(i32 %3, void (i32)* @signalHandler)
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGTERM
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @setFlag(i32 0)
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGUSR1
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @setFlag(i32 1)
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* %2
%18 = load i32, i32* @SIGUSR2
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @setFlag(i32 2)
br label %22
22: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIGUSR1 = global i32 0
@SIGUSR2 = global i32 0
define void @signalHandler(i32 %0) {
%2 = tail call i32 @signal(i32 %0, void (i32)* @signalHandler)
%3 = load i32, i32* @SIGTERM
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @setFlag(i32 0)
br label %7
7: ; preds = %5, %1
%8 = load i32, i32* @SIGUSR1
%9 = icmp eq i32 %8, %0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @setFlag(i32 1)
br label %12
12: ; preds = %10, %7
%13 = load i32, i32* @SIGUSR2
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @setFlag(i32 2)
br label %17
17: ; preds = %15, %12
ret void
}