#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 */

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int atoi(char *);
int getpgrp();
int getpid();
int getppid();
int getsid(int);
int /*<<< orphan*/ printf(char *, int, int, int, int, int);
int /*<<< orphan*/ sleep(int);
int tcgetpgrp(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int grp = atoi(argv[1]);
  printf("pid %d, ppid %d, pgid %d, sid %d, tcgrp %d\n", getpid(), getppid(),
         getpgrp(), getsid(getpid()), tcgetpgrp(STDIN_FILENO));
  sleep(1);
  sleep(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <getpgrp@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <tcgetpgrp@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    %eax,%r9d
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
xor    %eax,%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   1030 <getpid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1070 <getpgrp@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %eax,%ebp
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1060 <tcgetpgrp@plt>
lea    0xe47(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"pid %d, ppid %d, pgid %d, sid %d, tcgrp %d\0A\00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = call i32 @atoi(i8* %9)
store i32 %10, i32* %6
%11 = call i32 (...) @getpid()
%12 = call i32 (...) @getppid()
%13 = call i32 (...) @getpgrp()
%14 = call i32 (...) @getpid()
%15 = call i32 @getsid(i32 %14)
%16 = load i32, i32* @STDIN_FILENO
%17 = call i32 @tcgetpgrp(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13, i32 %15, i32 %17)
%19 = call i32 @sleep(i32 1)
%20 = call i32 @sleep(i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"pid %d, ppid %d, pgid %d, sid %d, tcgrp %d\0A\00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 (...) @getpgrp()
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @getsid(i32 %6)
%8 = load i32, i32* @STDIN_FILENO
%9 = tail call i32 @tcgetpgrp(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4, i32 %5, i32 %7, i32 %9)
%11 = tail call i32 @sleep(i32 1)
%12 = tail call i32 @sleep(i32 1)
ret i32 0
}