#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 scalar_t__ uid_t;
struct passwd {
  int /*<<< orphan*/ gr_name;
  int /*<<< orphan*/ pw_name;
};
struct group {
  int /*<<< orphan*/ gr_name;
  int /*<<< orphan*/ pw_name;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int NGROUPS_MAX;
int /*<<< orphan*/ assert(struct passwd *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getegid();
scalar_t__ geteuid();
scalar_t__ getgid();
struct passwd *getgrgid(scalar_t__);
int getgroups(int, scalar_t__ *);
scalar_t__ getpid();
scalar_t__ getppid();
struct passwd *getpwuid(scalar_t__);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *, long, ...);
int /*<<< orphan*/ stderr;
int main(void) {
  uid_t uid;
  gid_t gid, sup_grps[(NGROUPS_MAX + 1)];
  struct passwd *pwd;
  struct group *grp;
  int i, num_grps;
  printf("        Process-ID (PID): %ld\n", (long)getpid());
  printf("Parent Process-ID (PPID): %ld \n", (long)getppid());
  uid = getuid();
  assert(pwd = getpwuid(uid));
  printf("            Real User-ID: %ld - %s\n", (long)uid, pwd->pw_name);
  uid = geteuid();
  assert(pwd = getpwuid(uid));
  printf("       Effective User-ID: %ld - %s\n", (long)uid, pwd->pw_name);
  gid = getgid();
  assert(grp = getgrgid(gid));
  printf("           Real Group-ID: %ld - %s\n", (long)gid, grp->gr_name);
  gid = getegid();
  assert(grp = getgrgid(gid));
  printf("      Effective Group-ID: %ld - %s\n", (long)gid, grp->gr_name);
  num_grps = getgroups((NGROUPS_MAX + 1), sup_grps);
  if (num_grps == -1) {
    fprintf(stderr, "Err. getgroups() failed.\n");
    exit(EXIT_FAILURE);
  }
  printf("\nSupplementary group: %d\n", num_grps);
  for (i = 0; i < num_grps; i++) {
    grp = getgrgid(sup_grps[i]);
    printf("%5ld %s\n", (long)sup_grps[i], grp->gr_name);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    %rax,%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getpwuid@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   1090 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <geteuid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getpwuid@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   1090 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <getgid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <getgrgid@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
call   1090 <assert@plt>
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10d0 <getegid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <getgrgid@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
call   1090 <assert@plt>
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rsi
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   10c0 <getgroups@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    1366 <main+0x196>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movslq -0x40(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    13d1 <main+0x201>
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <getgrgid@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,-0x38(%rbp)
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    137f <main+0x1af>
mov    0x2bf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e03(%rip),%r12
mov    (%r12),%eax
add    $0x1,%eax
mov    %rsp,%r13
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdf1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10e0 <getppid@plt>
lea    0xdf8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <getpwuid@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <assert@plt>
mov    0x4(%r15),%edx
lea    0xde6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <geteuid@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <getpwuid@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <assert@plt>
mov    0x4(%r15),%edx
lea    0xdd8(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <getgid@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <getgrgid@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <assert@plt>
mov    (%r15),%edx
lea    0xdcb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10d0 <getegid@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <getgrgid@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <assert@plt>
mov    (%r15),%edx
lea    0xdbe(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%edi
add    $0x1,%edi
mov    %r13,%rsi
call   10c0 <getgroups@plt>
cmp    $0xffffffff,%eax
je     136c <main+0x19c>
mov    %eax,%r14d
movslq %eax,%rsi
lea    0xdd1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
jle    1354 <main+0x184>
mov    %r14d,%r15d
lea    0xdd5(%rip),%r14
xor    %ebx,%ebx
mov    0x0(%r13,%rbx,8),%rdi
call   1070 <getgrgid@plt>
mov    0x0(%r13,%rbx,8),%rsi
mov    (%rax),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1330 <main+0x160>
mov    0x2c6d(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
%struct.group = type { i32, i32 }
@NGROUPS_MAX = global i32 0
@.str = [31 x i8] c" Process-ID (PID): %ld\0A\00"
@.str.1 = [32 x i8] c"Parent Process-ID (PPID): %ld \0A\00"
@.str.2 = [36 x i8] c" Real User-ID: %ld - %s\0A\00"
@.str.3 = [36 x i8] c" Effective User-ID: %ld - %s\0A\00"
@.str.4 = [36 x i8] c" Real Group-ID: %ld - %s\0A\00"
@.str.5 = [36 x i8] c" Effective Group-ID: %ld - %s\0A\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"Err. getgroups() failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [26 x i8] c"\0ASupplementary group: %d\0A\00"
@.str.8 = [9 x i8] c"%5ld %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.passwd*
%7 = alloca %struct.group*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @NGROUPS_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i64, i64 %12
store i64 %12, i64* %5
%15 = call i64 (...) @getpid()
%16 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i64 (...) @getppid()
%18 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %17)
%19 = call i64 (...) @getuid()
store i64 %19, i64* %2
%20 = load i64, i64* %2
%21 = call %struct.passwd* @getpwuid(i64 %20)
store %struct.passwd* %21, %struct.passwd** %6
%22 = call i32 @assert(%struct.passwd* %21)
%23 = load i64, i64* %2
%24 = load %struct.passwd*, %struct.passwd** %6
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %23, i32 %26)
%28 = call i64 (...) @geteuid()
store i64 %28, i64* %2
%29 = load i64, i64* %2
%30 = call %struct.passwd* @getpwuid(i64 %29)
store %struct.passwd* %30, %struct.passwd** %6
%31 = call i32 @assert(%struct.passwd* %30)
%32 = load i64, i64* %2
%33 = load %struct.passwd*, %struct.passwd** %6
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %32, i32 %35)
%37 = call i64 (...) @getgid()
store i64 %37, i64* %3
%38 = load i64, i64* %3
%39 = call %struct.passwd* @getgrgid(i64 %38)
%40 = bitcast %struct.passwd* %39 to %struct.group*
store %struct.group* %40, %struct.group** %7
%41 = bitcast %struct.group* %40 to %struct.passwd*
%42 = call i32 @assert(%struct.passwd* %41)
%43 = load i64, i64* %3
%44 = load %struct.group*, %struct.group** %7
%45 = getelementptr inbounds %struct.group, %struct.group* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %43, i32 %46)
%48 = call i64 (...) @getegid()
store i64 %48, i64* %3
%49 = load i64, i64* %3
%50 = call %struct.passwd* @getgrgid(i64 %49)
%51 = bitcast %struct.passwd* %50 to %struct.group*
store %struct.group* %51, %struct.group** %7
%52 = bitcast %struct.group* %51 to %struct.passwd*
%53 = call i32 @assert(%struct.passwd* %52)
%54 = load i64, i64* %3
%55 = load %struct.group*, %struct.group** %7
%56 = getelementptr inbounds %struct.group, %struct.group* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %54, i32 %57)
%59 = load i32, i32* @NGROUPS_MAX
%60 = add nsw i32 %59, 1
%61 = call i32 @getgroups(i32 %60, i64* %14)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %0
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %0
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i64 %71)
store i32 0, i32* %8
br label %73
73: ; preds = %92, %69
%74 = load i32, i32* %8
%75 = load i32, i32* %9
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %95
77: ; preds = %73
%78 = load i32, i32* %8
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i64, i64* %14, i64 %79
%81 = load i64, i64* %80
%82 = call %struct.passwd* @getgrgid(i64 %81)
%83 = bitcast %struct.passwd* %82 to %struct.group*
store %struct.group* %83, %struct.group** %7
%84 = load i32, i32* %8
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i64, i64* %14, i64 %85
%87 = load i64, i64* %86
%88 = load %struct.group*, %struct.group** %7
%89 = getelementptr inbounds %struct.group, %struct.group* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i64 %87, i32 %90)
br label %92
92: ; preds = %77
%93 = load i32, i32* %8
%94 = add nsw i32 %93, 1
store i32 %94, i32* %8
br label %73
95: ; preds = %73
%96 = load i32, i32* @EXIT_SUCCESS
store i32 %96, i32* %1
%97 = load i8*, i8** %4
%98 = load i32, i32* %1
ret i32 %98
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@NGROUPS_MAX = global i32 0
@.str = [31 x i8] c" Process-ID (PID): %ld\0A\00"
@.str.1 = [32 x i8] c"Parent Process-ID (PPID): %ld \0A\00"
@.str.2 = [36 x i8] c" Real User-ID: %ld - %s\0A\00"
@.str.3 = [36 x i8] c" Effective User-ID: %ld - %s\0A\00"
@.str.4 = [36 x i8] c" Real Group-ID: %ld - %s\0A\00"
@.str.5 = [36 x i8] c" Effective Group-ID: %ld - %s\0A\00"
@stderr = global i32 0
@.str.6 = [26 x i8] c"Err. getgroups() failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [26 x i8] c"\0ASupplementary group: %d\0A\00"
@.str.8 = [9 x i8] c"%5ld %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @NGROUPS_MAX
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i64, i64 %3
%5 = tail call i64 (...) @getpid()
%6 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = tail call i64 (...) @getppid()
%8 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = tail call i64 (...) @getuid()
%10 = tail call %struct.passwd* @getpwuid(i64 %9)
%11 = tail call i32 @assert(%struct.passwd* %10)
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 1
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %9, i32 %13)
%15 = tail call i64 (...) @geteuid()
%16 = tail call %struct.passwd* @getpwuid(i64 %15)
%17 = tail call i32 @assert(%struct.passwd* %16)
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 1
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %15, i32 %19)
%21 = tail call i64 (...) @getgid()
%22 = tail call %struct.passwd* @getgrgid(i64 %21)
%23 = tail call i32 @assert(%struct.passwd* %22)
%24 = getelementptr %struct.passwd, %struct.passwd* %22, i64 0, i32 0
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %21, i32 %25)
%27 = tail call i64 (...) @getegid()
%28 = tail call %struct.passwd* @getgrgid(i64 %27)
%29 = tail call i32 @assert(%struct.passwd* %28)
%30 = getelementptr %struct.passwd, %struct.passwd* %28, i64 0, i32 0
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %27, i32 %31)
%33 = load i32, i32* @NGROUPS_MAX
%34 = add nsw i32 %33, 1
%35 = call i32 @getgroups(i32 %34, i64* %4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %0
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %0
%43 = sext i32 %35 to i64
%44 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i64 %43)
%45 = icmp sgt i32 %35, 0
br i1 %45, label %46, label %59
46: ; preds = %42
%47 = zext i32 %35 to i64
br label %48
48: ; preds = %46, %48
%49 = phi i64 [ 0, %46 ], [ %57, %48 ]
%50 = getelementptr inbounds i64, i64* %4, i64 %49
%51 = load i64, i64* %50
%52 = call %struct.passwd* @getgrgid(i64 %51)
%53 = load i64, i64* %50
%54 = getelementptr %struct.passwd, %struct.passwd* %52, i64 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i64 %53, i32 %55)
%57 = add nuw nsw i64 %49, 1
%58 = icmp eq i64 %57, %47
br i1 %58, label %59, label %48
59: ; preds = %48, %42
%60 = load i32, i32* @EXIT_SUCCESS
ret i32 %60
}