#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 SIGTERM;
int /*<<< orphan*/ SIG_BLOCK;
int WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ childprocess();
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ kill(int, int);
scalar_t__ pthread_sigmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
scalar_t__ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  sigset_t sigmask;
  if (sigfillset(&sigmask)) {
    fprintf(stderr, "Error line %u\n", 51);
    return 255;
  }
  if (pthread_sigmask(SIG_BLOCK, &sigmask, 0)) {
    fprintf(stderr, "Error line %u\n", 57);
    return 255;
  }
  int childpid = fork();
  if (-1 == childpid) {
    fprintf(stderr, "Error line %u\n", 65);
    return 255;
  }
  if (!childpid)
    childprocess();
  if (kill(childpid, SIGTERM)) {
    fprintf(stderr, "Error line %u\n", 74);
    return 255;
  }
  int status;
  if (childpid != waitpid(childpid, &status, 0)) {
    fprintf(stderr, "Error line %u\n", 81);
    return 255;
  }
  assert(WIFSIGNALED(status));
  fprintf(stderr, "Signal %d\n", WTERMSIG(status));
  assert(WTERMSIG(status) == SIGTERM);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <sigfillset@plt>
cmp    $0x0,%rax
je     11ef <main+0x4f>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    $0x33,%edx
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1363 <main+0x1c3>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   10a0 <pthread_sigmask@plt>
cmp    $0x0,%rax
je     1233 <main+0x93>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x39,%edx
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1363 <main+0x1c3>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
jne    1271 <main+0xd1>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x41,%edx
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1363 <main+0x1c3>
cmpl   $0x0,-0x18(%rbp)
jne    1282 <main+0xe2>
mov    $0x0,%al
call   1080 <childprocess@plt>
mov    -0x18(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
cmp    $0x0,%rax
je     12c3 <main+0x123>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
mov    $0x4a,%edx
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1363 <main+0x1c3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
je     130a <main+0x16a>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd0c(%rip),%rsi
mov    $0x51,%edx
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1363 <main+0x1c3>
mov    -0x1c(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <WTERMSIG@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xcd6(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <WTERMSIG@plt>
mov    0x2c9b(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1060 <sigfillset@plt>
test   %rax,%rax
je     11ce <main+0x2e>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    $0x33,%edx
jmp    11fd <main+0x5d>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   10a0 <pthread_sigmask@plt>
test   %rax,%rax
je     1212 <main+0x72>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    $0x39,%edx
call   1050 <fprintf@plt>
mov    $0xff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     123b <main+0x9b>
cmp    $0xffffffff,%ebp
jne    1242 <main+0xa2>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x41,%edx
jmp    11fd <main+0x5d>
xor    %eax,%eax
call   1080 <childprocess@plt>
mov    0x2d9f(%rip),%r14
mov    (%r14),%esi
mov    %ebp,%edi
call   1070 <kill@plt>
test   %rax,%rax
je     126f <main+0xcf>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
mov    $0x4a,%edx
jmp    11fd <main+0x5d>
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmp    %eax,%ebp
jne    12d1 <main+0x131>
mov    0x8(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsp),%edi
call   1090 <WTERMSIG@plt>
lea    0xd63(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    0x8(%rsp),%edi
call   1090 <WTERMSIG@plt>
xor    %edi,%edi
cmp    (%r14),%eax
sete   %dil
call   1040 <assert@plt>
jmp    1207 <main+0x67>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
mov    $0x51,%edx
jmp    11fd <main+0x5d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"Error line %u\0A\00"
@SIG_BLOCK = global i32 0
@SIGTERM = global i32 0
@.str.1 = [11 x i8] c"Signal %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @sigfillset(i32* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 51)
store i32 255, i32* %3
br label %63
14: ; preds = %2
%15 = load i32, i32* @SIG_BLOCK
%16 = call i64 @pthread_sigmask(i32 %15, i32* %6, i32 0)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 57)
store i32 255, i32* %3
br label %63
21: ; preds = %14
%22 = call i32 (...) @fork()
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 65)
store i32 255, i32* %3
br label %63
28: ; preds = %21
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (...) @childprocess()
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %7
%35 = load i32, i32* @SIGTERM
%36 = call i64 @kill(i32 %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 74)
store i32 255, i32* %3
br label %63
41: ; preds = %33
%42 = load i32, i32* %7
%43 = load i32, i32* %7
%44 = call i32 @waitpid(i32 %43, i32* %8, i32 0)
%45 = icmp ne i32 %42, %44
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 81)
store i32 255, i32* %3
br label %63
49: ; preds = %41
%50 = load i32, i32* %8
%51 = call i32 @WIFSIGNALED(i32 %50)
%52 = call i32 @assert(i32 %51)
%53 = load i32, i32* @stderr
%54 = load i32, i32* %8
%55 = call i32 @WTERMSIG(i32 %54)
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %8
%58 = call i32 @WTERMSIG(i32 %57)
%59 = load i32, i32* @SIGTERM
%60 = icmp eq i32 %58, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
store i32 0, i32* %3
br label %63
63: ; preds = %49, %46, %38, %25, %18, %11
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"Error line %u\0A\00"
@SIG_BLOCK = global i32 0
@SIGTERM = global i32 0
@.str.1 = [11 x i8] c"Signal %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = call i64 @sigfillset(i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 51)
br label %55
11: ; preds = %2
%12 = load i32, i32* @SIG_BLOCK
%13 = call i64 @pthread_sigmask(i32 %12, i32* %3, i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 57)
br label %55
18: ; preds = %11
%19 = call i32 (...) @fork()
switch i32 %19, label %25 [
i32 -1, label %20
i32 0, label %23
]
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 65)
br label %55
23: ; preds = %18
%24 = call i32 (...) @childprocess()
br label %25
25: ; preds = %18, %23
%26 = load i32, i32* @SIGTERM
%27 = call i64 @kill(i32 %19, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 74)
br label %55
32: ; preds = %25
%33 = bitcast i32* %4 to i8*
%34 = call i32 @waitpid(i32 %19, i32* %4, i32 0)
%35 = icmp eq i32 %19, %34
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 81)
br label %53
39: ; preds = %32
%40 = load i32, i32* %4
%41 = call i32 @WIFSIGNALED(i32 %40)
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* @stderr
%44 = load i32, i32* %4
%45 = call i32 @WTERMSIG(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %4
%48 = call i32 @WTERMSIG(i32 %47)
%49 = load i32, i32* @SIGTERM
%50 = icmp eq i32 %48, %49
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
br label %53
53: ; preds = %39, %36
%54 = phi i32 [ 255, %36 ], [ 0, %39 ]
br label %55
55: ; preds = %20, %29, %53, %15, %8
%56 = phi i32 [ 255, %8 ], [ 255, %15 ], [ 255, %20 ], [ 255, %29 ], [ %54, %53 ]
ret i32 %56
}