#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 EINVAL;
long SIG_BLOCK;
long SIG_SETMASK;
long SIG_UNBLOCK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, long);
int pthread_sigmask(long, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
long random();
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int do_test(void) {
  sigset_t ss;
  sigemptyset(&ss);
  int i;
  for (i = 0; i < 10000; ++i) {
    long int r = random();
    if (r != SIG_BLOCK && r != SIG_SETMASK && r != SIG_UNBLOCK) {
      int e = pthread_sigmask(r, &ss, NULL);
      if (e == 0) {
        printf("pthread_sigmask succeeded for how = %ld\n", r);
        exit(1);
      }
      if (e != EINVAL) {
        puts("pthread_sigmask didn't return EINVAL");
        exit(1);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x4(%rbp),%rdi
call   1050 <sigemptyset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2710,-0x8(%rbp)
jge    1244 <do_test+0xe4>
mov    $0x0,%al
call   1060 <random@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
je     1231 <do_test+0xd1>
mov    -0x10(%rbp),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
je     1231 <do_test+0xd1>
mov    -0x10(%rbp),%rax
mov    0x2e25(%rip),%rcx
cmp    (%rcx),%rax
je     1231 <do_test+0xd1>
mov    -0x10(%rbp),%rdi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <pthread_sigmask@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1204 <do_test+0xa4>
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%eax
je     122c <do_test+0xcc>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1231 <do_test+0xd1>
jmp    1236 <do_test+0xd6>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1178 <do_test+0x18>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
call   1050 <sigemptyset@plt>
mov    $0x2710,%ebp
mov    0x2e4f(%rip),%r15
mov    0x2e58(%rip),%r12
mov    0x2e59(%rip),%r13
mov    0x2e32(%rip),%r14
jmp    11a5 <do_test+0x45>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     11ee <do_test+0x8e>
xor    %eax,%eax
call   1060 <random@plt>
cmp    (%r15),%rax
je     11a0 <do_test+0x40>
mov    %rax,%rbx
cmp    (%r12),%rax
je     11a0 <do_test+0x40>
cmp    0x0(%r13),%rbx
je     11a0 <do_test+0x40>
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1070 <pthread_sigmask@plt>
test   %eax,%eax
je     11ff <do_test+0x9f>
cmp    (%r14),%eax
je     11a0 <do_test+0x40>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfa(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SIG_BLOCK = global i64 0
@SIG_SETMASK = global i64 0
@SIG_UNBLOCK = global i64 0
@.str = [41 x i8] c"pthread_sigmask succeeded for how = %ld\0A\00"
@EINVAL = global i32 0
@.str.1 = [37 x i8] c"pthread_sigmask didn't return EINVAL\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = call i32 @sigemptyset(i32* %1)
store i32 0, i32* %2
br label %6
6: ; preds = %40, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 10000
br i1 %8, label %9, label %43
9: ; preds = %6
%10 = call i64 (...) @random()
store i64 %10, i64* %3
%11 = load i64, i64* %3
%12 = load i64, i64* @SIG_BLOCK
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %39
14: ; preds = %9
%15 = load i64, i64* %3
%16 = load i64, i64* @SIG_SETMASK
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i64, i64* %3
%20 = load i64, i64* @SIG_UNBLOCK
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load i64, i64* %3
%24 = call i32 @pthread_sigmask(i64 %23, i32* %1, i32* null)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i64, i64* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %4
%33 = load i32, i32* @EINVAL
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
br label %39
39: ; preds = %38, %18, %14, %9
br label %40
40: ; preds = %39
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %6
43: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@SIG_BLOCK = global i64 0
@SIG_SETMASK = global i64 0
@SIG_UNBLOCK = global i64 0
@.str = [41 x i8] c"pthread_sigmask succeeded for how = %ld\0A\00"
@EINVAL = global i32 0
@.str.1 = [37 x i8] c"pthread_sigmask didn't return EINVAL\00"
define i32 @do_test() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sigemptyset(i32* %1)
br label %4
4: ; preds = %0, %27
%5 = phi i32 [ 0, %0 ], [ %28, %27 ]
%6 = call i64 (...) @random()
%7 = load i64, i64* @SIG_BLOCK
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @SIG_SETMASK
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
%12 = load i64, i64* @SIG_UNBLOCK
%13 = icmp eq i64 %6, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %27, label %15
15: ; preds = %4
%16 = call i32 @pthread_sigmask(i64 %6, i32* %1, i32* null)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %6)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i32, i32* @EINVAL
%23 = icmp eq i32 %16, %22
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21, %4
%28 = add nuw nsw i32 %5, 1
%29 = icmp eq i32 %28, 10000
br i1 %29, label %30, label %4
30: ; preds = %27
ret i32 0
}