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

/* Variables and functions */
unsigned int NSIG;
int /*<<< orphan*/ SIG_SETMASK;
scalar_t__ __sigaddset(int /*<<< orphan*/ *, unsigned int);
scalar_t__ __sigemptyset(int /*<<< orphan*/ *);
scalar_t__ __sigismember(int /*<<< orphan*/ *, unsigned int);
int sigmask(unsigned int);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int sigsetmask(int mask) {
  register unsigned 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 & sigmask(sig)) && __sigaddset(&set, sig) < 0)
        return -1;
  if (sigprocmask(SIG_SETMASK, &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 |= sigmask(sig);
  return mask;
}


x86 assembly (clang, -O0):
<sigsetmask>:
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 <sigsetmask+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <sigsetmask+0x68>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    117c <sigsetmask+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <sigsetmask+0x68>
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):
<sigsetmask>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
call   1040 <__sigemptyset@plt>
test   %rax,%rax
js     1165 <sigsetmask+0x45>
mov    %ebx,0x8(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1030 <sigprocmask@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     116a <sigsetmask+0x4a>
mov    0xc(%rsp),%eax
jmp    116a <sigsetmask+0x4a>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
@NSIG = global i32 0
define i32 @sigsetmask(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 %19
10: ; preds = %1
%11 = load i32, i32* %3
store i32 %11, i32* %5
%12 = load i32, i32* @SIG_SETMASK
%13 = call i64 @sigprocmask(i32 %12, i32* %5, i32* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %2
br label %19
16: ; preds = %10
%17 = load i32, i32* %6
store i32 %17, i32* %3
%18 = load i32, i32* %3
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %15, %9
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
@NSIG = global i32 0
define i32 @sigsetmask(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 %14, label %8
8: ; preds = %1
store i32 %0, i32* %2
%9 = load i32, i32* @SIG_SETMASK
%10 = call i64 @sigprocmask(i32 %9, i32* %2, i32* %3)
%11 = icmp slt i64 %10, 0
%12 = load i32, i32* %3
%13 = select i1 %11, i32 -1, i32 %12
br label %14
14: ; preds = %8, %1
%15 = phi i32 [ -1, %1 ], [ %13, %8 ]
ret i32 %15
}