#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();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ printf(char *, long, long, long);
int main(void) {
  pid_t childpid, endid;
  pid_t mypid;
  pid_t myparentspid;
  int status;
  mypid = getpid();
  myparentspid = getppid();
  childpid = fork();
  if (childpid == 0) {
    printf("children ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\n",
           (long int)getpid(), (long int)getppid(), (long int)myparentspid);
  } else {
    printf("ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\n",
           (long int)getpid(), (long int)getppid(), (long int)myparentspid);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <main+0x69>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    11d2 <main+0x92>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <getppid@plt>
test   %rbx,%rbx
lea    0xe85(%rip),%rcx
lea    0xe87(%rip),%rdi
cmove  %rcx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    %r14,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [65 x i8] c"children ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\0A\00"
@.str.1 = [56 x i8] c"ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 (...) @getpid()
store i64 %7, i64* %4
%8 = call i64 (...) @getppid()
store i64 %8, i64* %5
%9 = call i64 (...) @fork()
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = call i64 (...) @getpid()
%14 = call i64 (...) @getppid()
%15 = load i64, i64* %5
%16 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i64 %13, i64 %14, i64 %15)
br label %22
17: ; preds = %0
%18 = call i64 (...) @getpid()
%19 = call i64 (...) @getppid()
%20 = load i64, i64* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %18, i64 %19, i64 %20)
br label %22
22: ; preds = %17, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [65 x i8] c"children ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\0A\00"
@.str.1 = [56 x i8] c"ID(myPID_1): %ld, ID(myPID_2): %ld and Parent PID: %ld\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @getpid()
%2 = tail call i64 (...) @getppid()
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
%5 = tail call i64 (...) @getpid()
%6 = tail call i64 (...) @getppid()
%7 = select i1 %4, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 @printf(i8* %7, i64 %5, i64 %6, i64 %2)
ret i32 0
}