#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*/ SIGINT;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
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[]) {
  int cntdwn = 6;
  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, SIGINT);
  sigprocmask(SIG_BLOCK, &set, NULL);
  printf("WARN: mask the SIGINT.\n");
  while (cntdwn--) {
    printf("INFO: Count down to Exit! : %d\n", cntdwn);
    sleep(1);
  }
  sigprocmask(SIG_UNBLOCK, &set, NULL);
  printf("INFO: Demo Exit!\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   $0x6,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11e0 <main+0x90>
mov    -0x14(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11ac <main+0x5c>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <sigaddset@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
lea    0xe58(%rip),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    0xde2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIG_BLOCK = global i32 0
@.str = [24 x i8] c"WARN: mask the SIGINT.\0A\00"
@.str.1 = [32 x i8] c"INFO: Count down to Exit! : %d\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.2 = [18 x i8] c"INFO: Demo Exit!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6, i32* %6
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGINT
%10 = call i32 @sigaddset(i32* %7, i32 %9)
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %7, i32* null)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %18, %2
%15 = load i32, i32* %6
%16 = add nsw i32 %15, -1
store i32 %16, i32* %6
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 @sleep(i32 1)
br label %14
22: ; preds = %14
%23 = load i32, i32* @SIG_UNBLOCK
%24 = call i32 @sigprocmask(i32 %23, i32* %7, i32* null)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIG_BLOCK = global i32 0
@.str.1 = [32 x i8] c"INFO: Count down to Exit! : %d\0A\00"
@SIG_UNBLOCK = global i32 0
@str = [23 x i8] c"WARN: mask the SIGINT.\00"
@str.3 = [17 x i8] c"INFO: Demo Exit!\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* @SIGINT
%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 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 5)
%12 = call i32 @sleep(i32 1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = call i32 @sleep(i32 1)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = call i32 @sleep(i32 1)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 2)
%18 = call i32 @sleep(i32 1)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 1)
%20 = call i32 @sleep(i32 1)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 0)
%22 = call i32 @sleep(i32 1)
%23 = load i32, i32* @SIG_UNBLOCK
%24 = call i32 @sigprocmask(i32 %23, i32* %3, i32* null)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}