#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;
typedef int /*<<< orphan*/ pthread_t;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                   void *(*)(void *), void *);
int /*<<< orphan*/ pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int lwt_thread_create(pthread_t *th, const pthread_attr_t *attr,
                      void *(*fn)(void *), void *arg) {
  sigset_t oldset;
  sigset_t newset;
  int res;
  sigemptyset(&newset);
  sigaddset(&newset, SIGTERM);
  sigaddset(&newset, SIGINT);
  sigaddset(&newset, SIGHUP);
  sigaddset(&newset, SIGQUIT);
  pthread_sigmask(SIG_BLOCK, &newset, &oldset);
  res = pthread_create(th, attr, fn, arg);
  pthread_sigmask(SIG_SETMASK, &oldset, NULL);
  return res;
}


x86 assembly (clang, -O0):
<lwt_thread_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <sigemptyset@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <pthread_sigmask@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <pthread_create@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <pthread_sigmask@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwt_thread_create>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <sigemptyset@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rbp
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <pthread_sigmask@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <pthread_create@plt>
mov    %eax,%ebx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1040 <pthread_sigmask@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGTERM = global i32 0
@SIGINT = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @lwt_thread_create(i32* %0, i32* %1, i8* (i8*)* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8* (i8*)*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* (i8*)* %2, i8* (i8*)** %7
store i8* %3, i8** %8
%12 = call i32 @sigemptyset(i32* %10)
%13 = load i32, i32* @SIGTERM
%14 = call i32 @sigaddset(i32* %10, i32 %13)
%15 = load i32, i32* @SIGINT
%16 = call i32 @sigaddset(i32* %10, i32 %15)
%17 = load i32, i32* @SIGHUP
%18 = call i32 @sigaddset(i32* %10, i32 %17)
%19 = load i32, i32* @SIGQUIT
%20 = call i32 @sigaddset(i32* %10, i32 %19)
%21 = load i32, i32* @SIG_BLOCK
%22 = call i32 @pthread_sigmask(i32 %21, i32* %10, i32* %9)
%23 = load i32*, i32** %5
%24 = load i32*, i32** %6
%25 = load i8* (i8*)*, i8* (i8*)** %7
%26 = load i8*, i8** %8
%27 = call i32 @pthread_create(i32* %23, i32* %24, i8* (i8*)* %25, i8* %26)
store i32 %27, i32* %11
%28 = load i32, i32* @SIG_SETMASK
%29 = call i32 @pthread_sigmask(i32 %28, i32* %9, i32* null)
%30 = load i32, i32* %11
ret i32 %30
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIGINT = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @lwt_thread_create(i32* %0, i32* %1, i8* (i8*)* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @sigemptyset(i32* %6)
%10 = load i32, i32* @SIGTERM
%11 = call i32 @sigaddset(i32* %6, i32 %10)
%12 = load i32, i32* @SIGINT
%13 = call i32 @sigaddset(i32* %6, i32 %12)
%14 = load i32, i32* @SIGHUP
%15 = call i32 @sigaddset(i32* %6, i32 %14)
%16 = load i32, i32* @SIGQUIT
%17 = call i32 @sigaddset(i32* %6, i32 %16)
%18 = load i32, i32* @SIG_BLOCK
%19 = call i32 @pthread_sigmask(i32 %18, i32* %6, i32* %5)
%20 = call i32 @pthread_create(i32* %0, i32* %1, i8* (i8*)* %2, i8* %3)
%21 = load i32, i32* @SIG_SETMASK
%22 = call i32 @pthread_sigmask(i32 %21, i32* %5, i32* null)
ret i32 %20
}