#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 int pid_t;

/* Variables and functions */
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  if (!(pid = fork())) {
    printf("in child parent pid = %d,child pid = %d\n", getppid(), getpid());
    return 0;
  }
  printf("in parent pid = %d,child pid= %d\n", getpid(), pid);
  wait(&pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    11a0 <main+0x50>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <main+0x78>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
lea    -0x8(%rbp),%rdi
call   1060 <wait@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
je     1189 <main+0x39>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
jmp    11a9 <main+0x59>
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe60(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"in child parent pid = %d,child pid = %d\0A\00"
@.str.1 = [34 x i8] c"in parent pid = %d,child pid= %d\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 = icmp ne i32 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = call i32 (...) @getppid()
%7 = call i32 (...) @getpid()
%8 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
store i32 0, i32* %1
br label %14
9: ; preds = %0
%10 = call i32 (...) @getpid()
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
%13 = call i32 @wait(i32* %2)
store i32 0, i32* %1
br label %14
14: ; preds = %9, %5
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [41 x i8] c"in child parent pid = %d,child pid = %d\0A\00"
@.str.1 = [34 x i8] c"in parent pid = %d,child pid= %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
store i32 %3, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 (...) @getppid()
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
br label %13
9: ; preds = %0
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %3)
%12 = call i32 @wait(i32* %1)
br label %13
13: ; preds = %9, %5
ret i32 0
}