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

/* Variables and functions */
scalar_t__ fork();
int getpgrp();
int getpid();
int /*<<< orphan*/ printf(char *, int, int);
void fork16() {
  if (fork() == 0) {
    printf("Child1: pid=%d pgrp=%d\n", getpid(), getpgrp());
    if (fork() == 0)
      printf("Child2: pid=%d pgrp=%d\n", getpid(), getpgrp());
    while (1)
      ;
  }
}


x86 assembly (clang, -O0):
<fork16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11b8 <fork16+0x78>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getpgrp@plt>
mov    -0x4(%rbp),%esi
mov    %eax,%edx
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11ae <fork16+0x6e>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getpgrp@plt>
mov    -0x8(%rbp),%esi
mov    %eax,%edx
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
jmp    11b3 <fork16+0x73>
jmp    11b3 <fork16+0x73>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork16>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     114f <fork16+0xf>
pop    %rbx
ret
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getpgrp@plt>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    11a0 <fork16+0x60>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getpgrp@plt>
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
nopl   0x0(%rax,%rax,1)
jmp    11a0 <fork16+0x60>

LLVM IR (-O0):
@.str = [24 x i8] c"Child1: pid=%d pgrp=%d\0A\00"
@.str.1 = [24 x i8] c"Child2: pid=%d pgrp=%d\0A\00"
define void @fork16() {
%1 = call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %15
3: ; preds = %0
%4 = call i32 (...) @getpid()
%5 = call i32 (...) @getpgrp()
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = call i32 (...) @getpid()
%11 = call i32 (...) @getpgrp()
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
br label %13
13: ; preds = %9, %3
br label %14
14: ; preds = %13, %14
br label %14
15: ; preds = %0
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Child1: pid=%d pgrp=%d\0A\00"
@.str.1 = [24 x i8] c"Child2: pid=%d pgrp=%d\0A\00"
define void @fork16() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %15
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getpgrp()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (...) @getpgrp()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
br label %13
13: ; preds = %9, %3
br label %14
14: ; preds = %13, %14
br label %14
15: ; preds = %0
ret void
}