#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*/ SIGKILL;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
void test_sigprocmask(void) {
  sigset_t newmask;
  sigset_t oldmask;
  sigemptyset(&newmask);
  sigemptyset(&oldmask);
  sigaddset(&newmask, SIGKILL);
  sigaddset(&newmask, SIGSTOP);
  do {
    if (sigprocmask(SIG_SETMASK, &newmask, NULL) < 0) {
      perror("sigprocmask(SIG_SETMASK, &newmask, NULL) < 0");
      exit(1);
    }
  } while (0);
  do {
    if (sigprocmask(SIG_SETMASK, NULL, &oldmask) < 0) {
      perror("sigprocmask(SIG_SETMASK, NULL, &oldmask) < 0");
      exit(1);
    }
  } while (0);
  if (sigismember(&oldmask, SIGKILL) || sigismember(&oldmask, SIGSTOP)) {
    printf("SIGKILL or SIGSTOP should be ignored, but is not.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<test_sigprocmask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
call   1050 <sigemptyset@plt>
lea    -0x8(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    11e4 <test_sigprocmask+0x74>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11e9 <test_sigprocmask+0x79>
jmp    11ee <test_sigprocmask+0x7e>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    1224 <test_sigprocmask+0xb4>
lea    0xe18(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1229 <test_sigprocmask+0xb9>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
jne    1261 <test_sigprocmask+0xf1>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     1277 <test_sigprocmask+0x107>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sigprocmask>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    %rsp,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e44(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1090 <sigaddset@plt>
mov    0x2e2a(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <sigaddset@plt>
mov    0x2e30(%rip),%r12
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     1220 <test_sigprocmask+0xb0>
mov    (%r12),%edi
mov    %rsp,%rdx
xor    %esi,%esi
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     1229 <test_sigprocmask+0xb9>
mov    (%r15),%esi
mov    %rsp,%rdi
call   1070 <sigismember@plt>
test   %rax,%rax
jne    120a <test_sigprocmask+0x9a>
mov    (%r14),%esi
mov    %rsp,%rdi
call   1070 <sigismember@plt>
test   %rax,%rax
jne    120a <test_sigprocmask+0x9a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdd9(%rip),%rdi
jmp    1230 <test_sigprocmask+0xc0>
lea    0xdfd(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_SETMASK = global i32 0
@.str = [45 x i8] c"sigprocmask(SIG_SETMASK, &newmask, NULL) < 0\00"
@.str.1 = [45 x i8] c"sigprocmask(SIG_SETMASK, NULL, &oldmask) < 0\00"
@.str.2 = [51 x i8] c"SIGKILL or SIGSTOP should be ignored, but is not.\0A\00"
define void @test_sigprocmask() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @sigemptyset(i32* %1)
%4 = call i32 @sigemptyset(i32* %2)
%5 = load i32, i32* @SIGKILL
%6 = call i32 @sigaddset(i32* %1, i32 %5)
%7 = load i32, i32* @SIGSTOP
%8 = call i32 @sigaddset(i32* %1, i32 %7)
br label %9
9: ; preds = %0
%10 = load i32, i32* @SIG_SETMASK
%11 = call i64 @sigprocmask(i32 %10, i32* %1, i32* null)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
br label %17
17: ; preds = %16
br label %18
18: ; preds = %17
%19 = load i32, i32* @SIG_SETMASK
%20 = call i64 @sigprocmask(i32 %19, i32* null, i32* %2)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = load i32, i32* @SIGKILL
%28 = call i64 @sigismember(i32* %2, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i32, i32* @SIGSTOP
%32 = call i64 @sigismember(i32* %2, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30, %26
%35 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
ret void
}

LLVM IR (-O2):
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_SETMASK = global i32 0
@.str = [45 x i8] c"sigprocmask(SIG_SETMASK, &newmask, NULL) < 0\00"
@.str.1 = [45 x i8] c"sigprocmask(SIG_SETMASK, NULL, &oldmask) < 0\00"
@str = [50 x i8] c"SIGKILL or SIGSTOP should be ignored, but is not.\00"
define void @test_sigprocmask() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sigemptyset(i32* %1)
%6 = call i32 @sigemptyset(i32* %2)
%7 = load i32, i32* @SIGKILL
%8 = call i32 @sigaddset(i32* %1, i32 %7)
%9 = load i32, i32* @SIGSTOP
%10 = call i32 @sigaddset(i32* %1, i32 %9)
%11 = load i32, i32* @SIG_SETMASK
%12 = call i64 @sigprocmask(i32 %11, i32* %1, i32* null)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @SIG_SETMASK
%19 = call i64 @sigprocmask(i32 %18, i32* null, i32* %2)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = load i32, i32* @SIGKILL
%26 = call i64 @sigismember(i32* %2, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* @SIGSTOP
%30 = call i64 @sigismember(i32* %2, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28, %24
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
ret void
}