#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ SIGABRT;
int get_rand();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(void *);
scalar_t__ pthread_sigmask(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void *a_thread_func() {
  int r = get_rand();
  sigset_t actl;
  sigemptyset(&actl);
  sigaddset(&actl, SIGABRT);
  if (pthread_sigmask(r, &actl, NULL) != EINVAL) {
    perror("pthread_sigmask() did not fail even though invalid how parameter "
           "was passed to it.\n");
    pthread_exit((void *)-1);
  }
  printf("PASS: pthread_sigmask returned the correct error value.\n");
  pthread_exit(NULL);
  return NULL;
}


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <get_rand@plt>
mov    %eax,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <pthread_sigmask@plt>
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     11d5 <a_thread_func+0x65>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1060 <pthread_exit@plt>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_thread_func>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <get_rand@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <sigaddset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <pthread_sigmask@plt>
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11ce <a_thread_func+0x5e>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffffffffffff,%rdi
call   1060 <pthread_exit@plt>
jmp    11b2 <a_thread_func+0x42>

LLVM IR (-O0):
@SIGABRT = global i32 0
@EINVAL = global i64 0
@.str = [84 x i8] c"pthread_sigmask() did not fail even though invalid how parameter was passed to it.\0A\00"
@.str.1 = [57 x i8] c"PASS: pthread_sigmask returned the correct error value.\0A\00"
define i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @get_rand()
store i32 %3, i32* %1
%4 = call i32 @sigemptyset(i32* %2)
%5 = load i32, i32* @SIGABRT
%6 = call i32 @sigaddset(i32* %2, i32 %5)
%7 = load i32, i32* %1
%8 = call i64 @pthread_sigmask(i32 %7, i32* %2, i32* null)
%9 = load i64, i64* @EINVAL
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %14
14: ; preds = %11, %0
%15 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @pthread_exit(i8* null)
ret i8* null
}

LLVM IR (-O2):
@SIGABRT = global i32 0
@EINVAL = global i64 0
@.str = [84 x i8] c"pthread_sigmask() did not fail even though invalid how parameter was passed to it.\0A\00"
@str = [56 x i8] c"PASS: pthread_sigmask returned the correct error value.\00"
define noalias i8* @a_thread_func() {
%1 = alloca i32
%2 = tail call i32 (...) @get_rand()
%3 = bitcast i32* %1 to i8*
%4 = call i32 @sigemptyset(i32* %1)
%5 = load i32, i32* @SIGABRT
%6 = call i32 @sigaddset(i32* %1, i32 %5)
%7 = call i64 @pthread_sigmask(i32 %2, i32* %1, i32* null)
%8 = load i64, i64* @EINVAL
%9 = icmp eq i64 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %13
13: ; preds = %10, %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%15 = call i32 @pthread_exit(i8* null)
ret i8* null
}