#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 passwd {
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ endpwent();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getlogin();
struct passwd *getpwent();
int /*<<< orphan*/ printListOfGroups(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setpwent();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  char *user;
  int i;
  int userExists = 0;
  if (argc == 1) {
    printListOfGroups(getlogin());
  } else {
    for (i = 1; i < argc; i++) {
      struct passwd *p;
      setpwent();
      while (p = getpwent()) {
        if (strcmp(p->pw_name, argv[i]) == 0) {
          userExists = 1;
          break;
        }
      }
      endpwent();
      if (!userExists) {
        fprintf(stderr, "groups: '%s': no such user\n", argv[i]);
        return 1;
      }
      printf("%s : ", argv[i]);
      printListOfGroups(argv[i]);
      userExists = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11bb <main+0x3b>
mov    $0x0,%al
call   1090 <getlogin@plt>
mov    %rax,%rdi
call   10a0 <printListOfGroups@plt>
jmp    129d <main+0x11d>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1298 <main+0x118>
mov    $0x0,%al
call   1050 <setpwent@plt>
mov    $0x0,%al
call   1070 <getpwent@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     121c <main+0x9c>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1217 <main+0x97>
movl   $0x1,-0x20(%rbp)
jmp    121c <main+0x9c>
jmp    11d5 <main+0x55>
mov    $0x0,%al
call   1080 <endpwent@plt>
cmpl   $0x0,-0x20(%rbp)
jne    125a <main+0xda>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb7(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x124>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10a0 <printListOfGroups@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <main+0x42>
jmp    129d <main+0x11d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
cmp    $0x1,%edi
jne    11a4 <main+0x24>
xor    %eax,%eax
call   1090 <getlogin@plt>
mov    %rax,%rdi
call   10a0 <printListOfGroups@plt>
jmp    123b <main+0xbb>
cmp    $0x2,%edi
jl     123b <main+0xbb>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%ebp
lea    0xe5d(%rip),%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <setpwent@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <getpwent@plt>
test   %rax,%rax
je     1213 <main+0x93>
mov    (%rax),%edi
mov    (%rbx,%rbp,8),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11d0 <main+0x50>
xor    %eax,%eax
call   1080 <endpwent@plt>
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%rbx,%rbp,8),%rdi
call   10a0 <printListOfGroups@plt>
add    $0x1,%rbp
cmp    %r12,%rbp
jne    11c2 <main+0x42>
jmp    123b <main+0xbb>
xor    %eax,%eax
call   1080 <endpwent@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%eax
mov    (%rbx,%rax,8),%rdx
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"groups: '%s': no such user\0A\00"
@.str.1 = [6 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 %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i8* (...) @getlogin()
%14 = call i32 @printListOfGroups(i8* %13)
br label %67
15: ; preds = %2
store i32 1, i32* %7
br label %16
16: ; preds = %63, %15
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %66
20: ; preds = %16
%21 = call i32 (...) @setpwent()
br label %22
22: ; preds = %37, %20
%23 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %23, %struct.passwd** %9
%24 = icmp ne %struct.passwd* %23, null
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load %struct.passwd*, %struct.passwd** %9
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i32 %28, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %25
store i32 1, i32* %8
br label %38
37: ; preds = %25
br label %22
38: ; preds = %36, %22
%39 = call i32 (...) @endpwent()
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %50, label %42
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %48)
store i32 1, i32* %3
br label %68
50: ; preds = %38
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i8**, i8*** %5
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 @printListOfGroups(i8* %61)
store i32 0, i32* %8
br label %63
63: ; preds = %50
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %16
66: ; preds = %16
br label %67
67: ; preds = %66, %12
store i32 0, i32* %3
br label %68
68: ; preds = %67, %42
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"groups: '%s': no such user\0A\00"
@.str.1 = [6 x i8] c"%s : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %39
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %11
8: ; preds = %2
%9 = tail call i8* (...) @getlogin()
%10 = tail call i32 @printListOfGroups(i8* %9)
br label %39
11: ; preds = %6, %31
%12 = phi i64 [ 1, %6 ], [ %37, %31 ]
%13 = tail call i32 (...) @setpwent()
%14 = getelementptr inbounds i8*, i8** %1, i64 %12
br label %15
15: ; preds = %18, %11
%16 = tail call %struct.passwd* (...) @getpwent()
%17 = icmp eq %struct.passwd* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%20 = load i32, i32* %19
%21 = load i8*, i8** %14
%22 = tail call i64 @strcmp(i32 %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %15
24: ; preds = %15
%25 = tail call i32 (...) @endpwent()
%26 = load i32, i32* @stderr
%27 = and i64 %12, 4294967295
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %39
31: ; preds = %18
%32 = tail call i32 (...) @endpwent()
%33 = load i8*, i8** %14
%34 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %14
%36 = tail call i32 @printListOfGroups(i8* %35)
%37 = add nuw nsw i64 %12, 1
%38 = icmp eq i64 %37, %7
br i1 %38, label %39, label %11
39: ; preds = %31, %4, %24, %8
%40 = phi i32 [ 0, %8 ], [ 1, %24 ], [ 0, %4 ], [ 0, %31 ]
ret i32 %40
}