#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__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ free(scalar_t__ *);
int getegid();
int geteuid();
int getgid();
int getgroups(int, scalar_t__ *);
int getuid();
scalar_t__ *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
extern int printUserGroup(void) {
  int ret, i;
  gid_t *groups;
  printf("uid, gid: %4d %4d, %4d %4d\n", getuid(), geteuid(), getgid(),
         getegid());
  ret = getgroups(0, 0);
  groups = malloc(ret * sizeof(*groups));
  if (groups == NULL) {
    return -1;
  }
  getgroups(ret, groups);
  printf("supplementary groups: ");
  for (i = 0; i < ret; i++) {
    printf("%ld ", (long)groups[i]);
  }
  printf("\n");
  free(groups);
  return 0;
}


x86 assembly (clang, -O0):
<printUserGroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   10a0 <getegid@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <getgroups@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ff <printUserGroup+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <printUserGroup+0xf2>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <getgroups@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1254 <printUserGroup+0xd4>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1220 <printUserGroup+0xa0>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printUserGroup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <geteuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <getgid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <getegid@plt>
lea    0xe3e(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1090 <getgroups@plt>
mov    %eax,%ebp
lea    0x0(,%rbp,8),%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     124b <printUserGroup+0xbb>
mov    %rax,%r12
mov    %ebp,%edi
mov    %rax,%rsi
call   1090 <getgroups@plt>
lea    0xe19(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
jle    1237 <printUserGroup+0xa7>
mov    %ebp,%ebp
lea    0xe19(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1220 <printUserGroup+0x90>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1251 <printUserGroup+0xc1>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"uid, gid: %4d %4d, %4d %4d\0A\00"
@.str.1 = [23 x i8] c"supplementary groups: \00"
@.str.2 = [5 x i8] c"%ld \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @printUserGroup() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64*
%5 = call i32 (...) @getuid()
%6 = call i32 (...) @geteuid()
%7 = call i32 (...) @getgid()
%8 = call i32 (...) @getegid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %7, i32 %8)
%10 = call i32 @getgroups(i32 0, i64* null)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64* @malloc(i32 %14)
store i64* %15, i64** %4
%16 = load i64*, i64** %4
%17 = icmp eq i64* %16, null
br i1 %17, label %18, label %19
18: ; preds = %0
store i32 -1, i32* %1
br label %42
19: ; preds = %0
%20 = load i32, i32* %2
%21 = load i64*, i64** %4
%22 = call i32 @getgroups(i32 %20, i64* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %24
24: ; preds = %35, %19
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i64*, i64** %4
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %29, i64 %31
%33 = load i64, i64* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %28
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %24
38: ; preds = %24
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = load i64*, i64** %4
%41 = call i32 @free(i64* %40)
store i32 0, i32* %1
br label %42
42: ; preds = %38, %18
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [28 x i8] c"uid, gid: %4d %4d, %4d %4d\0A\00"
@.str.1 = [23 x i8] c"supplementary groups: \00"
@.str.2 = [5 x i8] c"%ld \00"
define i32 @printUserGroup() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (...) @geteuid()
%3 = tail call i32 (...) @getgid()
%4 = tail call i32 (...) @getegid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %3, i32 %4)
%6 = tail call i32 @getgroups(i32 0, i64* null)
%7 = shl i32 %6, 3
%8 = tail call i64* @malloc(i32 %7)
%9 = icmp eq i64* %8, null
br i1 %9, label %26, label %10
10: ; preds = %0
%11 = tail call i32 @getgroups(i32 %6, i64* %8)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp sgt i32 %6, 0
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = zext i32 %6 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = getelementptr inbounds i64, i64* %8, i64 %17
%19 = load i64, i64* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %15
br i1 %22, label %23, label %16
23: ; preds = %16, %10
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @free(i64* %8)
br label %26
26: ; preds = %0, %23
%27 = phi i32 [ 0, %23 ], [ -1, %0 ]
ret i32 %27
}