#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getchar();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  pid_t pid, ppid;
  pid = getpid();
  ppid = getppid();
  printf("PID: %d\n", pid);
  printf("PPID: %d\n", ppid);
  fprintf(stderr, "Press <Enter> to exit...");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %eax,%ebp
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"PID: %d\0A\00"
@.str.1 = [10 x i8] c"PPID: %d\0A\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Press <Enter> to exit...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @getpid()
store i32 %4, i32* %2
%5 = call i32 (...) @getppid()
store i32 %5, i32* %3
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"PID: %d\0A\00"
@.str.1 = [10 x i8] c"PPID: %d\0A\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Press <Enter> to exit...\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (...) @getppid()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (...) @getchar()
ret i32 0
}