#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*/ SIGABRT;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  sigset_t set;
  int sig_ret;
  int i = 0;
  sigemptyset(&set);
  sigaddset(&set, SIGABRT);
  sigprocmask(SIG_BLOCK, &set, NULL);
  for (i = 0; i < 5; i++) {
    sleep(1);
    printf("state:block\n");
    if (i == 2) {
      abort();
    }
  }
  sigprocmask(SIG_UNBLOCK, &set, NULL);
  for (i = 0; i < 5; i++) {
    sleep(1);
    printf("state:unblock\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11f9 <main+0x99>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x2,-0x1c(%rbp)
jne    11e6 <main+0x86>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    11eb <main+0x8b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <main+0x55>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    1244 <main+0xe4>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1216 <main+0xb6>
xor    %eax,%eax
add    $0x20,%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    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    0xe59(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@SIGABRT = global i32 0
@SIG_BLOCK = global i32 0
@.str = [13 x i8] c"state:block\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [15 x i8] c"state:unblock\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = call i32 @sigemptyset(i32* %6)
%10 = load i32, i32* @SIGABRT
%11 = call i32 @sigaddset(i32* %6, i32 %10)
%12 = load i32, i32* @SIG_BLOCK
%13 = call i32 @sigprocmask(i32 %12, i32* %6, i32* null)
store i32 0, i32* %8
br label %14
14: ; preds = %25, %2
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = call i32 @sleep(i32 1)
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %17
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %14
28: ; preds = %14
%29 = load i32, i32* @SIG_UNBLOCK
%30 = call i32 @sigprocmask(i32 %29, i32* %6, i32* null)
store i32 0, i32* %8
br label %31
31: ; preds = %37, %28
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 5
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = call i32 @sleep(i32 1)
%36 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %34
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %31
40: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
@SIGABRT = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@str = [12 x i8] c"state:block\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @sigemptyset(i32* %3)
%6 = load i32, i32* @SIGABRT
%7 = call i32 @sigaddset(i32* %3, i32 %6)
%8 = load i32, i32* @SIG_BLOCK
%9 = call i32 @sigprocmask(i32 %8, i32* %3, i32* null)
%10 = call i32 @sleep(i32 1)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%12 = call i32 @sleep(i32 1)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%14 = call i32 @sleep(i32 1)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%16 = call i32 (...) @abort()
unreachable
}