#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*/ SIGCONT;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGUSR1;
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(SIGCONT) != 0) {
    printf("Could not raise SIGCONT\n");
    exit(-1);
  }
  if (raise(SIGUSR1) != 0) {
    printf("Could not raise SIGUSR1\n");
    exit(-1);
  }
  if (sigpending(&pendingset) == -1) {
    printf("Error calling sigpending()\n");
    exit(-1);
  }
  if (sigismember(&pendingset, SIGCONT) == 1) {
    if (sigismember(&pendingset, SIGUSR1) == 1) {
      printf("All pending signals found\n");
      if (sigismember(&pendingset, SIGHUP) == 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("Not all pending signals found\n");
      exit(-1);
    }
  } else {
    printf("Not all pending signals found\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    0x2e3e(%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    0x2e18(%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    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    12cb <handler+0x16b>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    12b5 <handler+0x155>
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    1293 <handler+0x133>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe05(%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    0xf55(%rip),%rdi
jmp    123c <handler+0xdc>
mov    0x2e52(%rip),%rbx
mov    (%rbx),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    11be <handler+0x5e>
mov    0x2e47(%rip),%r14
mov    (%r14),%edi
call   1030 <raise@plt>
test   %rax,%rax
jne    11c7 <handler+0x67>
lea    0x4(%rsp),%rdi
call   1060 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    11d0 <handler+0x70>
lea    0xec8(%rip),%rdi
jmp    123c <handler+0xdc>
lea    0xef2(%rip),%rdi
jmp    123c <handler+0xdc>
lea    0xed1(%rip),%rdi
jmp    123c <handler+0xdc>
mov    (%rbx),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    1235 <handler+0xd5>
mov    (%r14),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
cmp    $0x1,%eax
jne    1235 <handler+0xd5>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1070 <sigismember@plt>
test   %eax,%eax
jne    124b <handler+0xeb>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf4(%rip),%rdi
jmp    123c <handler+0xdc>

LLVM IR (-O0):
@.str = [30 x i8] c"Could not call sigemptyset()\0A\00"
@SIGCONT = global i32 0
@.str.1 = [25 x i8] c"Could not raise SIGCONT\0A\00"
@SIGUSR1 = global i32 0
@.str.2 = [25 x i8] c"Could not raise SIGUSR1\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
@.str.5 = [27 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 = [31 x i8] c"Not all pending signals found\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* @SIGCONT
%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* @SIGUSR1
%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* @SIGCONT
%31 = call i32 @sigismember(i32* %3, i32 %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %53
33: ; preds = %29
%34 = load i32, i32* @SIGUSR1
%35 = call i32 @sigismember(i32* %3, i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %50
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 %46
42: ; preds = %37
%43 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %37
%47 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%48 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %33
%51 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %29
%54 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@SIGCONT = global i32 0
@SIGUSR1 = global i32 0
@SIGHUP = global i32 0
@str.10 = [30 x i8] c"Not all pending signals found\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 = [26 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 SIGUSR1\00"
@str.18 = [24 x i8] c"Could not raise SIGCONT\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* @SIGCONT
%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* @SIGUSR1
%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* @SIGCONT
%31 = call i32 @sigismember(i32* %2, i32 %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %53
33: ; preds = %29
%34 = load i32, i32* @SIGUSR1
%35 = call i32 @sigismember(i32* %2, i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %50
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 %46
42: ; preds = %37
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.14, i64 0, i64 0))
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %37
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %33
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %29
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
%55 = call i32 @exit(i32 -1)
unreachable
}