#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 SIGRTMIN;
int SIGUSR1;
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 == SIGRTMIN)
    printf("recv sig %d\n", s);
  else if (s == SIGUSR1) {
    sigset_t set;
    sigemptyset(&set);
    sigaddset(&set, SIGINT);
    sigaddset(&set, SIGRTMIN);
    if (sigprocmask(SIG_UNBLOCK, &set, 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/day09/rcv.c",
                40, "sigprocmask", strerror(errno));
        exit(EXIT_FAILURE);
      } while (0);
    if (sigprocmask(SIG_UNBLOCK, &set, 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/day09/rcv.c",
                42, "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    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jne    11a1 <handler+0x31>
mov    -0x4(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
jmp    12f7 <handler+0x187>
mov    -0x4(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    11c7 <handler+0x57>
mov    -0x4(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
jmp    12f2 <handler+0x182>
mov    -0x4(%rbp),%eax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%eax
jne    12ed <handler+0x17d>
lea    -0x8(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1277 <handler+0x107>
jmp    122a <handler+0xba>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%r9
lea    0xdbc(%rip),%rsi
lea    0xdc5(%rip),%rdx
mov    $0x28,%ecx
lea    0xe4b(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    12e8 <handler+0x178>
jmp    129b <handler+0x12b>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%r9
lea    0xd4b(%rip),%rsi
lea    0xd54(%rip),%rdx
mov    $0x2a,%ecx
lea    0xdda(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    12ed <handler+0x17d>
jmp    12f2 <handler+0x182>
jmp    12f7 <handler+0x187>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%esi
mov    0x2e56(%rip),%rbx
cmp    %edi,(%rbx)
je     1192 <handler+0x22>
mov    0x2e33(%rip),%r15
cmp    %esi,(%r15)
jne    11a7 <handler+0x37>
lea    0xe67(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
mov    0x2e32(%rip),%rax
cmp    %esi,(%rax)
jne    11ff <handler+0x8f>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1060 <sigemptyset@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    0x2e0d(%rip),%rbx
mov    (%rbx),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     1209 <handler+0x99>
mov    (%rbx),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     123e <handler+0xce>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2db8(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde6(%rip),%rsi
lea    0xdef(%rip),%rdx
lea    0xe7a(%rip),%r8
mov    %ebx,%edi
mov    $0x28,%ecx
jmp    1271 <handler+0x101>
mov    0x2d83(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdb1(%rip),%rsi
lea    0xdba(%rip),%rdx
lea    0xe45(%rip),%r8
mov    %ebx,%edi
mov    $0x2a,%ecx
mov    %rax,%r9
call   1050 <fprintf@plt>
mov    0x2d30(%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"
@SIGRTMIN = global i32 0
@SIGUSR1 = 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 = [146 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/day09/rcv.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 %55
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGRTMIN
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %54
17: ; preds = %10
%18 = load i32, i32* %2
%19 = load i32, i32* @SIGUSR1
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = call i32 @sigemptyset(i32* %3)
%23 = load i32, i32* @SIGINT
%24 = call i32 @sigaddset(i32* %3, i32 %23)
%25 = load i32, i32* @SIGRTMIN
%26 = call i32 @sigaddset(i32* %3, i32 %25)
%27 = load i32, i32* @SIG_UNBLOCK
%28 = call i32 @sigprocmask(i32 %27, i32* %3, i32* null)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %39
30: ; preds = %21
br label %31
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %21
%40 = load i32, i32* @SIG_UNBLOCK
%41 = call i32 @sigprocmask(i32 %40, i32* %3, i32* null)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %52
43: ; preds = %39
br label %44
44: ; preds = %43
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; No predecessors!
br label %52
52: ; preds = %51, %39
br label %53
53: ; preds = %52, %17
br label %54
54: ; preds = %53, %14
br label %55
55: ; preds = %54, %7
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@.str = [13 x i8] c"recv sig %d\0A\00"
@SIGRTMIN = global i32 0
@SIGUSR1 = 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 = [146 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/day09/rcv.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 %44
7: ; preds = %1
%8 = load i32, i32* @SIGRTMIN
%9 = icmp eq i32 %8, %0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %44
12: ; preds = %7
%13 = load i32, i32* @SIGUSR1
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %44
15: ; preds = %12
%16 = bitcast i32* %2 to i8*
%17 = call i32 @sigemptyset(i32* %2)
%18 = load i32, i32* @SIGINT
%19 = call i32 @sigaddset(i32* %2, i32 %18)
%20 = load i32, i32* @SIGRTMIN
%21 = call i32 @sigaddset(i32* %2, i32 %20)
%22 = load i32, i32* @SIG_UNBLOCK
%23 = call i32 @sigprocmask(i32 %22, i32* %2, i32* null)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %32
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %15
%33 = load i32, i32* @SIG_UNBLOCK
%34 = call i32 @sigprocmask(i32 %33, i32* %2, i32* null)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %32
br label %44
44: ; preds = %10, %43, %12, %5
ret void
}