#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 */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
extern void child_code(int parent_pid, int delay) {
  if (getpid() != parent_pid || fork() != 0)
    return;
  printf("child %d here, will sleep for %d seconds\n", getpid(), delay);
  sleep(delay);
  printf("child: done, about to exit\n");
  exit(17);
}


x86 assembly (clang, -O0):
<child_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
cmp    -0x4(%rbp),%eax
jne    117f <child_code+0x2f>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1185 <child_code+0x35>
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <sleep@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x11,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<child_code>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
cmp    %ebp,%eax
jne    117e <child_code+0x1e>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1185 <child_code+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <sleep@plt>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x11,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"child %d here, will sleep for %d seconds\0A\00"
@.str.1 = [28 x i8] c"child: done, about to exit\0A\00"
define void @child_code(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 (...) @getpid()
%6 = load i32, i32* %3
%7 = icmp ne i32 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i64 (...) @fork()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %8, %2
ret void
12: ; preds = %8
%13 = call i32 (...) @getpid()
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %4
%17 = call i32 @sleep(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 17)
unreachable
}

LLVM IR (-O2):
@.str = [42 x i8] c"child %d here, will sleep for %d seconds\0A\00"
@str = [27 x i8] c"child: done, about to exit\00"
define void @child_code(i32 %0, i32 %1) {
%3 = tail call i32 (...) @getpid()
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %5, %2
ret void
9: ; preds = %5
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %1)
%12 = tail call i32 @sleep(i32 %1)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 17)
unreachable
}