#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIG_BLOCK;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int sigpending(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *strsignal(int /*<<< orphan*/);
int main() {
  sigset_t intSet, pendingSet;
  sigemptyset(&intSet);
  sigaddset(&intSet, SIGINT);
  printf("Blocking SIGINT (%s)\n", strsignal(SIGINT));
  if (sigprocmask(SIG_BLOCK, &intSet, NULL) == -1) {
    pexit("sigprocmask");
  }
  raise(SIGINT);
  printf("Sent SIGINT to self\n");
  if (sigpending(&pendingSet) == -1) {
    pexit("sigpending");
  }
  if (sigismember(&pendingSet, SIGINT)) {
    printf("SIGINT is in the pending list\n");
  } else {
    printf("SIGINT is not in the pending list, aborting\n");
    exit(EXIT_FAILURE);
  }
  printf("Ignoring SIGINT\n");
  if (signal(SIGINT, SIG_IGN) == SIG_ERR) {
    pexit("signal");
  }
  printf("Unblocking SIGINT\n");
  if (sigprocmask(SIG_UNBLOCK, &intSet, NULL) == -1) {
    pexit("sigprocmask");
  }
  if (sigpending(&pendingSet) == -1) {
    pexit("sigpending");
  }
  if (sigismember(&pendingSet, SIGINT)) {
    printf("SIGINT is still in the pending list, aborting\n");
    exit(EXIT_FAILURE);
  } else {
    printf("SIGINT signal is not on the pending list any more\n");
  }
  printf("Program finished successfully.\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10d0 <sigaddset@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <strsignal@plt>
mov    %rax,%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1224 <main+0x74>
lea    0xdf7(%rip),%rdi
call   10c0 <pexit@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1040 <raise@plt>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1090 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    125e <main+0xae>
lea    0xdde(%rip),%rdi
call   10c0 <pexit@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x0,%rax
je     128d <main+0xdd>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a9 <main+0xf9>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    0x2cf3(%rip),%rcx
cmp    (%rcx),%rax
jne    12ea <main+0x13a>
lea    0xdba(%rip),%rdi
call   10c0 <pexit@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1323 <main+0x173>
lea    0xcf8(%rip),%rdi
call   10c0 <pexit@plt>
lea    -0xc(%rbp),%rdi
call   1090 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    1341 <main+0x191>
lea    0xcfb(%rip),%rdi
call   10c0 <pexit@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x0,%rax
je     1379 <main+0x1c9>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2e08(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10e0 <sigaddset@plt>
mov    (%r14),%edi
call   1090 <strsignal@plt>
lea    0xe0e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1220 <main+0x60>
lea    0xdfb(%rip),%rdi
call   10d0 <pexit@plt>
mov    (%r14),%edi
call   1040 <raise@plt>
lea    0xe05(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rdi
call   10a0 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    124d <main+0x8d>
lea    0xdda(%rip),%rdi
call   10d0 <pexit@plt>
mov    (%r14),%esi
mov    %rsp,%rdi
call   10b0 <sigismember@plt>
test   %rax,%rax
jne    1269 <main+0xa9>
lea    0xde4(%rip),%rdi
jmp    1332 <main+0x172>
lea    0xe04(%rip),%rdi
call   1050 <puts@plt>
lea    0xe16(%rip),%rdi
call   1050 <puts@plt>
mov    (%r14),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    0x2d2f(%rip),%rcx
cmp    (%rcx),%rax
jne    12aa <main+0xea>
lea    0xd88(%rip),%rdi
call   10d0 <pexit@plt>
lea    0xdf1(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    12dc <main+0x11c>
lea    0xd3f(%rip),%rdi
call   10d0 <pexit@plt>
mov    %rsp,%rdi
call   10a0 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    12f5 <main+0x135>
lea    0xd32(%rip),%rdi
call   10d0 <pexit@plt>
mov    (%r14),%esi
mov    %rsp,%rdi
call   10b0 <sigismember@plt>
test   %rax,%rax
jne    132b <main+0x16b>
lea    0xda8(%rip),%rdi
call   1050 <puts@plt>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [22 x i8] c"Blocking SIGINT (%s)\0A\00"
@SIG_BLOCK = global i32 0
@.str.1 = [12 x i8] c"sigprocmask\00"
@.str.2 = [21 x i8] c"Sent SIGINT to self\0A\00"
@.str.3 = [11 x i8] c"sigpending\00"
@.str.4 = [31 x i8] c"SIGINT is in the pending list\0A\00"
@.str.5 = [45 x i8] c"SIGINT is not in the pending list, aborting\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [17 x i8] c"Ignoring SIGINT\0A\00"
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.7 = [7 x i8] c"signal\00"
@.str.8 = [19 x i8] c"Unblocking SIGINT\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.9 = [47 x i8] c"SIGINT is still in the pending list, aborting\0A\00"
@.str.10 = [51 x i8] c"SIGINT signal is not on the pending list any more\0A\00"
@.str.11 = [32 x i8] c"Program finished successfully.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @sigemptyset(i32* %2)
%5 = load i32, i32* @SIGINT
%6 = call i32 @sigaddset(i32* %2, i32 %5)
%7 = load i32, i32* @SIGINT
%8 = call i8* @strsignal(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %2, i32* null)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = load i32, i32* @SIGINT
%17 = call i32 @raise(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @sigpending(i32* %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @pexit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
%24 = load i32, i32* @SIGINT
%25 = call i64 @sigismember(i32* %3, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %33
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32, i32* @SIGINT
%36 = load i32, i32* @SIG_IGN
%37 = call i64 @signal(i32 %35, i32 %36)
%38 = load i64, i64* @SIG_ERR
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%44 = load i32, i32* @SIG_UNBLOCK
%45 = call i32 @sigprocmask(i32 %44, i32* %2, i32* null)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = call i32 @sigpending(i32* %3)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 @pexit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* @SIGINT
%56 = call i64 @sigismember(i32* %3, i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %54
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0))
br label %64
64: ; preds = %62
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [22 x i8] c"Blocking SIGINT (%s)\0A\00"
@SIG_BLOCK = global i32 0
@.str.1 = [12 x i8] c"sigprocmask\00"
@.str.3 = [11 x i8] c"sigpending\00"
@EXIT_FAILURE = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.7 = [7 x i8] c"signal\00"
@SIG_UNBLOCK = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [20 x i8] c"Sent SIGINT to self\00"
@str.12 = [44 x i8] c"SIGINT is not in the pending list, aborting\00"
@str.13 = [30 x i8] c"SIGINT is in the pending list\00"
@str.14 = [16 x i8] c"Ignoring SIGINT\00"
@str.15 = [18 x i8] c"Unblocking SIGINT\00"
@str.16 = [50 x i8] c"SIGINT signal is not on the pending list any more\00"
@str.17 = [31 x i8] c"Program finished successfully.\00"
@str.18 = [46 x i8] c"SIGINT is still in the pending list, aborting\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @sigemptyset(i32* %1)
%6 = load i32, i32* @SIGINT
%7 = call i32 @sigaddset(i32* %1, i32 %6)
%8 = load i32, i32* @SIGINT
%9 = call i8* @strsignal(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %1, i32* null)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = load i32, i32* @SIGINT
%18 = call i32 @raise(i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%20 = call i32 @sigpending(i32* %2)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @pexit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* @SIGINT
%26 = call i64 @sigismember(i32* %2, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0))
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.14, i64 0, i64 0))
%31 = load i32, i32* @SIGINT
%32 = load i32, i32* @SIG_IGN
%33 = call i64 @signal(i32 %31, i32 %32)
%34 = load i64, i64* @SIG_ERR
%35 = icmp eq i64 %33, %34
br i1 %35, label %40, label %42
36: ; preds = %24
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.12, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %42
42: ; preds = %40, %28
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
%44 = load i32, i32* @SIG_UNBLOCK
%45 = call i32 @sigprocmask(i32 %44, i32* %1, i32* null)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = call i32 @sigpending(i32* %2)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 @pexit(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* @SIGINT
%56 = call i64 @sigismember(i32* %2, i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %54
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.18, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %54
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.16, i64 0, i64 0))
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.17, i64 0, i64 0))
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
unreachable
}