#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 */
struct sigaction {
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int NSIG;
int SIGKILL;
int SIGSTOP;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ sigaction(int, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
void ClearSignalMask() {
  sigset_t sset;
  sigemptyset(&sset);
  sigprocmask(SIG_SETMASK, &sset, NULL);
  for (int i = 1; i < NSIG; ++i) {
    if (i == SIGKILL || i == SIGSTOP)
      continue;
    struct sigaction sa = {};
    sa.sa_handler = SIG_DFL;
    sigemptyset(&sa.sa_mask);
    sigaction(i, &sa, NULL);
  }
}


x86 assembly (clang, -O0):
<ClearSignalMask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
jge    11ec <ClearSignalMask+0xac>
mov    -0x8(%rbp),%eax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%eax
je     11a4 <ClearSignalMask+0x64>
mov    -0x8(%rbp),%eax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%eax
jne    11a9 <ClearSignalMask+0x69>
jmp    11de <ClearSignalMask+0x9e>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigaction@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <ClearSignalMask+0x2e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ClearSignalMask>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    0x2e5b(%rip),%r15
mov    (%r15),%eax
cmp    $0x2,%eax
jl     11e0 <ClearSignalMask+0xb0>
mov    0x2e5c(%rip),%r12
mov    (%r12),%ecx
mov    0x2e49(%rip),%r13
mov    0x0(%r13),%edx
mov    $0x1,%ebx
mov    0x2e49(%rip),%rbp
lea    0x8(%rsp),%r14
jmp    11a7 <ClearSignalMask+0x77>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %eax,%ebx
jge    11e0 <ClearSignalMask+0xb0>
cmp    %ecx,%ebx
je     11a0 <ClearSignalMask+0x70>
cmp    %edx,%ebx
je     11a0 <ClearSignalMask+0x70>
movq   $0x0,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
call   1050 <sigemptyset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sigaction@plt>
mov    (%r12),%ecx
mov    0x0(%r13),%edx
mov    (%r15),%eax
jmp    11a0 <ClearSignalMask+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32, i32 }
@SIG_SETMASK = global i32 0
@NSIG = global i32 0
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_DFL = global i32 0
define void @ClearSignalMask() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = call i32 @sigemptyset(i32* %1)
%5 = load i32, i32* @SIG_SETMASK
%6 = call i32 @sigprocmask(i32 %5, i32* %1, i32* null)
store i32 1, i32* %2
br label %7
7: ; preds = %28, %0
%8 = load i32, i32* %2
%9 = load i32, i32* @NSIG
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* @SIGKILL
%14 = icmp eq i32 %12, %13
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = load i32, i32* @SIGSTOP
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %11
br label %28
20: ; preds = %15
%21 = bitcast %struct.sigaction* %3 to i8*
%22 = load i32, i32* @SIG_DFL
%23 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
%25 = call i32 @sigemptyset(i32* %24)
%26 = load i32, i32* %2
%27 = call i32 @sigaction(i32 %26, %struct.sigaction* %3, i32* null)
br label %28
28: ; preds = %20, %19
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %7
31: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { i32, i32 }
@SIG_SETMASK = global i32 0
@NSIG = global i32 0
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_DFL = global i32 0
define void @ClearSignalMask() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.sigaction*
%4 = bitcast i32* %1 to i8*
%5 = call i32 @sigemptyset(i32* %1)
%6 = load i32, i32* @SIG_SETMASK
%7 = call i32 @sigprocmask(i32 %6, i32* %1, i32* null)
%8 = load i32, i32* @NSIG
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = bitcast i64* %2 to i8*
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%13 = bitcast i64* %2 to i32*
%14 = load i32, i32* @SIGKILL
%15 = load i32, i32* @SIGSTOP
br label %17
16: ; preds = %32, %0
ret void
17: ; preds = %10, %32
%18 = phi i32 [ %8, %10 ], [ %33, %32 ]
%19 = phi i32 [ %15, %10 ], [ %34, %32 ]
%20 = phi i32 [ %14, %10 ], [ %35, %32 ]
%21 = phi i32 [ 1, %10 ], [ %36, %32 ]
%22 = icmp eq i32 %21, %20
%23 = icmp eq i32 %21, %19
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %32, label %25
25: ; preds = %17
store i64 0, i64* %2
%26 = load i32, i32* @SIG_DFL
store i32 %26, i32* %12
%27 = call i32 @sigemptyset(i32* %13)
%28 = call i32 @sigaction(i32 %21, %struct.sigaction* %3, i32* null)
%29 = load i32, i32* @SIGKILL
%30 = load i32, i32* @SIGSTOP
%31 = load i32, i32* @NSIG
br label %32
32: ; preds = %17, %25
%33 = phi i32 [ %18, %17 ], [ %31, %25 ]
%34 = phi i32 [ %19, %17 ], [ %30, %25 ]
%35 = phi i32 [ %20, %17 ], [ %29, %25 ]
%36 = add nuw nsw i32 %21, 1
%37 = icmp slt i32 %36, %33
br i1 %37, label %17, label %16
}