#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*/ printf(char *, ...);
int /*<<< orphan*/ pthread_exit(void *);
int pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
void *a_thread_func() {
  sigset_t set1, set2;
  int pthread_sigmask_return_val = 1;
  sigemptyset(&set1);
  sigemptyset(&set2);
  sigaddset(&set1, SIGKILL);
  sigaddset(&set1, SIGSTOP);
  pthread_sigmask_return_val = pthread_sigmask(SIG_SETMASK, &set1, NULL);
  pthread_sigmask(SIG_SETMASK, NULL, &set2);
  if (sigismember(&set2, SIGKILL)) {
    printf("FAIL: SIGKILL was added to the signal mask\n");
    pthread_exit((void *)-1);
  }
  if (sigismember(&set2, SIGSTOP)) {
    printf("FAIL: SIGSTOP was added to the signal mask\n");
    pthread_exit((void *)-1);
  }
  if (pthread_sigmask_return_val != 0) {
    printf("FAIL: pthread_sigmask returned %d. System should be able to "
           "enforce blocking un-ignorable signals without causing "
           "pthread_sigmask() to return an error.\n",
           pthread_sigmask_return_val);
    pthread_exit((void *)-1);
  }
  printf("Test PASSED\n");
  pthread_exit(NULL);
  return NULL;
}


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <sigemptyset@plt>
lea    -0x8(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <pthread_sigmask@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1060 <pthread_sigmask@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     120a <a_thread_func+0xaa>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%rdi
call   1050 <pthread_exit@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     1240 <a_thread_func+0xe0>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%rdi
call   1050 <pthread_exit@plt>
cmpl   $0x0,-0xc(%rbp)
je     1267 <a_thread_func+0x107>
mov    -0xc(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%rdi
call   1050 <pthread_exit@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <pthread_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_thread_func>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <sigemptyset@plt>
lea    0x8(%rsp),%r12
mov    %r12,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e3b(%rip),%r15
mov    (%r15),%esi
mov    %rbp,%rdi
call   1090 <sigaddset@plt>
mov    0x2e21(%rip),%r14
mov    (%r14),%esi
mov    %rbp,%rdi
call   1090 <sigaddset@plt>
mov    0x2e27(%rip),%rbx
mov    (%rbx),%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1070 <pthread_sigmask@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
xor    %esi,%esi
mov    %r12,%rdx
call   1070 <pthread_sigmask@plt>
mov    (%r15),%esi
mov    %r12,%rdi
call   1080 <sigismember@plt>
test   %rax,%rax
je     1203 <a_thread_func+0x93>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rdi
call   1060 <pthread_exit@plt>
mov    (%r14),%esi
lea    0x8(%rsp),%rdi
call   1080 <sigismember@plt>
test   %rax,%rax
je     122d <a_thread_func+0xbd>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rdi
call   1060 <pthread_exit@plt>
test   %ebp,%ebp
je     124d <a_thread_func+0xdd>
lea    0xdc8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffffffffffff,%rdi
call   1060 <pthread_exit@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_SETMASK = global i32 0
@.str = [44 x i8] c"FAIL: SIGKILL was added to the signal mask\0A\00"
@.str.1 = [44 x i8] c"FAIL: SIGSTOP was added to the signal mask\0A\00"
@.str.2 = [153 x i8] c"FAIL: pthread_sigmask returned %d. System should be able to enforce blocking un-ignorable signals without causing pthread_sigmask() to return an error.\0A\00"
@.str.3 = [13 x i8] c"Test PASSED\0A\00"
define i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %3
%4 = call i32 @sigemptyset(i32* %1)
%5 = call i32 @sigemptyset(i32* %2)
%6 = load i32, i32* @SIGKILL
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIGSTOP
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = load i32, i32* @SIG_SETMASK
%11 = call i32 @pthread_sigmask(i32 %10, i32* %1, i32* null)
store i32 %11, i32* %3
%12 = load i32, i32* @SIG_SETMASK
%13 = call i32 @pthread_sigmask(i32 %12, i32* null, i32* %2)
%14 = load i32, i32* @SIGKILL
%15 = call i64 @sigismember(i32* %2, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %20
20: ; preds = %17, %0
%21 = load i32, i32* @SIGSTOP
%22 = call i64 @sigismember(i32* %2, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %34
34: ; preds = %30, %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @pthread_exit(i8* null)
ret i8* null
}

LLVM IR (-O2):
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
@SIG_SETMASK = global i32 0
@.str.2 = [153 x i8] c"FAIL: pthread_sigmask returned %d. System should be able to enforce blocking un-ignorable signals without causing pthread_sigmask() to return an error.\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.4 = [43 x i8] c"FAIL: SIGSTOP was added to the signal mask\00"
@str.5 = [43 x i8] c"FAIL: SIGKILL was added to the signal mask\00"
define noalias i8* @a_thread_func() {
%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 i32 @pthread_sigmask(i32 %11, i32* %1, i32* null)
%13 = load i32, i32* @SIG_SETMASK
%14 = call i32 @pthread_sigmask(i32 %13, i32* null, i32* %2)
%15 = load i32, i32* @SIGKILL
%16 = call i64 @sigismember(i32* %2, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.5, i64 0, i64 0))
%20 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %21
21: ; preds = %18, %0
%22 = load i32, i32* @SIGSTOP
%23 = call i64 @sigismember(i32* %2, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.4, i64 0, i64 0))
%27 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %28
28: ; preds = %25, %21
%29 = icmp eq i32 %12, 0
br i1 %29, label %33, label %30
30: ; preds = %28
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%32 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %33
33: ; preds = %30, %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%35 = call i32 @pthread_exit(i8* null)
ret i8* null
}