#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 sig;
typedef int /*<<< orphan*/ set;
typedef int /*<<< orphan*/ oset;
typedef int /*<<< orphan*/ mask;

/* Variables and functions */
int NSIG;
scalar_t__ sigaddset(int /*<<< orphan*/ *, int);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int);
scalar_t__ sigprocmask(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int sigblock(int mask) {
  register int sig;
  sigset_t set, oset;
  if (sigemptyset(&set) < 0)
    return -1;
  if (sizeof(mask) == sizeof(set))
    *(int *)&set = mask;
  else if (sizeof(unsigned long int) == sizeof(set))
    *(unsigned long int *)&set = (unsigned int)mask;
  else
    for (sig = 1; sig < NSIG && sig <= sizeof(mask) * 8; ++sig)
      if ((mask & (1 << ((sig)-1))) && sigaddset(&set, sig) < 0)
        return -1;
  if (sigprocmask(2, &set, &oset) < 0)
    return -1;
  if (sizeof(mask) == sizeof(oset))
    mask = *(int *)&oset;
  else if (sizeof(unsigned long int) == sizeof(oset))
    mask = *(unsigned long int *)&oset;
  else
    for (sig = 1, mask = 0; sig < NSIG && sig <= sizeof(mask) * 8; ++sig)
      if (sigismember(&oset, sig))
        mask |= (1 << ((sig)-1));
  return mask;
}


x86 assembly (clang, -O0):
<sigblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <sigemptyset@plt>
cmp    $0x0,%rax
jge    114a <sigblock+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <sigblock+0x64>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x2,%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    1178 <sigblock+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <sigblock+0x64>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigblock>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
call   1040 <sigemptyset@plt>
test   %rax,%rax
js     1161 <sigblock+0x41>
mov    %ebx,0x8(%rsp)
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    $0x2,%edi
call   1030 <sigprocmask@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     1166 <sigblock+0x46>
mov    0xc(%rsp),%eax
jmp    1166 <sigblock+0x46>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@NSIG = global i32 0
define i32 @sigblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = call i64 @sigemptyset(i32* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %18
10: ; preds = %1
%11 = load i32, i32* %3
store i32 %11, i32* %5
%12 = call i64 @sigprocmask(i32 2, i32* %5, i32* %6)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -1, i32* %2
br label %18
15: ; preds = %10
%16 = load i32, i32* %6
store i32 %16, i32* %3
%17 = load i32, i32* %3
store i32 %17, i32* %2
br label %18
18: ; preds = %15, %14, %9
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@NSIG = global i32 0
define i32 @sigblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i64 @sigemptyset(i32* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
store i32 %0, i32* %2
%9 = call i64 @sigprocmask(i32 2, i32* %2, i32* %3)
%10 = icmp slt i64 %9, 0
%11 = load i32, i32* %3
%12 = select i1 %10, i32 -1, i32 %11
br label %13
13: ; preds = %8, %1
%14 = phi i32 [ -1, %1 ], [ %12, %8 ]
ret i32 %14
}