#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printSignalSet(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigpending(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int main(void) {
  sigset_t set;
  if (sigprocmask(0, NULL, &set) != 0) {
    perror("sigprocmask:");
    exit(EXIT_FAILURE);
  }
  printf("--- Initial signal mask for this process: ---\n");
  printSignalSet(&set);
  if (sigaddset(&set, SIGINT) != 0) {
    perror("sigaddset:");
    exit(EXIT_FAILURE);
  }
  if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) {
    perror("sigprocmask:");
    exit(EXIT_FAILURE);
  }
  printf("--- NEW signal mask for this process: ---\n");
  printSignalSet(&set);
  int secToSleep = 20;
  printf("Try Ctrl+C. Try killing this program with 'kill -kill %d'. Going to "
         "sleep for %d seconds.\n",
         getpid(), secToSleep);
  sleep(secToSleep);
  printf("Sleep returned.\n");
  sigset_t pendingSignalSet;
  sigpending(&pendingSignalSet);
  printf("--- Signals which are blocked/pending: ---\n");
  printSignalSet(&pendingSignalSet);
  printf("Removing all signals from mask.\n");
  if (sigemptyset(&set) != 0) {
    perror("sigemptyset:");
    exit(EXIT_FAILURE);
  }
  if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) {
    perror("sigprocmask:");
    exit(EXIT_FAILURE);
  }
  sleep(1);
  printf("Exited normally.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x8(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
je     11e2 <main+0x42>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1050 <printSignalSet@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10c0 <sigaddset@plt>
cmp    $0x0,%rax
je     122f <main+0x8f>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
je     1269 <main+0xc9>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1050 <printSignalSet@plt>
movl   $0x14,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
call   10b0 <sleep@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1090 <sigpending@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1050 <printSignalSet@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1070 <sigemptyset@plt>
cmp    $0x0,%rax
je     1312 <main+0x172>
lea    0xe2c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
je     134c <main+0x1ac>
lea    0xcc7(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1030 <sigprocmask@plt>
test   %rax,%rax
jne    12dd <main+0x12d>
lea    0xea9(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <printSignalSet@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10d0 <sigaddset@plt>
test   %rax,%rax
jne    12e6 <main+0x136>
mov    0x2dd6(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
jne    12dd <main+0x12d>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1060 <printSignalSet@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdcf(%rip),%rdi
mov    %eax,%esi
mov    $0x14,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x14,%edi
call   10c0 <sleep@plt>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <sigpending@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <printSignalSet@plt>
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1080 <sigemptyset@plt>
test   %rax,%rax
jne    12ef <main+0x13f>
mov    (%r15),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
jne    12dd <main+0x12d>
mov    $0x1,%edi
call   10c0 <sleep@plt>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd1c(%rip),%rdi
jmp    12f6 <main+0x146>
lea    0xd20(%rip),%rdi
jmp    12f6 <main+0x146>
lea    0xd7d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"sigprocmask:\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [47 x i8] c"--- Initial signal mask for this process: ---\0A\00"
@SIGINT = global i32 0
@.str.2 = [11 x i8] c"sigaddset:\00"
@SIG_SETMASK = global i32 0
@.str.3 = [43 x i8] c"--- NEW signal mask for this process: ---\0A\00"
@.str.4 = [91 x i8] c"Try Ctrl+C. Try killing this program with 'kill -kill %d'. Going to sleep for %d seconds.\0A\00"
@.str.5 = [17 x i8] c"Sleep returned.\0A\00"
@.str.6 = [44 x i8] c"--- Signals which are blocked/pending: ---\0A\00"
@.str.7 = [33 x i8] c"Removing all signals from mask.\0A\00"
@.str.8 = [13 x i8] c"sigemptyset:\00"
@.str.9 = [18 x i8] c"Exited normally.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 @sigprocmask(i32 0, i32* null, i32* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printSignalSet(i32* %2)
%14 = load i32, i32* @SIGINT
%15 = call i64 @sigaddset(i32* %2, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %11
%22 = load i32, i32* @SIG_SETMASK
%23 = call i64 @sigprocmask(i32 %22, i32* %2, i32* null)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @printSignalSet(i32* %2)
store i32 20, i32* %3
%32 = call i32 (...) @getpid()
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32, i32* %3
%36 = call i32 @sleep(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @sigpending(i32* %4)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @printSignalSet(i32* %4)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%42 = call i64 @sigemptyset(i32* %2)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %29
%45 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %29
%49 = load i32, i32* @SIG_SETMASK
%50 = call i64 @sigprocmask(i32 %49, i32* %2, i32* null)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = call i32 @sleep(i32 1)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"sigprocmask:\00"
@EXIT_FAILURE = global i32 0
@SIGINT = global i32 0
@.str.2 = [11 x i8] c"sigaddset:\00"
@SIG_SETMASK = global i32 0
@.str.4 = [91 x i8] c"Try Ctrl+C. Try killing this program with 'kill -kill %d'. Going to sleep for %d seconds.\0A\00"
@.str.8 = [13 x i8] c"sigemptyset:\00"
@str = [46 x i8] c"--- Initial signal mask for this process: ---\00"
@str.10 = [42 x i8] c"--- NEW signal mask for this process: ---\00"
@str.11 = [16 x i8] c"Sleep returned.\00"
@str.12 = [43 x i8] c"--- Signals which are blocked/pending: ---\00"
@str.13 = [32 x i8] c"Removing all signals from mask.\00"
@str.14 = [17 x i8] c"Exited normally.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i64 @sigprocmask(i32 0, i32* null, i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%12 = call i32 @printSignalSet(i32* %1)
%13 = load i32, i32* @SIGINT
%14 = call i64 @sigaddset(i32* %1, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = load i32, i32* @SIG_SETMASK
%22 = call i64 @sigprocmask(i32 %21, i32* %1, i32* null)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.10, i64 0, i64 0))
%30 = call i32 @printSignalSet(i32* %1)
%31 = call i32 (...) @getpid()
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 20)
%33 = call i32 @sleep(i32 20)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
%35 = bitcast i32* %2 to i8*
%36 = call i32 @sigpending(i32* %2)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.12, i64 0, i64 0))
%38 = call i32 @printSignalSet(i32* %2)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.13, i64 0, i64 0))
%40 = call i64 @sigemptyset(i32* %1)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %28
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %28
%47 = load i32, i32* @SIG_SETMASK
%48 = call i64 @sigprocmask(i32 %47, i32* %1, i32* null)
%49 = icmp eq i64 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
%55 = call i32 @sleep(i32 1)
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.14, i64 0, i64 0))
ret i32 0
}