#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*/ SIGABRT;
int /*<<< orphan*/ SIGALRM;
int SIG_SETMASK;
int get_rand();
scalar_t__ is_changed(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigprocmask(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(void) {
  int r = get_rand();
  sigset_t actl, oactl;
  sigemptyset(&actl);
  sigemptyset(&oactl);
  sigaddset(&actl, SIGABRT);
  sigprocmask(SIG_SETMASK, &actl, NULL);
  sigaddset(&actl, SIGALRM);
  if (sigprocmask(r, &actl, NULL) != -1) {
    perror("sigprocmask() did not fail even though invalid how parameter was "
           "passed to it.\n");
    return 2;
  }
  sigprocmask(SIG_SETMASK, NULL, &oactl);
  if (sigismember(&oactl, SIGABRT) != 1) {
    printf("FAIL: signal mask was changed. \n");
    return 1;
  }
  if (is_changed(oactl)) {
    printf("FAIL: signal mask was changed. \n");
    return 1;
  }
  printf("Test PASSED: signal mask was not changed.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <get_rand@plt>
mov    %eax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <sigemptyset@plt>
lea    -0x10(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     1216 <main+0x96>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    129c <main+0x11c>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1090 <sigismember@plt>
cmp    $0x1,%eax
je     125f <main+0xdf>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
mov    -0x10(%rbp),%edi
call   1070 <is_changed@plt>
cmp    $0x0,%rax
je     1289 <main+0x109>
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <main+0x11c>
lea    0xde1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <get_rand@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    %rsp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e24(%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   1030 <sigprocmask@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   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1246 <main+0xc6>
mov    (%r15),%edi
mov    %rsp,%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <sigismember@plt>
cmp    $0x1,%eax
jne    121a <main+0x9a>
mov    (%rsp),%edi
call   1070 <is_changed@plt>
test   %rax,%rax
je     1236 <main+0xb6>
lea    0xe59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    122b <main+0xab>
lea    0xdb3(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    122b <main+0xab>

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

LLVM IR (-O2):
@SIGABRT = global i32 0
@SIG_SETMASK = global i32 0
@SIGALRM = global i32 0
@.str = [80 x i8] c"sigprocmask() did not fail even though invalid how parameter was passed to it.\0A\00"
@str = [42 x i8] c"Test PASSED: signal mask was not changed.\00"
@str.4 = [32 x i8] c"FAIL: signal mask was changed. \00"
define i32 @main() {
%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 i32 @sigprocmask(i32 %10, i32* %1, i32* null)
%12 = load i32, i32* @SIGALRM
%13 = call i32 @sigaddset(i32* %1, i32 %12)
%14 = call i32 @sigprocmask(i32 %3, i32* %1, i32* null)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
br label %34
18: ; preds = %0
%19 = load i32, i32* @SIG_SETMASK
%20 = call i32 @sigprocmask(i32 %19, i32* null, i32* %2)
%21 = load i32, i32* @SIGABRT
%22 = call i32 @sigismember(i32* %2, i32 %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %34
26: ; preds = %18
%27 = load i32, i32* %2
%28 = call i64 @is_changed(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %34
32: ; preds = %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %30, %24, %16
%35 = phi i32 [ 2, %16 ], [ 1, %24 ], [ 1, %30 ], [ 0, %32 ]
ret i32 %35
}