#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);
int getpid();
int getppid();
int getsid(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, int, int, int);
void processInfo(char *msg) {
  pid_t pgid = getpgid(getpid());
  if (pgid == -1)
    perror("getpgid error:");
  pid_t sid = getsid(0);
  if (sid == -1)
    perror("getsid error:");
  printf("%s: This is %d in session %d (created from %d); pgid=%d\n", msg,
         getpid(), sid, getppid(), pgid);
}


x86 assembly (clang, -O0):
<processInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <getpgid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1193 <processInfo+0x33>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1050 <getsid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11b3 <processInfo+0x53>
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    %eax,%r8d
mov    -0xc(%rbp),%r9d
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processInfo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%edi
call   1070 <getpgid@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11c1 <processInfo+0x61>
xor    %edi,%edi
call   1050 <getsid@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11cf <processInfo+0x6f>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
mov    %r15d,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe38(%rip),%rdi
call   1060 <perror@plt>
jmp    1180 <processInfo+0x20>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
jmp    118e <processInfo+0x2e>

LLVM IR (-O0):
@.str = [15 x i8] c"getpgid error:\00"
@.str.1 = [14 x i8] c"getsid error:\00"
@.str.2 = [57 x i8] c"%s: This is %d in session %d (created from %d); pgid=%d\0A\00"
define void @processInfo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @getpid()
%6 = call i32 @getpgid(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 @getsid(i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = load i8*, i8** %2
%19 = call i32 (...) @getpid()
%20 = load i32, i32* %4
%21 = call i32 (...) @getppid()
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %19, i32 %20, i32 %21, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"getpgid error:\00"
@.str.1 = [14 x i8] c"getsid error:\00"
@.str.2 = [57 x i8] c"%s: This is %d in session %d (created from %d); pgid=%d\0A\00"
define void @processInfo(i8* %0) {
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @getpgid(i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i32 @getsid(i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %13, i32 %8, i32 %14, i32 %3)
ret void
}