#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ __NR_getpid;
int /*<<< orphan*/ __NR_gettid;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int /*<<< orphan*/ wait4(int /*<<< orphan*/, int *, int /*<<< orphan*/,
                         int /*<<< orphan*/ *);
int main() {
  pid_t child;
  int status;
  child = fork();
  if (!child) {
    int i = 0xfffff;
    while (i > 0)
      i--;
    exit(0);
  }
  wait4(child, &status, WNOHANG, NULL);
  syscall(__NR_getpid);
  getppid();
  syscall(__NR_gettid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1199 <main+0x49>
movl   $0xfffff,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1192 <main+0x42>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <main+0x2a>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <wait4@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1030 <syscall@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1030 <syscall@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     119a <main+0x4a>
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%edx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %ecx,%ecx
call   1040 <wait4@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1030 <syscall@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <syscall@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@WNOHANG = global i32 0
@__NR_getpid = global i32 0
@__NR_gettid = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %0
store i32 1048575, i32* %4
br label %9
9: ; preds = %12, %8
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
br label %9
15: ; preds = %9
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = load i32, i32* %2
%19 = load i32, i32* @WNOHANG
%20 = call i32 @wait4(i32 %18, i32* %3, i32 %19, i32* null)
%21 = load i32, i32* @__NR_getpid
%22 = call i32 @syscall(i32 %21)
%23 = call i32 (...) @getppid()
%24 = load i32, i32* @__NR_gettid
%25 = call i32 @syscall(i32 %24)
ret i32 0
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@__NR_getpid = global i32 0
@__NR_gettid = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = load i32, i32* @WNOHANG
%9 = call i32 @wait4(i32 %3, i32* %1, i32 %8, i32* null)
%10 = load i32, i32* @__NR_getpid
%11 = call i32 @syscall(i32 %10)
%12 = call i32 (...) @getppid()
%13 = load i32, i32* @__NR_gettid
%14 = call i32 @syscall(i32 %13)
ret i32 0
}