#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*/ SIGCONT;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIGUSR2;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ raise(int /*<<< orphan*/);
int sigemptyset(int /*<<< orphan*/ *);
int sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigpending(int /*<<< orphan*/ *);
void handler(int signo __attribute__((unused))) {
  sigset_t pendingset;
  if (sigemptyset(&pendingset) == -1) {
    printf("Could not call sigemptyset()\n");
    exit(-1);
  }
  if (raise(SIGUSR2) != 0) {
    printf("Could not raise SIGUSR2\n");
    exit(-1);
  }
  if (raise(SIGCONT) != 0) {
    printf("Could not raise SIGCONT\n");
    exit(-1);
  }
  if (sigpending(&pendingset) == -1) {
    printf("Error calling sigpending()\n");
    exit(-1);
  }
  if (sigismember(&pendingset, SIGUSR2) == 1 &&
      sigismember(&pendingset, SIGCONT) == 1) {
    printf("All pending signals found\n");
    if ((sigismember(&pendingset, SIGHUP) == 0) &&
        (sigismember(&pendingset, SIGABRT) == 0) &&
        (sigismember(&pendingset, SIGUSR1) == 0)) {
      printf("Unsent signals not found\n");
      printf("Test PASSED\n");
      exit(0);
    } else {
      printf("Error with unsent signals\n");
      printf("Test FAILED\n");
      exit(-1);
    }
  } else {
    printf("Error with send signals\n");
    printf("Test FAILED\n");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <sigemptyset@plt>
cmp    $0xffffffff,%eax
jne    1193 <handler+0x33>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
cmp    $0x0,%rax
je     11c1 <handler+0x61>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
cmp    $0x0,%rax
je     11ef <handler+0x8f>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1060 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    1217 <handler+0xb7>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    12eb <handler+0x18b>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    12eb <handler+0x18b>
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%eax
jne    12c9 <handler+0x169>
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%eax
jne    12c9 <handler+0x169>
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%eax
jne    12c9 <handler+0x169>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<handler>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rdi
call   1050 <sigemptyset@plt>
cmp    $0xffffffff,%eax
jne    117f <handler+0x1f>
lea    0xf4e(%rip),%rdi
jmp    128c <handler+0x12c>
mov    0x2e42(%rip),%rbx
mov    (%rbx),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    11c1 <handler+0x61>
mov    0x2e3f(%rip),%r14
mov    (%r14),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    11cd <handler+0x6d>
lea    0x4(%rsp),%rdi
call   1060 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    11d9 <handler+0x79>
lea    0xec1(%rip),%rdi
jmp    128c <handler+0x12c>
lea    0xee8(%rip),%rdi
jmp    128c <handler+0x12c>
lea    0xec4(%rip),%rdi
jmp    128c <handler+0x12c>
mov    (%rbx),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    1270 <handler+0x110>
mov    (%r14),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    1270 <handler+0x110>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
test   %eax,%eax
jne    1279 <handler+0x119>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
test   %eax,%eax
jne    1279 <handler+0x119>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
test   %eax,%eax
jne    1279 <handler+0x119>
lea    0xe00(%rip),%rdi
call   1040 <puts@plt>
lea    0xe0d(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xd89(%rip),%rdi
jmp    1280 <handler+0x120>
lea    0xdb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xdc0(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Could not call sigemptyset()\0A\00"
@SIGUSR2 = global i32 0
@.str.1 = [25 x i8] c"Could not raise SIGUSR2\0A\00"
@SIGCONT = global i32 0
@.str.2 = [25 x i8] c"Could not raise SIGCONT\0A\00"
@.str.3 = [28 x i8] c"Error calling sigpending()\0A\00"
@.str.4 = [27 x i8] c"All pending signals found\0A\00"
@SIGHUP = global i32 0
@SIGABRT = global i32 0
@SIGUSR1 = global i32 0
@.str.5 = [26 x i8] c"Unsent signals not found\0A\00"
@.str.6 = [13 x i8] c"Test PASSED\0A\00"
@.str.7 = [27 x i8] c"Error with unsent signals\0A\00"
@.str.8 = [13 x i8] c"Test FAILED\0A\00"
@.str.9 = [25 x i8] c"Error with send signals\0A\00"
define void @handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @sigemptyset(i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %1
%10 = load i32, i32* @SIGUSR2
%11 = call i64 @raise(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %9
%17 = load i32, i32* @SIGCONT
%18 = call i64 @raise(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %16
%24 = call i32 @sigpending(i32* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = load i32, i32* @SIGUSR2
%31 = call i32 @sigismember(i32* %3, i32 %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %58
33: ; preds = %29
%34 = load i32, i32* @SIGCONT
%35 = call i32 @sigismember(i32* %3, i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %58
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* @SIGHUP
%40 = call i32 @sigismember(i32* %3, i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %37
%43 = load i32, i32* @SIGABRT
%44 = call i32 @sigismember(i32* %3, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42
%47 = load i32, i32* @SIGUSR1
%48 = call i32 @sigismember(i32* %3, i32 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %46, %42, %37
%55 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%56 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %33, %29
%59 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%60 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@SIGUSR2 = global i32 0
@SIGCONT = global i32 0
@SIGHUP = global i32 0
@SIGABRT = global i32 0
@SIGUSR1 = global i32 0
@str = [24 x i8] c"Error with send signals\00"
@str.11 = [26 x i8] c"All pending signals found\00"
@str.12 = [26 x i8] c"Error with unsent signals\00"
@str.13 = [12 x i8] c"Test FAILED\00"
@str.14 = [25 x i8] c"Unsent signals not found\00"
@str.15 = [12 x i8] c"Test PASSED\00"
@str.16 = [27 x i8] c"Error calling sigpending()\00"
@str.17 = [24 x i8] c"Could not raise SIGCONT\00"
@str.18 = [24 x i8] c"Could not raise SIGUSR2\00"
@str.19 = [29 x i8] c"Could not call sigemptyset()\00"
define void @handler(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sigemptyset(i32* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.19, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %1
%10 = load i32, i32* @SIGUSR2
%11 = call i64 @raise(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.18, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %9
%17 = load i32, i32* @SIGCONT
%18 = call i64 @raise(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.17, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %16
%24 = call i32 @sigpending(i32* %2)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.16, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = load i32, i32* @SIGUSR2
%31 = call i32 @sigismember(i32* %2, i32 %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %58
33: ; preds = %29
%34 = load i32, i32* @SIGCONT
%35 = call i32 @sigismember(i32* %2, i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %58
37: ; preds = %33
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
%39 = load i32, i32* @SIGHUP
%40 = call i32 @sigismember(i32* %2, i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %37
%43 = load i32, i32* @SIGABRT
%44 = call i32 @sigismember(i32* %2, i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42
%47 = load i32, i32* @SIGUSR1
%48 = call i32 @sigismember(i32* %2, i32 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %46, %42, %37
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %33, %29
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
}