#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 */
struct group {
  char *gr_name;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ geteuid();
struct group *getgrgid(scalar_t__);
int getgroups(int, scalar_t__ *);
int /*<<< orphan*/ getuid();
scalar_t__ malloc(int);
int /*<<< orphan*/ printUser(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printUser("euid", geteuid());
  printUser("uid", getuid());
  int count = getgroups(0, NULL);
  gid_t *groups = (gid_t *)malloc(sizeof(gid_t) * count);
  getgroups(count, groups);
  printf("groups: ");
  int i;
  for (i = 0; i < count; i++) {
    gid_t gid = groups[i];
    const char *name = "?";
    struct group *grp = getgrgid(gid);
    if (grp != NULL) {
      name = grp->gr_name;
    };
    printf("%u <%s>", (unsigned int)gid, name);
    if (i != (count - 1))
      printf(", ");
  };
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,%esi
lea    0xe71(%rip),%rdi
call   1090 <printUser@plt>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,%esi
lea    0xe5d(%rip),%rdi
call   1090 <printUser@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <getgroups@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <getgroups@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127f <main+0x10f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
lea    0xe00(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <getgrgid@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1235 <main+0xc5>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     126c <main+0xfc>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1271 <main+0x101>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11eb <main+0x7b>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <geteuid@plt>
lea    0xe67(%rip),%rdi
mov    %eax,%esi
call   10a0 <printUser@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe53(%rip),%rdi
mov    %eax,%esi
call   10a0 <printUser@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <getgroups@plt>
mov    %eax,%r14d
lea    0x0(,%r14,8),%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %r14d,%edi
mov    %rax,%rsi
call   1080 <getgroups@plt>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    1255 <main+0xd5>
lea    -0x1(%r14),%r13d
mov    %r14d,%ebp
lea    0xe13(%rip),%r14
xor    %r15d,%r15d
jmp    1219 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r15,%rbp
je     1255 <main+0xd5>
mov    (%r12,%r15,8),%rbx
mov    %rbx,%rdi
call   1060 <getgrgid@plt>
lea    0xde2(%rip),%rdx
test   %rax,%rax
je     1234 <main+0xb4>
mov    (%rax),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r15,%r13
je     1210 <main+0x90>
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1210 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8* }
@.str = [5 x i8] c"euid\00"
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [9 x i8] c"groups: \00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [8 x i8] c"%u <%s>\00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca %struct.group*
store i32 0, i32* %1
%8 = call i32 (...) @geteuid()
%9 = call i32 @printUser(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @getuid()
%11 = call i32 @printUser(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @getgroups(i32 0, i64* null)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i64*
store i64* %18, i64** %3
%19 = load i32, i32* %2
%20 = load i64*, i64** %3
%21 = call i32 @getgroups(i32 %19, i64* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %23
23: ; preds = %53, %0
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %56
27: ; preds = %23
%28 = load i64*, i64** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %28, i64 %30
%32 = load i64, i64* %31
store i64 %32, i64* %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %6
%33 = load i64, i64* %5
%34 = call %struct.group* @getgrgid(i64 %33)
store %struct.group* %34, %struct.group** %7
%35 = load %struct.group*, %struct.group** %7
%36 = icmp ne %struct.group* %35, null
br i1 %36, label %37, label %41
37: ; preds = %27
%38 = load %struct.group*, %struct.group** %7
%39 = getelementptr inbounds %struct.group, %struct.group* %38, i32 0, i32 0
%40 = load i8*, i8** %39
store i8* %40, i8** %6
br label %41
41: ; preds = %37, %27
%42 = load i64, i64* %5
%43 = trunc i64 %42 to i32
%44 = load i8*, i8** %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %43, i8* %44)
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = sub nsw i32 %47, 1
%49 = icmp ne i32 %46, %48
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %41
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %23
56: ; preds = %23
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.group = type { i8* }
@.str = [5 x i8] c"euid\00"
@.str.1 = [4 x i8] c"uid\00"
@.str.2 = [9 x i8] c"groups: \00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [8 x i8] c"%u <%s>\00"
@.str.5 = [3 x i8] c", \00"
define i32 @main() {
%1 = tail call i32 (...) @geteuid()
%2 = tail call i32 @printUser(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @getuid()
%4 = tail call i32 @printUser(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 @getgroups(i32 0, i64* null)
%6 = shl i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i64*
%9 = tail call i32 @getgroups(i32 %5, i64* %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %35
12: ; preds = %0
%13 = add nsw i32 %5, -1
%14 = zext i32 %13 to i64
%15 = zext i32 %5 to i64
br label %16
16: ; preds = %12, %32
%17 = phi i64 [ 0, %12 ], [ %33, %32 ]
%18 = getelementptr inbounds i64, i64* %8, i64 %17
%19 = load i64, i64* %18
%20 = tail call %struct.group* @getgrgid(i64 %19)
%21 = icmp eq %struct.group* %20, null
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 0
%24 = load i8*, i8** %23
br label %25
25: ; preds = %22, %16
%26 = phi i8* [ %24, %22 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %16 ]
%27 = trunc i64 %19 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %27, i8* %26)
%29 = icmp eq i64 %17, %14
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = add nuw nsw i64 %17, 1
%34 = icmp eq i64 %33, %15
br i1 %34, label %35, label %16
35: ; preds = %32, %0
%36 = tail call i32 @putchar(i32 10)
ret i32 0
}