#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 getpgid(int /*<<< orphan*/);
int getsid(int /*<<< orphan*/);
char *pname(int);
int /*<<< orphan*/ printf(char *, int, char *);
int tcgetpgrp(int /*<<< orphan*/);
int main() {
  int pg = tcgetpgrp(0);
  printf("pg: %d (%s)\n", pg, pname(pg));
  int sid = getsid(0);
  printf("sid: %d (%s)\n", sid, pname(sid));
  int pgid = getpgid(0);
  printf("pgid: %d (%s)\n", pgid, pname(pgid));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <tcgetpgrp@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <pname@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <getsid@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <pname@plt>
mov    -0x18(%rbp),%esi
mov    %rax,%rdx
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <getpgid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <pname@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1050 <tcgetpgrp@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <pname@plt>
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <getsid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <pname@plt>
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <getpgid@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <pname@plt>
lea    0xe71(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"pg: %d (%s)\0A\00"
@.str.1 = [14 x i8] c"sid: %d (%s)\0A\00"
@.str.2 = [15 x i8] c"pgid: %d (%s)\0A\00"
define i32 @main() {
%1 = tail call i32 @tcgetpgrp(i32 0)
%2 = tail call i8* @pname(i32 %1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %2)
%4 = tail call i32 @getsid(i32 0)
%5 = tail call i8* @pname(i32 %4)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4, i8* %5)
%7 = tail call i32 @getpgid(i32 0)
%8 = tail call i8* @pname(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %8)
ret i32 0
}