#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__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, scalar_t__);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t child_pid = fork();
  if (child_pid == 0) {
    sleep(1);
    printf("### Child ###\nCurrent PID: %d and Child PID: %d\n", getpid(),
           child_pid);
  } else {
    printf("### Parent ###\nCurrent PID: %d and Child PID: %d\n", getpid(),
           child_pid);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <main+0x4d>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
jmp    11a6 <main+0x66>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1165 <main+0x25>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xed3(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
jmp    1181 <main+0x41>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"### Child ###\0ACurrent PID: %d and Child PID: %d\0A\00"
@.str.1 = [50 x i8] c"### Parent ###\0ACurrent PID: %d and Child PID: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = call i32 @sleep(i32 1)
%8 = call i32 (...) @getpid()
%9 = load i64, i64* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %8, i64 %9)
br label %15
11: ; preds = %0
%12 = call i32 (...) @getpid()
%13 = load i64, i64* %2
%14 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %12, i64 %13)
br label %15
15: ; preds = %11, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"### Child ###\0ACurrent PID: %d and Child PID: %d\0A\00"
@.str.1 = [50 x i8] c"### Parent ###\0ACurrent PID: %d and Child PID: %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @sleep(i32 1)
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %5, i64 0)
br label %10
7: ; preds = %0
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %8, i64 %1)
br label %10
10: ; preds = %7, %3
ret i32 0
}