#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*/ SIGTRAP;
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  sigset_t ss;
  struct sigaction sa;
  fprintf(stderr, "starting kid\n");
  sleep(5);
  fprintf(stderr, "unblocking SIGTRAP\n");
  sigemptyset(&ss);
  sigaddset(&ss, SIGTRAP);
  if (-1 == sigprocmask(SIG_UNBLOCK, &ss, 0))
    perror("block failed");
  sleep(5);
  fprintf(stderr, "kid exiting\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)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x14(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1080 <sigaddset@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f4 <main+0x94>
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%r14
mov    (%r14),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    (%r14),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <sigaddset@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11ec <main+0x8c>
mov    $0x5,%edi
call   1070 <sleep@plt>
mov    (%r14),%edi
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2f(%rip),%rdi
call   1060 <perror@plt>
jmp    11c9 <main+0x69>

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@stderr = global i32 0
@.str = [14 x i8] c"starting kid\0A\00"
@.str.1 = [20 x i8] c"unblocking SIGTRAP\0A\00"
@SIGTRAP = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.2 = [13 x i8] c"block failed\00"
@.str.3 = [13 x i8] c"kid exiting\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sigaction
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @sleep(i32 5)
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @sigemptyset(i32* %6)
%14 = load i32, i32* @SIGTRAP
%15 = call i32 @sigaddset(i32* %6, i32 %14)
%16 = load i32, i32* @SIG_UNBLOCK
%17 = call i32 @sigprocmask(i32 %16, i32* %6, i32 0)
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = call i32 @sleep(i32 5)
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"starting kid\0A\00"
@.str.1 = [20 x i8] c"unblocking SIGTRAP\0A\00"
@SIGTRAP = global i32 0
@SIG_UNBLOCK = global i32 0
@.str.2 = [13 x i8] c"block failed\00"
@.str.3 = [13 x i8] c"kid exiting\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @sleep(i32 5)
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @sigemptyset(i32* %3)
%11 = load i32, i32* @SIGTRAP
%12 = call i32 @sigaddset(i32* %3, i32 %11)
%13 = load i32, i32* @SIG_UNBLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %3, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 @sleep(i32 5)
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}