#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  unsigned long *__val;
};
typedef TYPE_1__ sigset_t;

/* Variables and functions */
int SIG_BLOCK;
int _SIGSET_NWORDS;
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
long osf_sigprocmask(int, unsigned long);
int sigprocmask(int how, const sigset_t *set, sigset_t *oset) {
  unsigned long int setval;
  long result;
  if (set)
    setval = set->__val[0];
  else {
    setval = 0;
    how = SIG_BLOCK;
  }
  result = osf_sigprocmask(how, setval);
  if (result == -1)
    return result;
  if (oset) {
    if (_SIGSET_NWORDS == 2)
      oset->__val[1] = 0;
    if (_SIGSET_NWORDS > 2)
      memset(oset, 0, sizeof(*oset));
    oset->__val[0] = result;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sigprocmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1151 <sigprocmask+0x31>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <sigprocmask+0x45>
movq   $0x0,-0x20(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <osf_sigprocmask@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    118c <sigprocmask+0x6c>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11eb <sigprocmask+0xcb>
cmpq   $0x0,-0x18(%rbp)
je     11e4 <sigprocmask+0xc4>
mov    0x2e4a(%rip),%rax
cmpl   $0x2,(%rax)
jne    11b6 <sigprocmask+0x96>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movq   $0x0,0x8(%rax)
mov    0x2e2b(%rip),%rax
cmpl   $0x2,(%rax)
jle    11d6 <sigprocmask+0xb6>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigprocmask>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
test   %rsi,%rsi
je     1134 <sigprocmask+0x14>
mov    (%rsi),%rax
mov    (%rax),%rsi
jmp    113f <sigprocmask+0x1f>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <osf_sigprocmask@plt>
cmp    $0xffffffffffffffff,%rax
je     116f <sigprocmask+0x4f>
xor    %ebp,%ebp
test   %r14,%r14
je     118d <sigprocmask+0x6d>
mov    %rax,%rbx
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
cmp    $0x2,%eax
jne    1176 <sigprocmask+0x56>
mov    (%r14),%rax
movq   $0x0,0x8(%rax)
jmp    1187 <sigprocmask+0x67>
mov    $0xffffffff,%ebp
jmp    118d <sigprocmask+0x6d>
jle    1187 <sigprocmask+0x67>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    (%r14),%rax
mov    %rbx,(%rax)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64* }
@SIG_BLOCK = global i32 0
@_SIGSET_NWORDS = global i32 0
define i32 @sigprocmask(i32 %0, %struct.TYPE_5__* %1, %struct.TYPE_5__* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_5__*
%7 = alloca %struct.TYPE_5__*
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %5
store %struct.TYPE_5__* %1, %struct.TYPE_5__** %6
store %struct.TYPE_5__* %2, %struct.TYPE_5__** %7
%10 = load %struct.TYPE_5__*, %struct.TYPE_5__** %6
%11 = icmp ne %struct.TYPE_5__* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load %struct.TYPE_5__*, %struct.TYPE_5__** %6
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %13, i32 0, i32 0
%15 = load i64*, i64** %14
%16 = getelementptr inbounds i64, i64* %15, i64 0
%17 = load i64, i64* %16
store i64 %17, i64* %8
br label %20
18: ; preds = %3
store i64 0, i64* %8
%19 = load i32, i32* @SIG_BLOCK
store i32 %19, i32* %5
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* %5
%22 = load i64, i64* %8
%23 = call i64 @osf_sigprocmask(i32 %21, i64 %22)
store i64 %23, i64* %9
%24 = load i64, i64* %9
%25 = icmp eq i64 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i64, i64* %9
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
br label %53
29: ; preds = %20
%30 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%31 = icmp ne %struct.TYPE_5__* %30, null
br i1 %31, label %32, label %52
32: ; preds = %29
%33 = load i32, i32* @_SIGSET_NWORDS
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%37 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %36, i32 0, i32 0
%38 = load i64*, i64** %37
%39 = getelementptr inbounds i64, i64* %38, i64 1
store i64 0, i64* %39
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* @_SIGSET_NWORDS
%42 = icmp sgt i32 %41, 2
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%45 = call i32 @memset(%struct.TYPE_5__* %44, i32 0, i32 8)
br label %46
46: ; preds = %43, %40
%47 = load i64, i64* %9
%48 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %48, i32 0, i32 0
%50 = load i64*, i64** %49
%51 = getelementptr inbounds i64, i64* %50, i64 0
store i64 %47, i64* %51
br label %52
52: ; preds = %46, %29
store i32 0, i32* %4
br label %53
53: ; preds = %52, %26
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64* }
@SIG_BLOCK = global i32 0
@_SIGSET_NWORDS = global i32 0
define i32 @sigprocmask(i32 %0, %struct.TYPE_5__* %1, %struct.TYPE_5__* %2) {
%4 = icmp eq %struct.TYPE_5__* %1, null
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0
%7 = load i64*, i64** %6
%8 = load i64, i64* %7
br label %11
9: ; preds = %3
%10 = load i32, i32* @SIG_BLOCK
br label %11
11: ; preds = %9, %5
%12 = phi i32 [ %0, %5 ], [ %10, %9 ]
%13 = phi i64 [ %8, %5 ], [ 0, %9 ]
%14 = tail call i64 @osf_sigprocmask(i32 %12, i64 %13)
%15 = icmp eq i64 %14, -1
br i1 %15, label %32, label %16
16: ; preds = %11
%17 = icmp eq %struct.TYPE_5__* %2, null
br i1 %17, label %32, label %18
18: ; preds = %16
%19 = load i32, i32* @_SIGSET_NWORDS
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %2, i64 0, i32 0
%23 = load i64*, i64** %22
%24 = getelementptr inbounds i64, i64* %23, i64 1
store i64 0, i64* %24
br label %29
25: ; preds = %18
%26 = icmp sgt i32 %19, 2
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = tail call i32 @memset(%struct.TYPE_5__* %2, i32 0, i32 8)
br label %29
29: ; preds = %21, %27, %25
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %2, i64 0, i32 0
%31 = load i64*, i64** %30
store i64 %14, i64* %31
br label %32
32: ; preds = %16, %29, %11
%33 = phi i32 [ -1, %11 ], [ 0, %29 ], [ 0, %16 ]
ret i32 %33
}