#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_UNBLOCK;
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int);
scalar_t__ sigpending(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int signalunblock(int signum) {
  sigset_t pendmask, mask;
  if (sigpending(&pendmask) < 0)
    return -1;
  if (sigismember(&pendmask, signum) == 0)
    return -1;
  sigemptyset(&mask);
  sigaddset(&mask, signum);
  if (sigprocmask(SIG_UNBLOCK, &mask, NULL) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<signalunblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <sigpending@plt>
cmp    $0x0,%rax
jge    117a <signalunblock+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <signalunblock+0x94>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigismember@plt>
cmp    $0x0,%rax
jne    119c <signalunblock+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <signalunblock+0x94>
lea    -0x10(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    -0x8(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11dd <signalunblock+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <signalunblock+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signalunblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %rsp,%rdi
call   1050 <sigpending@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11a7 <signalunblock+0x57>
mov    %rsp,%rdi
mov    %ebp,%esi
call   1060 <sigismember@plt>
test   %rax,%rax
je     11a7 <signalunblock+0x57>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <sigaddset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIG_UNBLOCK = global i32 0
define i32 @signalunblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i64 @sigpending(i32* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %23
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i64 @sigismember(i32* %4, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -1, i32* %2
br label %23
14: ; preds = %9
%15 = call i32 @sigemptyset(i32* %5)
%16 = load i32, i32* %3
%17 = call i32 @sigaddset(i32* %5, i32 %16)
%18 = load i32, i32* @SIG_UNBLOCK
%19 = call i64 @sigprocmask(i32 %18, i32* %5, i32* null)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %2
br label %23
22: ; preds = %14
store i32 0, i32* %2
br label %23
23: ; preds = %22, %21, %13, %8
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@SIG_UNBLOCK = global i32 0
define i32 @signalunblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i64 @sigpending(i32* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %1
%9 = call i64 @sigismember(i32* %2, i32 %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = call i32 @sigemptyset(i32* %3)
%13 = call i32 @sigaddset(i32* %3, i32 %0)
%14 = load i32, i32* @SIG_UNBLOCK
%15 = call i64 @sigprocmask(i32 %14, i32* %3, i32* null)
%16 = ashr i64 %15, 63
%17 = trunc i64 %16 to i32
br label %18
18: ; preds = %11, %8, %1
%19 = phi i32 [ -1, %1 ], [ -1, %8 ], [ %17, %11 ]
ret i32 %19
}