#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 */
struct sigaction {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigpending(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  sigset_t set, pendingset;
  struct sigaction action;
  sigemptyset(&set);
  sigaddset(&set, SIGTERM);
  sigprocmask(SIG_BLOCK, &set, NULL);
  kill(getpid(), SIGTERM);
  sigpending(&pendingset);
  if (sigismember(&pendingset, SIGTERM)) {
    printf("INFO: The SIGTERM is been blocked!\n");
  }
  sigprocmask(SIG_UNBLOCK, &set, NULL);
  int cntdwn = 5;
  while (cntdwn--) {
    printf("INFO: Count down to exit! : %d\n", cntdwn);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   10b0 <sigaddset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
lea    -0x18(%rbp),%rdi
call   1080 <sigpending@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1090 <sigismember@plt>
cmp    $0x0,%rax
je     1221 <main+0x91>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
movl   $0x5,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     1272 <main+0xe2>
mov    -0x24(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    123e <main+0xae>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sigemptyset@plt>
mov    0x2e2a(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10c0 <sigaddset@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1080 <kill@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <sigpending@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   10a0 <sigismember@plt>
test   %rax,%rax
je     120e <main+0x6e>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    0xdd8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@.str = [36 x i8] c"INFO: The SIGTERM is been blocked!\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [32 x i8] c"INFO: Count down to exit! : %d\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 %struct.sigaction
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @sigemptyset(i32* %6)
%11 = load i32, i32* @SIGTERM
%12 = call i32 @sigaddset(i32* %6, i32 %11)
%13 = load i32, i32* @SIG_BLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %6, i32* null)
%15 = call i32 (...) @getpid()
%16 = load i32, i32* @SIGTERM
%17 = call i32 @kill(i32 %15, i32 %16)
%18 = call i32 @sigpending(i32* %7)
%19 = load i32, i32* @SIGTERM
%20 = call i64 @sigismember(i32* %7, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* @SIG_UNBLOCK
%26 = call i32 @sigprocmask(i32 %25, i32* %6, i32* null)
store i32 5, i32* %9
br label %27
27: ; preds = %31, %24
%28 = load i32, i32* %9
%29 = add nsw i32 %28, -1
store i32 %29, i32* %9
%30 = icmp ne i32 %28, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* %9
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i32 @sleep(i32 1)
br label %27
35: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIG_BLOCK = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.1 = [32 x i8] c"INFO: Count down to exit! : %d\0A\00"
@str = [35 x i8] c"INFO: The SIGTERM is been blocked!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @sigemptyset(i32* %3)
%8 = load i32, i32* @SIGTERM
%9 = call i32 @sigaddset(i32* %3, i32 %8)
%10 = load i32, i32* @SIG_BLOCK
%11 = call i32 @sigprocmask(i32 %10, i32* %3, i32* null)
%12 = call i32 (...) @getpid()
%13 = load i32, i32* @SIGTERM
%14 = call i32 @kill(i32 %12, i32 %13)
%15 = call i32 @sigpending(i32* %4)
%16 = load i32, i32* @SIGTERM
%17 = call i64 @sigismember(i32* %4, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* @SIG_UNBLOCK
%23 = call i32 @sigprocmask(i32 %22, i32* %3, i32* null)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = call i32 @sleep(i32 1)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 3)
%27 = call i32 @sleep(i32 1)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 2)
%29 = call i32 @sleep(i32 1)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 1)
%31 = call i32 @sleep(i32 1)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 0)
%33 = call i32 @sleep(i32 1)
ret i32 0
}