#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 fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int pid;
  pid = fork();
  if (pid == 0) {
    printf("\n\tI'm the child\nMy ID is %d and pid = %d\n\n", getpid(), pid);
    return 0;
  } else {
    printf("\n\tI'm the parent\nMy ID is %d and pid = %d\n", getpid(), pid);
    printf("Note that the value in my variable 'pid' is same as the process ID "
           "of my child\n\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1179 <main+0x49>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <main+0x78>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
test   %ebx,%ebx
je     1175 <main+0x35>
lea    0xecf(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
jmp    1187 <main+0x47>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"\0A\09I'm the child\0AMy ID is %d and pid = %d\0A\0A\00"
@.str.1 = [43 x i8] c"\0A\09I'm the parent\0AMy ID is %d and pid = %d\0A\00"
@.str.2 = [81 x i8] c"Note that the value in my variable 'pid' is same as the process ID of my child\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 (...) @getpid()
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
store i32 0, i32* %1
br label %15
10: ; preds = %0
%11 = call i32 (...) @getpid()
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %15
15: ; preds = %10, %6
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [43 x i8] c"\0A\09I'm the child\0AMy ID is %d and pid = %d\0A\0A\00"
@.str.1 = [43 x i8] c"\0A\09I'm the parent\0AMy ID is %d and pid = %d\0A\00"
@str = [80 x i8] c"Note that the value in my variable 'pid' is same as the process ID of my child\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
%3 = tail call i32 (...) @getpid()
br i1 %2, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
br label %9
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %1)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %6, %4
ret i32 0
}