#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ READ();
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ WRITE(scalar_t__);
int /*<<< orphan*/ e(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ setsid();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
void test_tracefork_child() {
  pid_t pid;
  signal(SIGHUP, SIG_IGN);
  pid = setsid();
  WRITE(pid);
  if (READ() != 0)
    e(100);
  if ((pid = fork()) < 0)
    e(101);
  exit(pid > 0 ? 42 : 84);
}


x86 assembly (clang, -O0):
<test_tracefork_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <WRITE@plt>
mov    $0x0,%al
call   1030 <READ@plt>
cmp    $0x0,%rax
je     11be <test_tracefork_child+0x4e>
mov    $0x64,%edi
call   1060 <e@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jge    11dd <test_tracefork_child+0x6d>
mov    $0x65,%edi
call   1060 <e@plt>
mov    -0x8(%rbp),%rcx
mov    $0x54,%edi
mov    $0x2a,%eax
cmp    $0x0,%rcx
cmovg  %eax,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<test_tracefork_child>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
xor    %eax,%eax
call   1040 <setsid@plt>
mov    %rax,%rdi
call   1080 <WRITE@plt>
xor    %eax,%eax
call   1030 <READ@plt>
test   %rax,%rax
je     11ad <test_tracefork_child+0x3d>
mov    $0x64,%edi
call   1060 <e@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    11c6 <test_tracefork_child+0x56>
mov    $0x65,%edi
call   1060 <e@plt>
test   %rbx,%rbx
mov    $0x2a,%eax
mov    $0x54,%edi
cmovg  %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
define void @test_tracefork_child() {
%1 = alloca i64
%2 = load i32, i32* @SIGHUP
%3 = load i32, i32* @SIG_IGN
%4 = call i32 @signal(i32 %2, i32 %3)
%5 = call i64 (...) @setsid()
store i64 %5, i64* %1
%6 = load i64, i64* %1
%7 = call i32 @WRITE(i64 %6)
%8 = call i64 (...) @READ()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @e(i32 100)
br label %12
12: ; preds = %10, %0
%13 = call i64 (...) @fork()
store i64 %13, i64* %1
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @e(i32 101)
br label %17
17: ; preds = %15, %12
%18 = load i64, i64* %1
%19 = icmp sgt i64 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 42, i32 84
%22 = call i32 @exit(i32 %21)
unreachable
}

LLVM IR (-O2):
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
define void @test_tracefork_child() {
%1 = load i32, i32* @SIGHUP
%2 = load i32, i32* @SIG_IGN
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = tail call i64 (...) @setsid()
%5 = tail call i32 @WRITE(i64 %4)
%6 = tail call i64 (...) @READ()
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 @e(i32 100)
br label %10
10: ; preds = %8, %0
%11 = tail call i64 (...) @fork()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @e(i32 101)
br label %15
15: ; preds = %13, %10
%16 = icmp sgt i64 %11, 0
%17 = select i1 %16, i32 42, i32 84
%18 = tail call i32 @exit(i32 %17)
unreachable
}