#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;
  int /*<<< orphan*/ pw_name;
};
struct group {
  char *gr_name;
};
struct TYPE_2__ {
  char *gr_name;
};

/* Variables and functions */
int /*<<< orphan*/ endgrent();
int /*<<< orphan*/ endpwent();
struct group *getgrent();
TYPE_1__ *getgrgid(int /*<<< orphan*/);
struct passwd *getpwent();
scalar_t__ isUserInGroup(char *, struct group *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setgrent();
int /*<<< orphan*/ setpwent();
scalar_t__ strcmp(int /*<<< orphan*/, char *);
void printListOfGroups(char *userName) {
  struct group *g;
  struct passwd *p;
  setpwent();
  while (p = getpwent()) {
    if (strcmp(p->pw_name, userName) == 0) {
      printf("%s ", getgrgid(p->pw_gid)->gr_name);
      break;
    }
  }
  endpwent();
  setgrent();
  while (g = getgrent()) {
    if (isUserInGroup(userName, g)) {
      printf("%s ", g->gr_name);
    }
  }
  printf("\n");
  endgrent();
}


x86 assembly (clang, -O0):
<printListOfGroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   10a0 <setpwent@plt>
mov    $0x0,%al
call   10b0 <getpwent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1208 <printListOfGroups+0x68>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1203 <printListOfGroups+0x63>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1080 <getgrgid@plt>
mov    (%rax),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1208 <printListOfGroups+0x68>
jmp    11b3 <printListOfGroups+0x13>
mov    $0x0,%al
call   10c0 <endpwent@plt>
mov    $0x0,%al
call   1070 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     125c <printListOfGroups+0xbc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <isUserInGroup@plt>
cmp    $0x0,%rax
je     1257 <printListOfGroups+0xb7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1216 <printListOfGroups+0x76>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <endgrent@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printListOfGroups>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %eax,%eax
call   10b0 <setpwent@plt>
nop
xor    %eax,%eax
call   10c0 <getpwent@plt>
test   %rax,%rax
je     11f7 <printListOfGroups+0x47>
mov    %rax,%rbx
mov    0x4(%rax),%edi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    11c0 <printListOfGroups+0x10>
mov    (%rbx),%edi
call   1090 <getgrgid@plt>
mov    (%rax),%rsi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10d0 <endpwent@plt>
xor    %eax,%eax
call   1080 <setgrent@plt>
xor    %eax,%eax
call   1050 <getgrent@plt>
test   %rax,%rax
je     124e <printListOfGroups+0x9e>
mov    %rax,%rbx
lea    0xde5(%rip),%r14
jmp    122f <printListOfGroups+0x7f>
nopl   (%rax)
xor    %eax,%eax
call   1050 <getgrent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124e <printListOfGroups+0x9e>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <isUserInGroup@plt>
test   %rax,%rax
je     1220 <printListOfGroups+0x70>
mov    (%rbx),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1220 <printListOfGroups+0x70>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <endgrent@plt>

LLVM IR (-O0):
%struct.group = type { i8* }
%struct.passwd = type { i32, i32 }
%struct.TYPE_2__ = type { i8* }
@.str = [4 x i8] c"%s \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @printListOfGroups(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.group*
%4 = alloca %struct.passwd*
store i8* %0, i8** %2
%5 = call i32 (...) @setpwent()
br label %6
6: ; preds = %24, %1
%7 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %7, %struct.passwd** %4
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = load %struct.passwd*, %struct.passwd** %4
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load i8*, i8** %2
%14 = call i64 @strcmp(i32 %12, i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9
%17 = load %struct.passwd*, %struct.passwd** %4
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call %struct.TYPE_2__* @getgrgid(i32 %19)
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %25
24: ; preds = %9
br label %6
25: ; preds = %16, %6
%26 = call i32 (...) @endpwent()
%27 = call i32 (...) @setgrent()
br label %28
28: ; preds = %41, %25
%29 = call %struct.group* (...) @getgrent()
store %struct.group* %29, %struct.group** %3
%30 = icmp ne %struct.group* %29, null
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = load i8*, i8** %2
%33 = load %struct.group*, %struct.group** %3
%34 = call i64 @isUserInGroup(i8* %32, %struct.group* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load %struct.group*, %struct.group** %3
%38 = getelementptr inbounds %struct.group, %struct.group* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %36, %31
br label %28
42: ; preds = %28
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 (...) @endgrent()
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.group = type { i8* }
@.str = [4 x i8] c"%s \00"
define void @printListOfGroups(i8* %0) {
%2 = tail call i32 (...) @setpwent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.passwd* (...) @getpwent()
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i32 %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call %struct.TYPE_2__* @getgrgid(i32 %13)
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %3, %11
%19 = tail call i32 (...) @endpwent()
%20 = tail call i32 (...) @setgrent()
%21 = tail call %struct.group* (...) @getgrent()
%22 = icmp eq %struct.group* %21, null
br i1 %22, label %34, label %23
23: ; preds = %18, %31
%24 = phi %struct.group* [ %32, %31 ], [ %21, %18 ]
%25 = tail call i64 @isUserInGroup(i8* %0, %struct.group* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = getelementptr inbounds %struct.group, %struct.group* %24, i64 0, i32 0
%29 = load i8*, i8** %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %23
%32 = tail call %struct.group* (...) @getgrent()
%33 = icmp eq %struct.group* %32, null
br i1 %33, label %34, label %23
34: ; preds = %31, %18
%35 = tail call i32 @putchar(i32 10)
%36 = tail call i32 (...) @endgrent()
ret void
}