#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 /*<<< orphan*/ SIGALRM;
int SIG_SETMASK;
int get_rand();
scalar_t__ is_changed(int /*<<< orphan*/, int /*<<< orphan*/);
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, oactl;
  sigemptyset(&actl);
  sigemptyset(&oactl);
  sigaddset(&actl, SIGABRT);
  pthread_sigmask(SIG_SETMASK, &actl, NULL);
  sigaddset(&actl, SIGALRM);
  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);
  }
  pthread_sigmask(SIG_SETMASK, NULL, &oactl);
  if (is_changed(oactl, SIGABRT)) {
    printf("FAIL: signal mask was changed. \n");
    pthread_exit((void *)-1);
  }
  printf("PASS: signal mask was not changed.\n");
  pthread_exit((void *)0);
  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>
lea    -0xc(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <pthread_sigmask@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <pthread_sigmask@plt>
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
je     1214 <a_thread_func+0x94>
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   1070 <pthread_exit@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0xc(%rbp),%rdx
call   1080 <pthread_sigmask@plt>
mov    -0xc(%rbp),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
call   1060 <is_changed@plt>
cmp    $0x0,%rax
je     125d <a_thread_func+0xdd>
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%rdi
call   1070 <pthread_exit@plt>
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <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   %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    %rsp,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e1c(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e22(%rip),%r15
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <pthread_sigmask@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <pthread_sigmask@plt>
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
jne    1249 <a_thread_func+0xc9>
mov    (%r15),%edi
mov    %rsp,%rdx
xor    %esi,%esi
call   1080 <pthread_sigmask@plt>
mov    (%rsp),%edi
mov    (%r14),%esi
call   1060 <is_changed@plt>
test   %rax,%rax
je     1229 <a_thread_func+0xa9>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rdi
call   1070 <pthread_exit@plt>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   1070 <pthread_exit@plt>
jmp    11f4 <a_thread_func+0x74>

LLVM IR (-O0):
@SIGABRT = global i32 0
@SIG_SETMASK = global i32 0
@SIGALRM = 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 = [33 x i8] c"FAIL: signal mask was changed. \0A\00"
@.str.2 = [36 x i8] c"PASS: signal mask was not changed.\0A\00"
define i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @get_rand()
store i32 %4, i32* %1
%5 = call i32 @sigemptyset(i32* %2)
%6 = call i32 @sigemptyset(i32* %3)
%7 = load i32, i32* @SIGABRT
%8 = call i32 @sigaddset(i32* %2, i32 %7)
%9 = load i32, i32* @SIG_SETMASK
%10 = call i64 @pthread_sigmask(i32 %9, i32* %2, i32* null)
%11 = load i32, i32* @SIGALRM
%12 = call i32 @sigaddset(i32* %2, i32 %11)
%13 = load i32, i32* %1
%14 = call i64 @pthread_sigmask(i32 %13, i32* %2, i32* null)
%15 = load i64, i64* @EINVAL
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 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* @SIG_SETMASK
%22 = call i64 @pthread_sigmask(i32 %21, i32* null, i32* %3)
%23 = load i32, i32* %3
%24 = load i32, i32* @SIGABRT
%25 = call i64 @is_changed(i32 %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %30
30: ; preds = %27, %20
%31 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @pthread_exit(i8* null)
ret i8* null
}

LLVM IR (-O2):
@SIGABRT = global i32 0
@SIG_SETMASK = global i32 0
@SIGALRM = 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 = [35 x i8] c"PASS: signal mask was not changed.\00"
@str.3 = [32 x i8] c"FAIL: signal mask was changed. \00"
define noalias i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 (...) @get_rand()
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = call i32 @sigemptyset(i32* %1)
%7 = call i32 @sigemptyset(i32* %2)
%8 = load i32, i32* @SIGABRT
%9 = call i32 @sigaddset(i32* %1, i32 %8)
%10 = load i32, i32* @SIG_SETMASK
%11 = call i64 @pthread_sigmask(i32 %10, i32* %1, i32* null)
%12 = load i32, i32* @SIGALRM
%13 = call i32 @sigaddset(i32* %1, i32 %12)
%14 = call i64 @pthread_sigmask(i32 %3, i32* %1, i32* null)
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 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* @SIG_SETMASK
%22 = call i64 @pthread_sigmask(i32 %21, i32* null, i32* %2)
%23 = load i32, i32* %2
%24 = load i32, i32* @SIGABRT
%25 = call i64 @is_changed(i32 %23, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.3, i64 0, i64 0))
%29 = call i32 @pthread_exit(i8* inttoptr (i64 -1 to i8*))
br label %30
30: ; preds = %27, %20
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%32 = call i32 @pthread_exit(i8* null)
ret i8* null
}