#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*/ SIGINT;
int /*<<< orphan*/ SIGTSTP;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigpending(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
void main(int args, char **argv) {
  sigset_t set, set2;
  sigset_t pending;
  sigemptyset(&set);
  sigaddset(&set, SIGINT);
  sigaddset(&set, SIGTSTP);
  sigprocmask(SIG_BLOCK, &set, &set2);
  sleep(10);
  sigpending(&pending);
  if (sigismember(&pending, SIGINT)) {
    printf("SIGINT\n");
  }
  if (sigismember(&pending, SIGTSTP)) {
    printf("SIGTSTP\n");
    sigprocmask(SIG_SETMASK, &set2, NULL);
    sleep(10);
    printf("after ctrl z");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <sigpending@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     11fd <main+0x8d>
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdi
call   1070 <sigismember@plt>
cmp    $0x0,%rax
je     1251 <main+0xe1>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e4b(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e29(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <sigprocmask@plt>
mov    $0xa,%edi
call   1090 <sleep@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sigpending@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <sigismember@plt>
test   %rax,%rax
je     1203 <main+0x83>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%esi
lea    0x4(%rsp),%rdi
call   1080 <sigismember@plt>
test   %rax,%rax
je     124c <main+0xcc>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0xa,%edi
call   1090 <sleep@plt>
lea    0xdb9(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str = [8 x i8] c"SIGINT\0A\00"
@.str.1 = [9 x i8] c"SIGTSTP\0A\00"
@SIG_SETMASK = global i32 0
@.str.2 = [13 x i8] c"after ctrl z\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i32 @sigemptyset(i32* %5)
%9 = load i32, i32* @SIGINT
%10 = call i32 @sigaddset(i32* %5, i32 %9)
%11 = load i32, i32* @SIGTSTP
%12 = call i32 @sigaddset(i32* %5, i32 %11)
%13 = load i32, i32* @SIG_BLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %5, i32* %6)
%15 = call i32 @sleep(i32 10)
%16 = call i32 @sigpending(i32* %7)
%17 = load i32, i32* @SIGINT
%18 = call i64 @sigismember(i32* %7, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32, i32* @SIGTSTP
%24 = call i64 @sigismember(i32* %7, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @SIG_SETMASK
%29 = call i32 @sigprocmask(i32 %28, i32* %6, i32* null)
%30 = call i32 @sleep(i32 10)
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %26, %22
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
@.str.2 = [13 x i8] c"after ctrl z\00"
@str = [8 x i8] c"SIGTSTP\00"
@str.3 = [7 x i8] c"SIGINT\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @sigemptyset(i32* %3)
%10 = load i32, i32* @SIGINT
%11 = call i32 @sigaddset(i32* %3, i32 %10)
%12 = load i32, i32* @SIGTSTP
%13 = call i32 @sigaddset(i32* %3, i32 %12)
%14 = load i32, i32* @SIG_BLOCK
%15 = call i32 @sigprocmask(i32 %14, i32* %3, i32* %4)
%16 = call i32 @sleep(i32 10)
%17 = call i32 @sigpending(i32* %5)
%18 = load i32, i32* @SIGINT
%19 = call i64 @sigismember(i32* %5, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i32, i32* @SIGTSTP
%25 = call i64 @sigismember(i32* %5, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @SIG_SETMASK
%30 = call i32 @sigprocmask(i32 %29, i32* %4, i32* null)
%31 = call i32 @sleep(i32 10)
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %27, %23
ret void
}