#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 */
int fork();
scalar_t__ getpid();
scalar_t__ getppid();
int pr_a(int);
int pr_b(int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int main() {
  pid_t pid, ppid;
  int a = 0;
  int b = 100;
  int children = fork();
  if (children == -1) {
    return 1;
  }
  pid = getpid();
  ppid = getppid();
  if (children == 0) {
    b = pr_b(b);
  } else {
    a = pr_a(a);
  }
  printf("My pid = %d, my ppid = %d,result a = %d,result b = %d\n", (int)pid,
         (int)ppid, a, b);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x64,-0x20(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    119d <main+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0x9e>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11cd <main+0x6d>
mov    -0x20(%rbp),%edi
call   1070 <pr_b@plt>
mov    %eax,-0x20(%rbp)
jmp    11d8 <main+0x78>
mov    -0x1c(%rbp),%edi
call   1050 <pr_a@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x40>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     11a7 <main+0x47>
xor    %edi,%edi
call   1050 <pr_a@plt>
mov    %eax,%ebx
mov    $0x64,%r8d
jmp    11b4 <main+0x54>
mov    $0x1,%eax
jmp    11ca <main+0x6a>
mov    $0x64,%edi
call   1070 <pr_b@plt>
mov    %eax,%r8d
lea    0xe45(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"My pid = %d, my ppid = %d,result a = %d,result b = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 100, i32* %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %30
11: ; preds = %0
%12 = call i64 (...) @getpid()
store i64 %12, i64* %2
%13 = call i64 (...) @getppid()
store i64 %13, i64* %3
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %5
%18 = call i32 @pr_b(i32 %17)
store i32 %18, i32* %5
br label %22
19: ; preds = %11
%20 = load i32, i32* %4
%21 = call i32 @pr_a(i32 %20)
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %16
%23 = load i64, i64* %2
%24 = trunc i64 %23 to i32
%25 = load i64, i64* %3
%26 = trunc i64 %25 to i32
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %26, i32 %27, i32 %28)
store i32 0, i32* %1
br label %30
30: ; preds = %22, %10
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [55 x i8] c"My pid = %d, my ppid = %d,result a = %d,result b = %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, -1
br i1 %2, label %17, label %3
3: ; preds = %0
%4 = tail call i64 (...) @getpid()
%5 = tail call i64 (...) @getppid()
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @pr_b(i32 100)
br label %11
9: ; preds = %3
%10 = tail call i32 @pr_a(i32 0)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ 0, %7 ], [ %10, %9 ]
%13 = phi i32 [ %8, %7 ], [ 100, %9 ]
%14 = trunc i64 %4 to i32
%15 = trunc i64 %5 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %12, i32 %13)
br label %17
17: ; preds = %0, %11
%18 = phi i32 [ 0, %11 ], [ 1, %0 ]
ret i32 %18
}