#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_perm_wrapper(int);
void sig_handler(int signo) {
  if (signo == SIGTERM)
    printf("received SIGSTERM\n");
  else if (signo == SIGINT)
    printf("\nreceived SIGINT\n");
  set_perm_wrapper(1 << 1);
  exit(0);
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    115e <sig_handler+0x2e>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
jmp    1181 <sig_handler+0x51>
mov    -0x4(%rbp),%eax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
jne    117c <sig_handler+0x4c>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
jmp    1181 <sig_handler+0x51>
mov    $0x2,%edi
call   1030 <set_perm_wrapper@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<sig_handler>:
push   %rax
mov    0x2ea8(%rip),%rax
cmp    %edi,(%rax)
jne    1145 <sig_handler+0x15>
lea    0xece(%rip),%rdi
jmp    1157 <sig_handler+0x27>
mov    0x2e9c(%rip),%rax
cmp    %edi,(%rax)
jne    115c <sig_handler+0x2c>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1040 <set_perm_wrapper@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGTERM = global i32 0
@.str = [19 x i8] c"received SIGSTERM\0A\00"
@SIGINT = global i32 0
@.str.1 = [18 x i8] c"\0Areceived SIGINT\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* @SIGTERM
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %15
8: ; preds = %1
%9 = load i32, i32* %2
%10 = load i32, i32* @SIGINT
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
br label %15
15: ; preds = %14, %6
%16 = call i32 @set_perm_wrapper(i32 2)
%17 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIGINT = global i32 0
@str = [17 x i8] c"\0Areceived SIGINT\00"
@str.2 = [18 x i8] c"received SIGSTERM\00"
define void @sig_handler(i32 %0) {
%2 = load i32, i32* @SIGTERM
%3 = icmp eq i32 %2, %0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @SIGINT
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %10
7: ; preds = %4, %1
%8 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0), %4 ]
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
br label %10
10: ; preds = %7, %4
%11 = tail call i32 @set_perm_wrapper(i32 2)
%12 = tail call i32 @exit(i32 0)
unreachable
}