#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*/ EINVAL;
int NSIG;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int sighold(int sig) {
  sigset_t mask;
  if ((sig <= 0) || (sig >= NSIG)) {
    errno = EINVAL;
    return (-1);
  }
  sigemptyset(&mask);
  sigaddset(&mask, sig);
  return (sigprocmask(SIG_BLOCK, &mask, (sigset_t *)0));
}


x86 assembly (clang, -O0):
<sighold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1157 <sighold+0x27>
mov    -0x8(%rbp),%eax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
jl     1175 <sighold+0x45>
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    0x2e79(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <sighold+0x73>
lea    -0xc(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1050 <sigaddset@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighold>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1171 <sighold+0x41>
mov    %edi,%ebx
mov    0x2e87(%rip),%rax
cmp    %edi,(%rax)
jle    1171 <sighold+0x41>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigemptyset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <sigaddset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
jmp    1188 <sighold+0x58>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    0x2e5f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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