#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 */
int /*<<< orphan*/ PTHREAD_CANCEL_ASYNCHRONOUS;
int SIGSEGV;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ pthread_setcanceltype(int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ signal_management_handler(int);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sigwait(int /*<<< orphan*/ *, int *);
void *signal_management_thread(void *PTR) {
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
  sigset_t blocked;
  sigprocmask(SIG_SETMASK, 0, &blocked);
  int s;
  sigwait(&blocked, &s);
  if (s != SIGSEGV) {
    sigprocmask(SIG_UNBLOCK, &blocked, 0);
  }
  signal_management_handler(s);
  return NULL;
}


x86 assembly (clang, -O0):
<signal_management_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <pthread_setcanceltype@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1030 <sigprocmask@plt>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <sigwait@plt>
mov    -0x10(%rbp),%eax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%eax
je     11a7 <signal_management_thread+0x67>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x10(%rbp),%edi
call   1040 <signal_management_handler@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_management_thread>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <pthread_setcanceltype@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <sigwait@plt>
mov    0x8(%rsp),%edi
mov    0x2e5b(%rip),%rax
cmp    (%rax),%edi
je     11a2 <signal_management_thread+0x62>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    0x8(%rsp),%edi
call   1040 <signal_management_handler@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
@SIG_SETMASK = global i32 0
@SIGSEGV = global i32 0
@SIG_UNBLOCK = global i32 0
define i8* @signal_management_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%6 = call i32 @pthread_setcanceltype(i32 %5, i32 0)
%7 = load i32, i32* @SIG_SETMASK
%8 = call i32 @sigprocmask(i32 %7, i32* null, i32* %3)
%9 = call i32 @sigwait(i32* %3, i32* %4)
%10 = load i32, i32* %4
%11 = load i32, i32* @SIGSEGV
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @SIG_UNBLOCK
%15 = call i32 @sigprocmask(i32 %14, i32* %3, i32* null)
br label %16
16: ; preds = %13, %1
%17 = load i32, i32* %4
%18 = call i32 @signal_management_handler(i32 %17)
ret i8* null
}

LLVM IR (-O2):
@PTHREAD_CANCEL_ASYNCHRONOUS = global i32 0
@SIG_SETMASK = global i32 0
@SIGSEGV = global i32 0
@SIG_UNBLOCK = global i32 0
define noalias i8* @signal_management_thread(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @PTHREAD_CANCEL_ASYNCHRONOUS
%5 = tail call i32 @pthread_setcanceltype(i32 %4, i32 0)
%6 = bitcast i32* %2 to i8*
%7 = load i32, i32* @SIG_SETMASK
%8 = call i32 @sigprocmask(i32 %7, i32* null, i32* %2)
%9 = bitcast i32* %3 to i8*
%10 = call i32 @sigwait(i32* %2, i32* %3)
%11 = load i32, i32* %3
%12 = load i32, i32* @SIGSEGV
%13 = icmp eq i32 %11, %12
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i32, i32* @SIG_UNBLOCK
%16 = call i32 @sigprocmask(i32 %15, i32* %2, i32* null)
%17 = load i32, i32* %3
br label %18
18: ; preds = %14, %1
%19 = phi i32 [ %17, %14 ], [ %11, %1 ]
%20 = call i32 @signal_management_handler(i32 %19)
ret i8* null
}