#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*/ SIG_SETMASK;
int /*<<< orphan*/ pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void BlockSignals(int signalsListToBlock[], int len, sigset_t *sigmask) {
  sigemptyset(sigmask);
  int i;
  for (i = 0; i < len; ++i)
    sigaddset(sigmask, signalsListToBlock[i]);
  pthread_sigmask(SIG_SETMASK, sigmask, NULL);
}


x86 assembly (clang, -O0):
<BlockSignals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <sigemptyset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1181 <BlockSignals+0x51>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <sigaddset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <BlockSignals+0x23>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <pthread_sigmask@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BlockSignals>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <sigemptyset@plt>
test   %ebp,%ebp
jle    1165 <BlockSignals+0x35>
mov    %ebp,%ebp
xor    %ebx,%ebx
nop
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1050 <sigaddset@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <BlockSignals+0x20>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <pthread_sigmask@plt>

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
define void @BlockSignals(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
%9 = call i32 @sigemptyset(i32* %8)
store i32 0, i32* %7
br label %10
10: ; preds = %22, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32*, i32** %6
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @sigaddset(i32* %15, i32 %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %10
25: ; preds = %10
%26 = load i32, i32* @SIG_SETMASK
%27 = load i32*, i32** %6
%28 = call i32 @pthread_sigmask(i32 %26, i32* %27, i32* null)
ret void
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
define void @BlockSignals(i32* nocapture %0, i32 %1, i32* %2) {
%4 = tail call i32 @sigemptyset(i32* %2)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @sigaddset(i32* %2, i32 %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = load i32, i32* @SIG_SETMASK
%17 = tail call i32 @pthread_sigmask(i32 %16, i32* %2, i32* null)
ret void
}