#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct passwd {
  int /*<<< orphan*/ pw_gid;
};
typedef int /*<<< orphan*/ gid_t;
struct TYPE_2__ {
  char *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ geteuid();
scalar_t__ getgrouplist(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        int *);
struct passwd *getpwnam(char *);
TYPE_1__ *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ print_gid(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *realloc(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *user = NULL;
  if (argc < 2)
    user = getpwuid(geteuid())->pw_name;
  int i, ret = 0;
  for (i = 1; i < argc || user; i++, user = NULL) {
    int ngroups = 0;
    struct passwd *pw = NULL;
    gid_t *groups = NULL;
    if (!user)
      user = argv[i];
    pw = getpwnam(user);
    if (!pw) {
      fprintf(stderr, "groups: no such user '%s'\n", user);
      ret = 1;
      continue;
    }
    do {
      ngroups++;
      groups = realloc(groups, ngroups * sizeof(gid_t));
    } while (getgrouplist(user, pw->pw_gid, groups, &ngroups) < 0);
    if (argc > 1)
      printf("%s: ", user);
    print_gid(groups, ngroups);
    free(groups);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cd <main+0x3d>
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    $0x1,%al
cmp    -0x8(%rbp),%ecx
mov    %al,-0x39(%rbp)
jl     11f7 <main+0x67>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1207 <main+0x77>
jmp    1301 <main+0x171>
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1239 <main+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <getpwnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1276 <main+0xe6>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd9b(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x20(%rbp)
jmp    12eb <main+0x15b>
jmp    127b <main+0xeb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x38(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   10b0 <getgrouplist@plt>
cmp    $0x0,%rax
jl     127b <main+0xeb>
cmpl   $0x1,-0x8(%rbp)
jle    12d6 <main+0x146>
mov    -0x18(%rbp),%rsi
lea    0xd4a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <print_gid@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    11db <main+0x4b>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
xor    %eax,%eax
mov    %edi,0xc(%rsp)
cmp    $0x1,%edi
jg     11e2 <main+0x52>
movl   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    (%rax),%r13
test   %r13,%r13
setne  %al
jne    11e5 <main+0x55>
mov    0x8(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
mov    0xc(%rsp),%ecx
cmp    $0x3,%ecx
mov    $0x2,%r12d
cmovge %ecx,%r12d
mov    $0x1,%ebp
lea    0x4(%rsp),%rbx
movl   $0x0,0x8(%rsp)
jmp    1235 <main+0xa5>
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1060 <print_gid@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x1,%rbp
xor    %eax,%eax
mov    $0x0,%r13d
cmp    %r12,%rbp
je     11cf <main+0x3f>
movl   $0x0,0x4(%rsp)
test   $0x1,%al
jne    124a <main+0xba>
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,8),%r13
mov    %r13,%rdi
call   1080 <getpwnam@plt>
test   %rax,%rax
je     12c0 <main+0x130>
mov    %rax,%r14
xor    %r15d,%r15d
nopl   (%rax)
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
lea    0x4(,%rax,4),%esi
mov    %r15,%rdi
call   10a0 <realloc@plt>
mov    %rax,%r15
mov    (%r14),%esi
mov    %r13,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
call   10b0 <getgrouplist@plt>
test   %rax,%rax
js     1260 <main+0xd0>
cmpl   $0x2,0xc(%rsp)
jl     1210 <main+0x80>
lea    0xd76(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
jmp    1210 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
mov    %r13,%rdx
call   1090 <fprintf@plt>
movl   $0x1,0x8(%rsp)
jmp    1224 <main+0x94>

LLVM IR (-O0):
%struct.passwd = type { i32 }
%struct.TYPE_2__ = type { i8* }
@stderr = global i32 0
@.str = [27 x i8] c"groups: no such user '%s'\0A\00"
@.str.1 = [5 x i8] c"%s: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.passwd*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = call i32 (...) @geteuid()
%16 = call %struct.TYPE_2__* @getpwuid(i32 %15)
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %19
19: ; preds = %14, %2
store i32 0, i32* %8
store i32 1, i32* %7
br label %20
20: ; preds = %77, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br label %27
27: ; preds = %24, %20
%28 = phi i1 [ true, %20 ], [ %26, %24 ]
br i1 %28, label %29, label %80
29: ; preds = %27
store i32 0, i32* %9
store %struct.passwd* null, %struct.passwd** %10
store i32* null, i32** %11
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
store i8* %37, i8** %6
br label %38
38: ; preds = %32, %29
%39 = load i8*, i8** %6
%40 = call %struct.passwd* @getpwnam(i8* %39)
store %struct.passwd* %40, %struct.passwd** %10
%41 = load %struct.passwd*, %struct.passwd** %10
%42 = icmp ne %struct.passwd* %41, null
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %6
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %45)
store i32 1, i32* %8
br label %77
47: ; preds = %38
br label %48
48: ; preds = %57, %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
%51 = load i32*, i32** %11
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 4
%55 = trunc i64 %54 to i32
%56 = call i32* @realloc(i32* %51, i32 %55)
store i32* %56, i32** %11
br label %57
57: ; preds = %48
%58 = load i8*, i8** %6
%59 = load %struct.passwd*, %struct.passwd** %10
%60 = getelementptr inbounds %struct.passwd, %struct.passwd* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load i32*, i32** %11
%63 = call i64 @getgrouplist(i8* %58, i32 %61, i32* %62, i32* %9)
%64 = icmp slt i64 %63, 0
br i1 %64, label %48, label %65
65: ; preds = %57
%66 = load i32, i32* %4
%67 = icmp sgt i32 %66, 1
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i8*, i8** %6
%70 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %68, %65
%72 = load i32*, i32** %11
%73 = load i32, i32* %9
%74 = call i32 @print_gid(i32* %72, i32 %73)
%75 = load i32*, i32** %11
%76 = call i32 @free(i32* %75)
br label %77
77: ; preds = %71, %43
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
store i8* null, i8** %6
br label %20
80: ; preds = %27
%81 = load i32, i32* %8
ret i32 %81
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"groups: no such user '%s'\0A\00"
@.str.1 = [5 x i8] c"%s: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i32 (...) @geteuid()
%7 = tail call %struct.TYPE_2__* @getpwuid(i32 %6)
%8 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %54
11: ; preds = %2, %5
%12 = phi i1 [ %10, %5 ], [ false, %2 ]
%13 = phi i8* [ %9, %5 ], [ null, %2 ]
%14 = bitcast i32* %3 to i8*
%15 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%16 = zext i32 %15 to i64
br label %17
17: ; preds = %11, %50
%18 = phi i64 [ 1, %11 ], [ %52, %50 ]
%19 = phi i1 [ %12, %11 ], [ false, %50 ]
%20 = phi i32 [ 0, %11 ], [ %51, %50 ]
%21 = phi i8* [ %13, %11 ], [ null, %50 ]
store i32 0, i32* %3
br i1 %19, label %25, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8*, i8** %1, i64 %18
%24 = load i8*, i8** %23
br label %25
25: ; preds = %22, %17
%26 = phi i8* [ %21, %17 ], [ %24, %22 ]
%27 = call %struct.passwd* @getpwnam(i8* %26)
%28 = icmp eq %struct.passwd* %27, null
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i64 0, i32 0
br label %34
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %50
34: ; preds = %29, %34
%35 = phi i32* [ %39, %34 ], [ null, %29 ]
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
%38 = shl i32 %37, 2
%39 = call i32* @realloc(i32* %35, i32 %38)
%40 = load i32, i32* %30
%41 = call i64 @getgrouplist(i8* %26, i32 %40, i32* %39, i32* %3)
%42 = icmp slt i64 %41, 0
br i1 %42, label %34, label %43
43: ; preds = %34
br i1 %4, label %46, label %44
44: ; preds = %43
%45 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %46
46: ; preds = %44, %43
%47 = load i32, i32* %3
%48 = call i32 @print_gid(i32* %39, i32 %47)
%49 = call i32 @free(i32* %39)
br label %50
50: ; preds = %46, %31
%51 = phi i32 [ %20, %46 ], [ 1, %31 ]
%52 = add nuw nsw i64 %18, 1
%53 = icmp eq i64 %52, %16
br i1 %53, label %54, label %17
54: ; preds = %50, %5
%55 = phi i32 [ 0, %5 ], [ %51, %50 ]
ret i32 %55
}