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

/* Variables and functions */
#define SIGHUP 130
#define SIGINT 129
#define SIGTERM 128
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *thr1_routine(void *arg) {
  int sig;
  sigset_t sset;
  for (;;) {
    sigfillset(&sset);
    sigwait(&sset, &sig);
    switch (sig) {
    case SIGHUP:
      printf("[ROUTINE] Got SIGHUP %d\n", sig);
      break;
    case SIGTERM:
      printf("[ROUTINE] Got SIGTERM %d\n", sig);
      break;
    case SIGINT:
      printf("[ROUTINE] Got SIGINT %d\n", sig);
      break;
    default:
      printf("[ROUTINE] Got signal %d\n", sig);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<thr1_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
mov    %rdi,-0x20(%rbp)
call   1040 <sigfillset@plt>
mov    -0x20(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <sigwait@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     11a6 <thr1_routine+0x76>
jmp    116c <thr1_routine+0x3c>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     11ba <thr1_routine+0x8a>
jmp    117f <thr1_routine+0x4f>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
jne    11ce <thr1_routine+0x9e>
jmp    1192 <thr1_routine+0x62>
mov    -0xc(%rbp),%esi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
jmp    11dd <thr1_routine+0xad>
mov    -0xc(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
jmp    11dd <thr1_routine+0xad>
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
jmp    11dd <thr1_routine+0xad>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    113c <thr1_routine+0xc>

x86 assembly (clang, -O2):
<thr1_routine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rsp,%r14
lea    0xecf(%rip),%r15
lea    0xee2(%rip),%r12
lea    0xea8(%rip),%r13
lea    0xeed(%rip),%rbp
jmp    117d <thr1_routine+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x81,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <sigfillset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <sigwait@plt>
mov    (%rsp),%esi
cmp    $0x80,%esi
je     11c0 <thr1_routine+0x90>
cmp    $0x81,%esi
je     1170 <thr1_routine+0x40>
cmp    $0x82,%esi
jne    11d0 <thr1_routine+0xa0>
mov    %r13,%rdi
mov    $0x82,%esi
call   1030 <printf@plt>
jmp    117d <thr1_routine+0x4d>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x80,%esi
call   1030 <printf@plt>
jmp    117d <thr1_routine+0x4d>
nop
mov    %rbp,%rdi
call   1030 <printf@plt>
jmp    117d <thr1_routine+0x4d>

LLVM IR (-O0):
@.str = [25 x i8] c"[ROUTINE] Got SIGHUP %d\0A\00"
@.str.1 = [26 x i8] c"[ROUTINE] Got SIGTERM %d\0A\00"
@.str.2 = [25 x i8] c"[ROUTINE] Got SIGINT %d\0A\00"
@.str.3 = [25 x i8] c"[ROUTINE] Got signal %d\0A\00"
define i8* @thr1_routine(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %21, %1
%6 = call i32 @sigfillset(i32* %4)
%7 = call i32 @sigwait(i32* %4, i32* %3)
%8 = load i32, i32* %3
switch i32 %8, label %18 [
i32 130, label %9
i32 128, label %12
i32 129, label %15
]
9: ; preds = %5
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %21
12: ; preds = %5
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %21
15: ; preds = %5
%16 = load i32, i32* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %21
18: ; preds = %5
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %15, %12, %9
br label %5
}

LLVM IR (-O2):
@.str = [25 x i8] c"[ROUTINE] Got SIGHUP %d\0A\00"
@.str.1 = [26 x i8] c"[ROUTINE] Got SIGTERM %d\0A\00"
@.str.2 = [25 x i8] c"[ROUTINE] Got SIGINT %d\0A\00"
@.str.3 = [25 x i8] c"[ROUTINE] Got signal %d\0A\00"
define noalias i8* @thr1_routine(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
br label %6
6: ; preds = %18, %1
%7 = call i32 @sigfillset(i32* %3)
%8 = call i32 @sigwait(i32* %3, i32* %2)
%9 = load i32, i32* %2
switch i32 %9, label %16 [
i32 130, label %10
i32 128, label %12
i32 129, label %14
]
10: ; preds = %6
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 130)
br label %18
12: ; preds = %6
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 128)
br label %18
14: ; preds = %6
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 129)
br label %18
16: ; preds = %6
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %16, %14, %12, %10
br label %6
}