#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 atoi(char *);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigdelset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sigpending(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main() {
  sigset_t mascara;
  sigemptyset(&mascara);
  sigaddset(&mascara, SIGINT);
  sigaddset(&mascara, SIGTSTP);
  if (sigprocmask(SIG_BLOCK, &mascara, NULL) == -1) {
    perror("No se puede borrar las señales");
    return -1;
  }
  char *sleep_secs = getenv("SLEEP_SECS");
  if (sleep_secs == NULL) {
    printf("No se puede leer SLEEP_SECS\n");
    return -1;
  }
  int secs = atoi(sleep_secs);
  if (secs < 0)
    secs = 0;
  sigset_t pendiente;
  sigemptyset(&pendiente);
  if (sigpending(&pendiente) == -1) {
    perror("No hay señales pendientes");
    return -1;
  }
  switch (sigismember(&pendiente, SIGINT)) {
  case 1:
    printf("Se ha recibido SIGINT durante sleep\n");
    break;
  case -1:
    perror("No hay señal pendiente SIGINT");
    return -1;
    break;
  }
  switch (sigismember(&pendiente, SIGTSTP)) {
  case 1:
    printf("Se ha recibido SIGTSTP durante sleep, desbloqueando señal...\n");
    sigdelset(&mascara, SIGINT);
    if (sigprocmask(SIG_UNBLOCK, &mascara, NULL) == -1) {
      perror("No se puede desbloquear las señales");
      return -1;
    }
    break;
  case -1:
    perror("No hay señal pendiente SIGTSTP");
    return -1;
    break;
  }
  printf("Termino el programa\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1213 <main+0x73>
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
lea    0xe06(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1246 <main+0xa6>
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    -0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1263 <main+0xc3>
movl   $0x0,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <sigemptyset@plt>
lea    -0x18(%rbp),%rdi
call   1090 <sigpending@plt>
cmp    $0xffffffff,%eax
jne    1296 <main+0xf6>
lea    0xdc3(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   10b0 <sigismember@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     12dd <main+0x13d>
jmp    12bb <main+0x11b>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
jne    12f5 <main+0x155>
jmp    12cc <main+0x12c>
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
jmp    12f5 <main+0x155>
lea    0xda4(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   10b0 <sigismember@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0xffffffff,%eax
je     1385 <main+0x1e5>
jmp    131a <main+0x17a>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
jne    139d <main+0x1fd>
jmp    132b <main+0x18b>
lea    0xd75(%rip),%rdi
call   1050 <printf@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1070 <sigdelset@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    1380 <main+0x1e0>
lea    0xd77(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
jmp    139d <main+0x1fd>
lea    0xd7f(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b0 <main+0x210>
lea    0xd87(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
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),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10b0 <sigaddset@plt>
mov    0x2e19(%rip),%r15
mov    (%r15),%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>
cmp    $0xffffffff,%eax
je     12b9 <main+0x129>
lea    0xf39(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1238 <main+0xa8>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sigemptyset@plt>
mov    %rbx,%rdi
call   1090 <sigpending@plt>
cmp    $0xffffffff,%eax
je     12c2 <main+0x132>
mov    (%r14),%esi
lea    0x8(%rsp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x1,%eax
je     1249 <main+0xb9>
cmp    $0xffffffff,%eax
jne    1255 <main+0xc5>
lea    0xe08(%rip),%rdi
jmp    12d2 <main+0x142>
lea    0xed6(%rip),%rdi
call   1050 <puts@plt>
jmp    12d7 <main+0x147>
lea    0xe4f(%rip),%rdi
call   1050 <puts@plt>
mov    (%r15),%esi
lea    0x8(%rsp),%rdi
call   10a0 <sigismember@plt>
cmp    $0x1,%eax
je     1275 <main+0xe5>
cmp    $0xffffffff,%eax
jne    12a9 <main+0x119>
lea    0xe0c(%rip),%rdi
jmp    12d2 <main+0x142>
lea    0xe47(%rip),%rdi
call   1050 <puts@plt>
mov    (%r14),%esi
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sigdelset@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     12cb <main+0x13b>
lea    0xe51(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    12dc <main+0x14c>
lea    0xd40(%rip),%rdi
jmp    12d2 <main+0x142>
lea    0xd57(%rip),%rdi
jmp    12d2 <main+0x142>
lea    0xd88(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%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 = [32 x i8] c"No se puede borrar las se\C3\B1ales\00"
@.str.1 = [11 x i8] c"SLEEP_SECS\00"
@.str.2 = [29 x i8] c"No se puede leer SLEEP_SECS\0A\00"
@.str.3 = [27 x i8] c"No hay se\C3\B1ales pendientes\00"
@.str.4 = [37 x i8] c"Se ha recibido SIGINT durante sleep\0A\00"
@.str.5 = [31 x i8] c"No hay se\C3\B1al pendiente SIGINT\00"
@.str.6 = [63 x i8] c"Se ha recibido SIGTSTP durante sleep, desbloqueando se\C3\B1al...\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.7 = [37 x i8] c"No se puede desbloquear las se\C3\B1ales\00"
@.str.8 = [32 x i8] c"No hay se\C3\B1al pendiente SIGTSTP\00"
@.str.9 = [21 x i8] c"Termino el programa\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @sigemptyset(i32* %2)
%7 = load i32, i32* @SIGINT
%8 = call i32 @sigaddset(i32* %2, i32 %7)
%9 = load i32, i32* @SIGTSTP
%10 = call i32 @sigaddset(i32* %2, i32 %9)
%11 = load i32, i32* @SIG_BLOCK
%12 = call i32 @sigprocmask(i32 %11, i32* %2, i32* null)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
16: ; preds = %0
%17 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 0, i32* %4
br label %28
28: ; preds = %27, %22
%29 = call i32 @sigemptyset(i32* %5)
%30 = call i32 @sigpending(i32* %5)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
34: ; preds = %28
%35 = load i32, i32* @SIGINT
%36 = call i32 @sigismember(i32* %5, i32 %35)
switch i32 %36, label %41 [
i32 1, label %37
i32 -1, label %39
]
37: ; preds = %34
%38 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %41
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
41: ; preds = %34, %37
%42 = load i32, i32* @SIGTSTP
%43 = call i32 @sigismember(i32* %5, i32 %42)
switch i32 %43, label %56 [
i32 1, label %44
i32 -1, label %54
]
44: ; preds = %41
%45 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32, i32* @SIGINT
%47 = call i32 @sigdelset(i32* %2, i32 %46)
%48 = load i32, i32* @SIG_UNBLOCK
%49 = call i32 @sigprocmask(i32 %48, i32* %2, i32* null)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
53: ; preds = %44
br label %56
54: ; preds = %41
%55 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %1
br label %58
56: ; preds = %41, %53
%57 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %58
58: ; preds = %56, %54, %51, %39, %32, %20, %14
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str = [32 x i8] c"No se puede borrar las se\C3\B1ales\00"
@.str.1 = [11 x i8] c"SLEEP_SECS\00"
@.str.3 = [27 x i8] c"No hay se\C3\B1ales pendientes\00"
@.str.5 = [31 x i8] c"No hay se\C3\B1al pendiente SIGINT\00"
@SIG_UNBLOCK = global i32 0
@.str.7 = [37 x i8] c"No se puede desbloquear las se\C3\B1ales\00"
@.str.8 = [32 x i8] c"No hay se\C3\B1al pendiente SIGTSTP\00"
@str = [36 x i8] c"Se ha recibido SIGINT durante sleep\00"
@str.10 = [62 x i8] c"Se ha recibido SIGTSTP durante sleep, desbloqueando se\C3\B1al...\00"
@str.11 = [20 x i8] c"Termino el programa\00"
@str.12 = [28 x i8] c"No se puede leer SLEEP_SECS\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @sigemptyset(i32* %1)
%5 = load i32, i32* @SIGINT
%6 = call i32 @sigaddset(i32* %1, i32 %5)
%7 = load i32, i32* @SIGTSTP
%8 = call i32 @sigaddset(i32* %1, i32 %7)
%9 = load i32, i32* @SIG_BLOCK
%10 = call i32 @sigprocmask(i32 %9, i32* %1, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %51
14: ; preds = %0
%15 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.12, i64 0, i64 0))
br label %51
19: ; preds = %14
%20 = bitcast i32* %2 to i8*
%21 = call i32 @sigemptyset(i32* %2)
%22 = call i32 @sigpending(i32* %2)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %49
26: ; preds = %19
%27 = load i32, i32* @SIGINT
%28 = call i32 @sigismember(i32* %2, i32 %27)
switch i32 %28, label %33 [
i32 1, label %29
i32 -1, label %31
]
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %49
33: ; preds = %26, %29
%34 = load i32, i32* @SIGTSTP
%35 = call i32 @sigismember(i32* %2, i32 %34)
switch i32 %35, label %47 [
i32 1, label %36
i32 -1, label %45
]
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.10, i64 0, i64 0))
%38 = load i32, i32* @SIGINT
%39 = call i32 @sigdelset(i32* %1, i32 %38)
%40 = load i32, i32* @SIG_UNBLOCK
%41 = call i32 @sigprocmask(i32 %40, i32* %1, i32* null)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %49
45: ; preds = %33
%46 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
br label %49
47: ; preds = %36, %33
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
br label %49
49: ; preds = %47, %45, %43, %31, %24
%50 = phi i32 [ -1, %24 ], [ 0, %47 ], [ -1, %45 ], [ -1, %43 ], [ -1, %31 ]
br label %51
51: ; preds = %17, %49, %12
%52 = phi i32 [ -1, %12 ], [ -1, %17 ], [ %50, %49 ]
ret i32 %52
}