#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;
  pid = getpid();
  ppid = getppid();
  if (fork() == -1) {
  } else if (pid == 0) {
    a = pr_a(a);
    ;
    printf("My pid = %d, my ppid = %d,result a = %d,result b = %d\n", (int)pid,
           (int)ppid, a, b);
  } else {
    b = pr_b(b);
    ;
    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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x64,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
jne    11a8 <main+0x48>
jmp    1211 <main+0xb1>
cmpq   $0x0,-0x10(%rbp)
jne    11e2 <main+0x82>
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    0xe28(%rip),%rdi
call   1040 <printf@plt>
jmp    120c <main+0xac>
mov    -0x20(%rbp),%edi
call   1070 <pr_b@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
jmp    1211 <main+0xb1>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     11c6 <main+0x66>
test   %rbx,%rbx
je     11a6 <main+0x46>
mov    $0x64,%edi
call   1070 <pr_b@plt>
lea    0xe66(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %eax,%r8d
jmp    11c1 <main+0x61>
xor    %edi,%edi
call   1050 <pr_a@plt>
lea    0xe4c(%rip),%rdi
xor    %esi,%esi
mov    %r14d,%edx
mov    %eax,%ecx
mov    $0x64,%r8d
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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
store i32 0, i32* %1
store i32 0, i32* %4
store i32 100, i32* %5
%6 = call i64 (...) @getpid()
store i64 %6, i64* %2
%7 = call i64 (...) @getppid()
store i64 %7, i64* %3
%8 = call i32 (...) @fork()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
br label %35
11: ; preds = %0
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i32 @pr_a(i32 %15)
store i32 %16, i32* %4
%17 = load i64, i64* %2
%18 = trunc i64 %17 to i32
%19 = load i64, i64* %3
%20 = trunc i64 %19 to i32
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20, i32 %21, i32 %22)
br label %34
24: ; preds = %11
%25 = load i32, i32* %5
%26 = call i32 @pr_b(i32 %25)
store i32 %26, i32* %5
%27 = load i64, i64* %2
%28 = trunc i64 %27 to i32
%29 = load i64, i64* %3
%30 = trunc i64 %29 to i32
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %30, i32 %31, i32 %32)
br label %34
34: ; preds = %24, %14
br label %35
35: ; preds = %34, %10
ret i32 0
}

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 i64 (...) @getpid()
%2 = tail call i64 (...) @getppid()
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, -1
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = tail call i32 @pr_a(i32 0)
%9 = trunc i64 %2 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 0, i32 %9, i32 %8, i32 100)
br label %16
11: ; preds = %5
%12 = tail call i32 @pr_b(i32 100)
%13 = trunc i64 %1 to i32
%14 = trunc i64 %2 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 0, i32 %12)
br label %16
16: ; preds = %7, %11, %0
ret i32 0
}