#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*/ SIGTSTP;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ atoi(int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
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 /*<<< orphan*/);
int main(int argc, char **argv) {
  sigset_t blk_grupo;
  sigemptyset(&blk_grupo);
  sigaddset(&blk_grupo, SIGINT);
  sigaddset(&blk_grupo, SIGTSTP);
  sigprocmask(SIG_BLOCK, &blk_grupo, NULL);
  printf("Sleeping\n");
  sleep(atoi(getenv("SLEEP_SECS")));
  sigpending(&blk_grupo);
  if (sigismember(&blk_grupo, SIGINT))
    printf("SIGINT received\n");
  if (sigismember(&blk_grupo, SIGTSTP))
    printf("SIGTSTP received\n");
  sigprocmask(SIG_UNBLOCK, &blk_grupo, NULL);
  printf("Last message. Bye bye.\n");
}


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)
lea    -0x14(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   10b0 <sigaddset@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   10b0 <sigaddset@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
lea    0xe0e(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,%edi
call   10a0 <sleep@plt>
lea    -0x14(%rbp),%rdi
call   1070 <sigpending@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1090 <sigismember@plt>
cmp    $0x0,%rax
je     1240 <main+0xb0>
lea    0xdda(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1090 <sigismember@plt>
cmp    $0x0,%rax
je     1268 <main+0xd8>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
lea    0xdb3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e33(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   10b0 <sigaddset@plt>
mov    0x2e19(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10b0 <sigaddset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
lea    0xe27(%rip),%rdi
call   1050 <puts@plt>
lea    0xe10(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
mov    %eax,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
call   1070 <sigpending@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1090 <sigismember@plt>
test   %rax,%rax
je     1227 <main+0x97>
lea    0xe1a(%rip),%rdi
call   1050 <puts@plt>
mov    (%r14),%esi
lea    0xc(%rsp),%rdi
call   1090 <sigismember@plt>
test   %rax,%rax
je     1245 <main+0xb5>
lea    0xdeb(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
lea    0xdb3(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str = [10 x i8] c"Sleeping\0A\00"
@.str.1 = [11 x i8] c"SLEEP_SECS\00"
@.str.2 = [17 x i8] c"SIGINT received\0A\00"
@.str.3 = [18 x i8] c"SIGTSTP received\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.4 = [24 x i8] c"Last message. Bye bye.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @sigemptyset(i32* %6)
%8 = load i32, i32* @SIGINT
%9 = call i32 @sigaddset(i32* %6, i32 %8)
%10 = load i32, i32* @SIGTSTP
%11 = call i32 @sigaddset(i32* %6, i32 %10)
%12 = load i32, i32* @SIG_BLOCK
%13 = call i32 @sigprocmask(i32 %12, i32* %6, i32* null)
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @atoi(i32 %15)
%17 = call i32 @sleep(i32 %16)
%18 = call i32 @sigpending(i32* %6)
%19 = load i32, i32* @SIGINT
%20 = call i64 @sigismember(i32* %6, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* @SIGTSTP
%26 = call i64 @sigismember(i32* %6, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* @SIG_UNBLOCK
%32 = call i32 @sigprocmask(i32 %31, i32* %6, i32* null)
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str.1 = [11 x i8] c"SLEEP_SECS\00"
@SIG_UNBLOCK = global i32 0
@str = [9 x i8] c"Sleeping\00"
@str.5 = [23 x i8] c"Last message. Bye bye.\00"
@str.6 = [17 x i8] c"SIGTSTP received\00"
@str.7 = [16 x i8] c"SIGINT received\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* @SIGTSTP
%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 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%13 = call i32 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @atoi(i32 %13)
%15 = call i32 @sleep(i32 %14)
%16 = call i32 @sigpending(i32* %3)
%17 = load i32, i32* @SIGINT
%18 = call i64 @sigismember(i32* %3, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32, i32* @SIGTSTP
%24 = call i64 @sigismember(i32* %3, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @SIG_UNBLOCK
%30 = call i32 @sigprocmask(i32 %29, i32* %3, i32* null)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}