#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 SIGINT;
int SIGQUIT;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void handler(int s) {
  if (s == SIGINT) {
    printf("recv sig %d\n", s);
  } else if (s == SIGQUIT) {
    sigset_t bset;
    sigemptyset(&bset);
    sigaddset(&bset, SIGINT);
    if (sigprocmask(SIG_UNBLOCK, &bset, NULL) == -1)
      do {
        fprintf(stderr, "[%s][%d]:%s %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/"
                "heads/master/apue/day08/sigprocmask.c",
                25, "sigprocmask", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
jne    11a1 <handler+0x31>
mov    -0x4(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
jmp    1249 <handler+0xd9>
mov    -0x4(%rbp),%eax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
jne    1244 <handler+0xd4>
lea    -0x8(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    123f <handler+0xcf>
jmp    11f2 <handler+0x82>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%r9
lea    0xdf4(%rip),%rsi
lea    0xdfd(%rip),%rdx
mov    $0x19,%ecx
lea    0xe8b(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1244 <handler+0xd4>
jmp    1249 <handler+0xd9>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%esi
mov    0x2e63(%rip),%rbx
cmp    %edi,(%rbx)
jne    1194 <handler+0x24>
lea    0xe78(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
mov    0x2e3d(%rip),%rax
cmp    %esi,(%rax)
jne    11ce <handler+0x5e>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <sigemptyset@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11d6 <handler+0x66>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2deb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe19(%rip),%rsi
lea    0xe22(%rip),%rdx
lea    0xeb5(%rip),%r8
mov    %ebx,%edi
mov    $0x19,%ecx
mov    %rax,%r9
call   1050 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [13 x i8] c"recv sig %d\0A\00"
@SIGQUIT = global i32 0
@SIG_UNBLOCK = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day08/sigprocmask.c\00"
@.str.3 = [12 x i8] c"sigprocmask\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @SIGINT
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %32
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGQUIT
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = call i32 @sigemptyset(i32* %3)
%16 = load i32, i32* @SIGINT
%17 = call i32 @sigaddset(i32* %3, i32 %16)
%18 = load i32, i32* @SIG_UNBLOCK
%19 = call i32 @sigprocmask(i32 %18, i32* %3, i32* null)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %30
21: ; preds = %14
br label %22
22: ; preds = %21
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; No predecessors!
br label %30
30: ; preds = %29, %14
br label %31
31: ; preds = %30, %10
br label %32
32: ; preds = %31, %7
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [13 x i8] c"recv sig %d\0A\00"
@SIGQUIT = global i32 0
@SIG_UNBLOCK = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day08/sigprocmask.c\00"
@.str.3 = [12 x i8] c"sigprocmask\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @handler(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @SIGINT
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %26
7: ; preds = %1
%8 = load i32, i32* @SIGQUIT
%9 = icmp eq i32 %8, %0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = bitcast i32* %2 to i8*
%12 = call i32 @sigemptyset(i32* %2)
%13 = load i32, i32* @SIGINT
%14 = call i32 @sigaddset(i32* %2, i32 %13)
%15 = load i32, i32* @SIG_UNBLOCK
%16 = call i32 @sigprocmask(i32 %15, i32* %2, i32* null)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.2, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %10
br label %26
26: ; preds = %7, %25, %5
ret void
}