#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 errno;
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setenv(char *, char *, int);
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 /*<<< orphan*/ sscanf(char *, char *, int *);
char *strerror(int);
void main(int args, char *argv[]) {
  int errn;
  setenv("SLEEP_SECS", "7", 1);
  char *sleep_secs = getenv("SLEEP_SECS");
  if (sleep_secs == NULL) {
    errn = errno;
    printf("getenv:\t%s\n", strerror(errn));
  }
  int sl_sc;
  printf("sleep secs:\t%s\n", sleep_secs);
  sscanf(sleep_secs, "%d", &sl_sc);
  sigset_t set;
  sigset_t pending;
  sigemptyset(&set);
  sigaddset(&set, SIGINT);
  sigaddset(&set, SIGTSTP);
  sigprocmask(SIG_BLOCK, &set, NULL);
  printf("going to sleep\n");
  sleep(sl_sc);
  sigpending(&pending);
  if (sigismember(&pending, SIGINT))
    printf("SIGINT\n");
  if (sigismember(&pending, SIGTSTP)) {
    printf("SIGTSTP\n");
    sigemptyset(&set);
    sigaddset(&set, SIGINT);
    sigprocmask(SIG_BLOCK, &set, NULL);
  }
  printf("reanuda y muere\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe3a(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    0xe22(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1217 <main+0x67>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf5(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <sscanf@plt>
lea    -0x28(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10d0 <sigaddset@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10d0 <sigaddset@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%edi
call   10c0 <sleep@plt>
lea    -0x2c(%rbp),%rdi
call   1090 <sigpending@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x0,%rax
je     12c9 <main+0x119>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x0,%rax
je     1324 <main+0x174>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x28(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   10d0 <sigaddset@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe2e(%rip),%rbx
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1060 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1215 <main+0x55>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xe02(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdfc(%rip),%rsi
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
call   1090 <sscanf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2d9a(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10e0 <sigaddset@plt>
mov    0x2d80(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   10e0 <sigaddset@plt>
mov    0x2d55(%rip),%r15
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
lea    0xda5(%rip),%rdi
call   1050 <puts@plt>
mov    0x14(%rsp),%edi
call   10d0 <sleep@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <sigpending@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   10b0 <sigismember@plt>
test   %rax,%rax
je     12be <main+0xfe>
lea    0xd9a(%rip),%rdi
call   1050 <puts@plt>
mov    (%r12),%esi
lea    0xc(%rsp),%rdi
call   10b0 <sigismember@plt>
test   %rax,%rax
je     1302 <main+0x142>
lea    0xd73(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
call   10e0 <sigaddset@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
lea    0xd32(%rip),%rdi
call   1050 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"SLEEP_SECS\00"
@.str.1 = [2 x i8] c"7\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"getenv:\09%s\0A\00"
@.str.3 = [16 x i8] c"sleep secs:\09%s\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str.5 = [16 x i8] c"going to sleep\0A\00"
@.str.6 = [8 x i8] c"SIGINT\0A\00"
@.str.7 = [9 x i8] c"SIGTSTP\0A\00"
@.str.8 = [17 x i8] c"reanuda y muere\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @errno
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %2
%20 = load i8*, i8** %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%24 = call i32 @sigemptyset(i32* %8)
%25 = load i32, i32* @SIGINT
%26 = call i32 @sigaddset(i32* %8, i32 %25)
%27 = load i32, i32* @SIGTSTP
%28 = call i32 @sigaddset(i32* %8, i32 %27)
%29 = load i32, i32* @SIG_BLOCK
%30 = call i32 @sigprocmask(i32 %29, i32* %8, i32* null)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32, i32* %7
%33 = call i32 @sleep(i32 %32)
%34 = call i32 @sigpending(i32* %9)
%35 = load i32, i32* @SIGINT
%36 = call i64 @sigismember(i32* %9, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %19
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %19
%41 = load i32, i32* @SIGTSTP
%42 = call i64 @sigismember(i32* %9, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 @sigemptyset(i32* %8)
%47 = load i32, i32* @SIGINT
%48 = call i32 @sigaddset(i32* %8, i32 %47)
%49 = load i32, i32* @SIG_BLOCK
%50 = call i32 @sigprocmask(i32 %49, i32* %8, i32* null)
br label %51
51: ; preds = %44, %40
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"SLEEP_SECS\00"
@.str.1 = [2 x i8] c"7\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"getenv:\09%s\0A\00"
@.str.3 = [16 x i8] c"sleep secs:\09%s\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@str = [15 x i8] c"going to sleep\00"
@str.9 = [16 x i8] c"reanuda y muere\00"
@str.10 = [8 x i8] c"SIGTSTP\00"
@str.11 = [7 x i8] c"SIGINT\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %9, %2
%14 = bitcast i32* %3 to i8*
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%16 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%17 = bitcast i32* %4 to i8*
%18 = bitcast i32* %5 to i8*
%19 = call i32 @sigemptyset(i32* %4)
%20 = load i32, i32* @SIGINT
%21 = call i32 @sigaddset(i32* %4, i32 %20)
%22 = load i32, i32* @SIGTSTP
%23 = call i32 @sigaddset(i32* %4, i32 %22)
%24 = load i32, i32* @SIG_BLOCK
%25 = call i32 @sigprocmask(i32 %24, i32* %4, i32* null)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = call i32 @sleep(i32 %27)
%29 = call i32 @sigpending(i32* %5)
%30 = load i32, i32* @SIGINT
%31 = call i64 @sigismember(i32* %5, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %13
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
br label %35
35: ; preds = %33, %13
%36 = load i32, i32* @SIGTSTP
%37 = call i64 @sigismember(i32* %5, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.10, i64 0, i64 0))
%41 = call i32 @sigemptyset(i32* %4)
%42 = load i32, i32* @SIGINT
%43 = call i32 @sigaddset(i32* %4, i32 %42)
%44 = load i32, i32* @SIG_BLOCK
%45 = call i32 @sigprocmask(i32 %44, i32* %4, i32* null)
br label %46
46: ; preds = %39, %35
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
ret void
}