#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 getpgrp();
int getpid();
int getppid();
int getsid(int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  while (1) {
    if (getppid() == 1)
      break;
    printf("pid %d, ppid %d, pgid %d, sid %d\n", getpid(), getppid(), getpgrp(),
           getsid(getpid()));
    sleep(1);
  }
  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   1070 <getppid@plt>
cmp    $0x1,%eax
jne    118b <main+0x2b>
jmp    11de <main+0x7e>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getpgrp@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    %eax,%r8d
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1176 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <getppid@plt>
cmp    $0x1,%eax
je     11d2 <main+0x72>
lea    0xe86(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpgrp@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1050 <getsid@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
cmp    $0x1,%eax
jne    1180 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"pid %d, ppid %d, pgid %d, sid %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %6
6: ; preds = %2, %10
%7 = call i32 (...) @getppid()
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %6
br label %18
10: ; preds = %6
%11 = call i32 (...) @getpid()
%12 = call i32 (...) @getppid()
%13 = call i32 (...) @getpgrp()
%14 = call i32 (...) @getpid()
%15 = call i32 @getsid(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13, i32 %15)
%17 = call i32 @sleep(i32 1)
br label %6
18: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"pid %d, ppid %d, pgid %d, sid %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getppid()
%4 = icmp eq i32 %3, 1
br i1 %4, label %15, label %5
5: ; preds = %2, %5
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (...) @getppid()
%8 = tail call i32 (...) @getpgrp()
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 @getsid(i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, i32 %8, i32 %10)
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i32 (...) @getppid()
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %5
15: ; preds = %5, %2
ret i32 0
}