#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);
int /*<<< orphan*/ sleep(int);
int main() {
  int r = 10;
  int m = 10;
  int fd = fork();
  if (fd) {
    while (1) {
      r++;
      printf("I am parent : %d \n", getpid());
      sleep(1);
      printf("Parent mydata %d \n", r);
      printf("Parent Child data : %d \n", m);
    }
  } else {
    while (1) {
      m++;
      printf("I am child :%d \n", getpid());
      sleep(1);
      printf("child mydata : %d \n", m);
      printf("Child Parent data : %d \n", r);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0xa,-0xc(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11c4 <main+0x84>
jmp    1176 <main+0x36>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x8(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
jmp    1176 <main+0x36>
jmp    11c9 <main+0x89>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0xc(%rbp),%esi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
jmp    11c9 <main+0x89>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xb,%ebx
test   %eax,%eax
je     11a7 <main+0x67>
lea    0xea1(%rip),%r14
lea    0xead(%rip),%r15
lea    0xeb9(%rip),%r12
nopl   (%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
add    $0x1,%ebx
jmp    1170 <main+0x30>
lea    0xe91(%rip),%r14
lea    0xe9b(%rip),%r15
lea    0xea8(%rip),%r12
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
add    $0x1,%ebx
jmp    11c0 <main+0x80>

LLVM IR (-O0):
@.str = [19 x i8] c"I am parent : %d \0A\00"
@.str.1 = [19 x i8] c"Parent mydata %d \0A\00"
@.str.2 = [25 x i8] c"Parent Child data : %d \0A\00"
@.str.3 = [17 x i8] c"I am child :%d \0A\00"
@.str.4 = [20 x i8] c"child mydata : %d \0A\00"
@.str.5 = [25 x i8] c"Child Parent data : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
store i32 10, i32* %3
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %0
br label %9
9: ; preds = %8, %9
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
%12 = call i32 (...) @getpid()
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @sleep(i32 1)
%15 = load i32, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %9
19: ; preds = %0
br label %20
20: ; preds = %19, %20
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = call i32 (...) @getpid()
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 @sleep(i32 1)
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %2
%29 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %20
}

LLVM IR (-O2):
@.str = [19 x i8] c"I am parent : %d \0A\00"
@.str.1 = [19 x i8] c"Parent mydata %d \0A\00"
@.str.2 = [25 x i8] c"Parent Child data : %d \0A\00"
@.str.3 = [17 x i8] c"I am child :%d \0A\00"
@.str.4 = [20 x i8] c"child mydata : %d \0A\00"
@.str.5 = [25 x i8] c"Child Parent data : %d \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %11, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %5, %3 ], [ 10, %0 ]
%5 = add nuw nsw i32 %4, 1
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @sleep(i32 1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 10)
br label %3
11: ; preds = %0, %11
%12 = phi i32 [ %13, %11 ], [ 10, %0 ]
%13 = add nuw nsw i32 %12, 1
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 10)
br label %11
}