#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*/ SIGALRM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ alrm_is_pending(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
char *strerror(int /*<<< orphan*/);
int main(void) {
  sigset_t sigset;
  sigemptyset(&sigset);
  sigaddset(&sigset, SIGALRM);
  if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
    printf("sigprocmask error: %s\n", strerror(errno));
    exit(-1);
  }
  alrm_is_pending("before alarm");
  alarm(2);
  sleep(4);
  alrm_is_pending("after alarm");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10a0 <sigaddset@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    1201 <main+0x71>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe0f(%rip),%rdi
call   10b0 <alrm_is_pending@plt>
mov    $0x2,%edi
call   1050 <alarm@plt>
mov    $0x4,%edi
call   1090 <sleep@plt>
lea    0xdfc(%rip),%rdi
call   10b0 <alrm_is_pending@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <sigaddset@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     11ff <main+0x6f>
lea    0xe45(%rip),%rdi
call   10b0 <alrm_is_pending@plt>
mov    $0x2,%edi
call   1050 <alarm@plt>
mov    $0x4,%edi
call   1090 <sleep@plt>
lea    0xe32(%rip),%rdi
call   10b0 <alrm_is_pending@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@.str = [23 x i8] c"sigprocmask error: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"before alarm\00"
@.str.2 = [12 x i8] c"after alarm\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @sigemptyset(i32* %2)
%4 = load i32, i32* @SIGALRM
%5 = call i32 @sigaddset(i32* %2, i32 %4)
%6 = load i32, i32* @SIG_BLOCK
%7 = call i64 @sigprocmask(i32 %6, i32* %2, i32* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = call i32 @alrm_is_pending(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @alarm(i32 2)
%17 = call i32 @sleep(i32 4)
%18 = call i32 @alrm_is_pending(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@SIGALRM = global i32 0
@SIG_BLOCK = global i32 0
@.str = [23 x i8] c"sigprocmask error: %s\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"before alarm\00"
@.str.2 = [12 x i8] c"after alarm\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sigemptyset(i32* %1)
%4 = load i32, i32* @SIGALRM
%5 = call i32 @sigaddset(i32* %1, i32 %4)
%6 = load i32, i32* @SIG_BLOCK
%7 = call i64 @sigprocmask(i32 %6, i32* %1, i32* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = call i32 @alrm_is_pending(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @alarm(i32 2)
%17 = call i32 @sleep(i32 4)
%18 = call i32 @alrm_is_pending(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}