#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 atoi(int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigdelset(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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int args, char *argv[]) {
  printf("Setting $SLEEP_SECS to %s\n", argv[1]);
  char buf[256];
  strcpy(buf, "SLEEP_SECS=");
  strcat(buf, argv[1]);
  putenv(buf);
  sigset_t set;
  sigset_t pending;
  sigemptyset(&set);
  sigaddset(&set, SIGINT);
  sigaddset(&set, SIGTSTP);
  sigprocmask(SIG_BLOCK, &set, NULL);
  int sleep_secs = atoi(getenv("SLEEP_SECS"));
  sleep(sleep_secs);
  sigpending(&pending);
  if (sigismember(&pending, SIGINT))
    printf("SIGINT recieved");
  if (sigismember(&pending, SIGTSTP)) {
    printf("SIGSTP recieved");
    printf("Unlocking SIGSTP, proccess will die");
    sigdelset(&set, SIGTSTP);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10c0 <strcat@plt>
lea    -0x110(%rbp),%rdi
call   1070 <putenv@plt>
lea    -0x114(%rbp),%rdi
call   1080 <sigemptyset@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x114(%rbp),%rdi
call   10f0 <sigaddset@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
lea    -0x114(%rbp),%rdi
call   10f0 <sigaddset@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    -0x114(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
lea    0xd9f(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
mov    %eax,-0x11c(%rbp)
mov    -0x11c(%rbp),%edi
call   10e0 <sleep@plt>
lea    -0x118(%rbp),%rdi
call   10a0 <sigpending@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    -0x118(%rbp),%rdi
call   10d0 <sigismember@plt>
cmp    $0x0,%rax
je     12de <main+0x10e>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
lea    -0x118(%rbp),%rdi
call   10d0 <sigismember@plt>
cmp    $0x0,%rax
je     132e <main+0x15e>
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
lea    -0x114(%rbp),%rdi
call   1090 <sigdelset@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe23(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   10c0 <strcat@plt>
mov    %r14,%rdi
call   1070 <putenv@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sigemptyset@plt>
mov    0x2dbb(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   10f0 <sigaddset@plt>
mov    0x2da1(%rip),%r14
mov    (%r14),%esi
mov    %rbx,%rdi
call   10f0 <sigaddset@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
lea    0xdc3(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   10e0 <sleep@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <sigpending@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   10d0 <sigismember@plt>
test   %rax,%rax
je     12a2 <main+0xd2>
lea    0xd97(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%esi
lea    0x8(%rsp),%rdi
call   10d0 <sigismember@plt>
test   %rax,%rax
je     12dd <main+0x10d>
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd89(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r14),%esi
lea    0xc(%rsp),%rdi
call   1090 <sigdelset@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Setting $SLEEP_SECS to %s\0A\00"
@.str.1 = [12 x i8] c"SLEEP_SECS=\00"
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str.2 = [11 x i8] c"SLEEP_SECS\00"
@.str.3 = [16 x i8] c"SIGINT recieved\00"
@.str.4 = [16 x i8] c"SIGSTP recieved\00"
@.str.5 = [36 x i8] c"Unlocking SIGSTP, proccess will die\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcat(i8* %16, i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @putenv(i8* %21)
%23 = call i32 @sigemptyset(i32* %7)
%24 = load i32, i32* @SIGINT
%25 = call i32 @sigaddset(i32* %7, i32 %24)
%26 = load i32, i32* @SIGTSTP
%27 = call i32 @sigaddset(i32* %7, i32 %26)
%28 = load i32, i32* @SIG_BLOCK
%29 = call i32 @sigprocmask(i32 %28, i32* %7, i32* null)
%30 = call i32 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @atoi(i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = call i32 @sleep(i32 %32)
%34 = call i32 @sigpending(i32* %8)
%35 = load i32, i32* @SIGINT
%36 = call i64 @sigismember(i32* %8, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %2
%41 = load i32, i32* @SIGTSTP
%42 = call i64 @sigismember(i32* %8, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @SIGTSTP
%48 = call i32 @sigdelset(i32* %7, i32 %47)
br label %49
49: ; preds = %44, %40
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [27 x i8] c"Setting $SLEEP_SECS to %s\0A\00"
@.str.1 = [12 x i8] c"SLEEP_SECS=\00"
@SIGINT = global i32 0
@SIGTSTP = global i32 0
@SIG_BLOCK = global i32 0
@.str.2 = [11 x i8] c"SLEEP_SECS\00"
@.str.3 = [16 x i8] c"SIGINT recieved\00"
@.str.4 = [16 x i8] c"SIGSTP recieved\00"
@.str.5 = [36 x i8] c"Unlocking SIGSTP, proccess will die\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %6
%12 = call i32 @strcat(i8* %9, i8* %11)
%13 = call i32 @putenv(i8* %9)
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
%16 = call i32 @sigemptyset(i32* %4)
%17 = load i32, i32* @SIGINT
%18 = call i32 @sigaddset(i32* %4, i32 %17)
%19 = load i32, i32* @SIGTSTP
%20 = call i32 @sigaddset(i32* %4, i32 %19)
%21 = load i32, i32* @SIG_BLOCK
%22 = call i32 @sigprocmask(i32 %21, i32* %4, i32* null)
%23 = call i32 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @atoi(i32 %23)
%25 = call i32 @sleep(i32 %24)
%26 = call i32 @sigpending(i32* %5)
%27 = load i32, i32* @SIGINT
%28 = call i64 @sigismember(i32* %5, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %2
%33 = load i32, i32* @SIGTSTP
%34 = call i64 @sigismember(i32* %5, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @SIGTSTP
%40 = call i32 @sigdelset(i32* %4, i32 %39)
br label %41
41: ; preds = %36, %32
ret i32 0
}