#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 */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  int status;
  pid_t pid;
  if (fork() == 0) {
    pid = fork();
    printf("HC: %d\n", getpid());
    if (pid == 0) {
      exit(0);
    }
  }
  pid = wait(&status);
  printf("BT: %d\n", pid);
  exit(0);
}


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    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11af <main+0x5f>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
movslq %eax,%rsi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11aa <main+0x5a>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11af <main+0x5f>
lea    -0x14(%rbp),%rdi
call   1060 <wait@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    118d <main+0x3d>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
movslq %eax,%rsi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
test   %rbx,%rbx
jne    118d <main+0x3d>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
lea    0xe6a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"HC: %d\0A\00"
@.str.1 = [8 x i8] c"BT: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = call i64 (...) @fork()
store i64 %11, i64* %7
%12 = call i32 (...) @getpid()
%13 = sext i32 %12 to i64
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %10
br label %20
20: ; preds = %19, %2
%21 = call i64 @wait(i32* %6)
store i64 %21, i64* %7
%22 = load i64, i64* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"HC: %d\0A\00"
@.str.1 = [8 x i8] c"BT: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = tail call i64 (...) @fork()
%9 = tail call i32 (...) @getpid()
%10 = sext i32 %9 to i64
%11 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = icmp eq i64 %8, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %7, %2
%16 = call i64 @wait(i32* %3)
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%18 = call i32 @exit(i32 0)
unreachable
}