#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 {
  scalar_t__ pw_gid;
  scalar_t__ pw_uid;
  int /*<<< orphan*/ pw_name;
};
struct group {
  scalar_t__ gr_gid;
};

/* Variables and functions */
int /*<<< orphan*/ endpwent();
scalar_t__ errno;
struct passwd *getpwent();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_entry(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ setpwent();
void list_primary_group_members(const struct group *g) {
  setpwent();
  errno = 0;
  struct passwd *u;
  while ((u = getpwent())) {
    if (u->pw_gid == g->gr_gid)
      print_entry(u->pw_name, (unsigned long int)u->pw_uid);
    errno = 0;
  }
  if (errno)
    perror("getpwent");
  endpwent();
}


x86 assembly (clang, -O0):
<list_primary_group_members>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <setpwent@plt>
mov    0x2e76(%rip),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1040 <getpwent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11c1 <list_primary_group_members+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jne    11ae <list_primary_group_members+0x5e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <print_entry@plt>
mov    0x2e2b(%rip),%rax
movq   $0x0,(%rax)
jmp    1171 <list_primary_group_members+0x21>
mov    0x2e18(%rip),%rax
cmpq   $0x0,(%rax)
je     11de <list_primary_group_members+0x8e>
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1050 <endpwent@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_primary_group_members>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <setpwent@plt>
mov    0x2e7b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movq   $0x0,(%r14)
xor    %eax,%eax
call   1040 <getpwent@plt>
test   %rax,%rax
je     1199 <list_primary_group_members+0x49>
mov    (%rax),%rcx
cmp    (%rbx),%rcx
jne    1170 <list_primary_group_members+0x20>
mov    0x10(%rax),%edi
mov    0x8(%rax),%rsi
call   1070 <print_entry@plt>
jmp    1170 <list_primary_group_members+0x20>
cmpq   $0x0,(%r14)
jne    11ad <list_primary_group_members+0x5d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <endpwent@plt>
lea    0xe4c(%rip),%rdi
call   1060 <perror@plt>
jmp    119f <list_primary_group_members+0x4f>

LLVM IR (-O0):
%struct.group = type { i64 }
%struct.passwd = type { i64, i64, i32 }
@errno = global i64 0
@.str = [9 x i8] c"getpwent\00"
define void @list_primary_group_members(%struct.group* %0) {
%2 = alloca %struct.group*
%3 = alloca %struct.passwd*
store %struct.group* %0, %struct.group** %2
%4 = call i32 (...) @setpwent()
store i64 0, i64* @errno
br label %5
5: ; preds = %24, %1
%6 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %6, %struct.passwd** %3
%7 = icmp ne %struct.passwd* %6, null
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load %struct.passwd*, %struct.passwd** %3
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load %struct.group*, %struct.group** %2
%13 = getelementptr inbounds %struct.group, %struct.group* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %11, %14
br i1 %15, label %16, label %24
16: ; preds = %8
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = load %struct.passwd*, %struct.passwd** %3
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i32 0, i32 1
%22 = load i64, i64* %21
%23 = call i32 @print_entry(i32 %19, i64 %22)
br label %24
24: ; preds = %16, %8
store i64 0, i64* @errno
br label %5
25: ; preds = %5
%26 = load i64, i64* @errno
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = call i32 (...) @endpwent()
ret void
}

LLVM IR (-O2):
%struct.group = type { i64 }
%struct.passwd = type { i64, i64, i32 }
@errno = global i64 0
@.str = [9 x i8] c"getpwent\00"
define void @list_primary_group_members(%struct.group* nocapture %0) {
%2 = tail call i32 (...) @setpwent()
store i64 0, i64* @errno
%3 = tail call %struct.passwd* (...) @getpwent()
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 0
br label %7
7: ; preds = %5, %19
%8 = phi %struct.passwd* [ %3, %5 ], [ %20, %19 ]
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* %6
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 1
%17 = load i64, i64* %16
%18 = tail call i32 @print_entry(i32 %15, i64 %17)
br label %19
19: ; preds = %13, %7
store i64 0, i64* @errno
%20 = tail call %struct.passwd* (...) @getpwent()
%21 = icmp eq %struct.passwd* %20, null
br i1 %21, label %22, label %7
22: ; preds = %19, %1
%23 = load i64, i64* @errno
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = tail call i32 (...) @endpwent()
ret void
}