#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 char *intmax_t;
typedef int /*<<< orphan*/ domain;

/* Variables and functions */
scalar_t__ getdomainname(char *, int);
char *getgid();
char *getlogin();
char *getpgrp();
char *getpid();
char *getppid();
char *getsid(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  intmax_t pid, ppid, pgrp, sid, gid;
  char domain[256], *login;
  pid = getpid();
  ppid = getppid();
  pgrp = getpgrp();
  gid = getgid();
  sid = getsid(pid);
  if (getdomainname(domain, sizeof(domain)) < 0)
    strcpy(domain, "(none)");
  if ((login = getlogin()) == NULL)
    login = "(null)";
  printf("pid    %jd\n", pid);
  printf("ppid   %jd\n", ppid);
  printf("gid    %jd\n", gid);
  printf("sid    %jd\n", sid);
  printf("prgp   %jd\n", pgrp);
  printf("domain %s\n", domain);
  printf("login  %s\n", login);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <getppid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <getpgrp@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getsid@plt>
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   1050 <getdomainname@plt>
cmp    $0x0,%rax
jge    1209 <main+0x79>
lea    -0x130(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1090 <getlogin@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
jne    122f <main+0x9f>
lea    0xddf(%rip),%rax
mov    %rax,-0x138(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdcc(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdc4(%rip),%rdi
call   1060 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
mov    -0x138(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <getppid@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10a0 <getpgrp@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <getgid@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1070 <getsid@plt>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x100,%esi
call   1050 <getdomainname@plt>
test   %rax,%rax
jns    11f5 <main+0x65>
lea    0xe13(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1090 <getlogin@plt>
test   %rax,%rax
lea    0xe01(%rip),%rbp
cmovne %rax,%rbp
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
lea    0xdf4(%rip),%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
lea    0xdf1(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
lea    0xdee(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
lea    0xdea(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"(none)\00"
@.str.1 = [7 x i8] c"(null)\00"
@.str.2 = [12 x i8] c"pid %jd\0A\00"
@.str.3 = [12 x i8] c"ppid %jd\0A\00"
@.str.4 = [12 x i8] c"gid %jd\0A\00"
@.str.5 = [12 x i8] c"sid %jd\0A\00"
@.str.6 = [12 x i8] c"prgp %jd\0A\00"
@.str.7 = [11 x i8] c"domain %s\0A\00"
@.str.8 = [11 x i8] c"login %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i8*
store i32 0, i32* %1
%9 = call i8* (...) @getpid()
store i8* %9, i8** %2
%10 = call i8* (...) @getppid()
store i8* %10, i8** %3
%11 = call i8* (...) @getpgrp()
store i8* %11, i8** %4
%12 = call i8* (...) @getgid()
store i8* %12, i8** %6
%13 = load i8*, i8** %2
%14 = call i8* @getsid(i8* %13)
store i8* %14, i8** %5
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = call i64 @getdomainname(i8* %15, i32 256)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %0
%22 = call i8* (...) @getlogin()
store i8* %22, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %25
25: ; preds = %24, %21
%26 = load i8*, i8** %2
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %4
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"(none)\00"
@.str.1 = [7 x i8] c"(null)\00"
@.str.2 = [12 x i8] c"pid %jd\0A\00"
@.str.3 = [12 x i8] c"ppid %jd\0A\00"
@.str.4 = [12 x i8] c"gid %jd\0A\00"
@.str.5 = [12 x i8] c"sid %jd\0A\00"
@.str.6 = [12 x i8] c"prgp %jd\0A\00"
@.str.7 = [11 x i8] c"domain %s\0A\00"
@.str.8 = [11 x i8] c"login %s\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i8* (...) @getpid()
%4 = tail call i8* (...) @getppid()
%5 = tail call i8* (...) @getpgrp()
%6 = tail call i8* (...) @getgid()
%7 = tail call i8* @getsid(i8* %3)
%8 = call i64 @getdomainname(i8* %2, i32 256)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i8* (...) @getlogin()
%14 = icmp eq i8* %13, null
%15 = select i1 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%18 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* %15)
ret i32 0
}