#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 getpgid(int /*<<< orphan*/);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  pid_t pid, ppid, pgid;
  pid = getpid();
  ppid = getppid();
  pgid = getpgid(0);
  printf("pid is %d\n", pid);
  printf("ppid is %d\n", ppid);
  printf("pgid is %d\n", pgid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,-0x18(%rbp)
xor    %edi,%edi
call   1050 <getpgid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <getpgid@plt>
mov    %eax,%r14d
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"pid is %d\0A\00"
@.str.1 = [12 x i8] c"ppid is %d\0A\00"
@.str.2 = [12 x i8] c"pgid is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getpid()
store i32 %9, i32* %6
%10 = call i32 (...) @getppid()
store i32 %10, i32* %7
%11 = call i32 @getpgid(i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %7
%15 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %8
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"pid is %d\0A\00"
@.str.1 = [12 x i8] c"ppid is %d\0A\00"
@.str.2 = [12 x i8] c"pgid is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 @getpgid(i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %5)
ret i32 0
}