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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
struct passwd *getpwnam(char const *);
int /*<<< orphan*/ print_entry(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void list_secondary_group_members(const struct group *g) {
  for (char **members = g->gr_mem; *members; members++) {
    errno = 0;
    const struct passwd *u = getpwnam(((const char *)*members));
    if (u) {
      print_entry(u->pw_name, (unsigned long int)u->pw_uid);
    } else {
      fprintf(stderr, "getpwnam(%s) failed: %s\n", ((const char *)*members),
              (errno) ? strerror(errno) : "user not found");
    }
  }
}


x86 assembly (clang, -O0):
<list_secondary_group_members>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1223 <list_secondary_group_members+0xe3>
mov    0x2e6c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <getpwnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a6 <list_secondary_group_members+0x66>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <print_entry@plt>
jmp    120d <list_secondary_group_members+0xcd>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e14(%rip),%rax
cmpq   $0x0,(%rax)
je     11e6 <list_secondary_group_members+0xa6>
mov    0x2e03(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    %rax,-0x30(%rbp)
jmp    11f6 <list_secondary_group_members+0xb6>
lea    0xe2c(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11f6 <list_secondary_group_members+0xb6>
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rcx
lea    0xdf8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1212 <list_secondary_group_members+0xd2>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1157 <list_secondary_group_members+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_secondary_group_members>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%rbx
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11d9 <list_secondary_group_members+0x99>
add    $0x8,%rbx
mov    0x2e73(%rip),%r12
lea    0xead(%rip),%r13
lea    0xe8d(%rip),%r14
jmp    1197 <list_secondary_group_members+0x57>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rax),%edi
mov    (%rax),%rsi
call   1060 <print_entry@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11d9 <list_secondary_group_members+0x99>
movq   $0x0,(%r12)
call   1030 <getpwnam@plt>
test   %rax,%rax
jne    1180 <list_secondary_group_members+0x40>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebp
mov    -0x8(%rbx),%r15
mov    (%r12),%rdi
mov    %r13,%rcx
test   %rdi,%rdi
je     11ca <list_secondary_group_members+0x8a>
call   1050 <strerror@plt>
mov    %rax,%rcx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
jmp    118b <list_secondary_group_members+0x4b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8** }
%struct.passwd = type { i64, i32 }
@errno = global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"getpwnam(%s) failed: %s\0A\00"
@.str.1 = [15 x i8] c"user not found\00"
define void @list_secondary_group_members(%struct.group* %0) {
%2 = alloca %struct.group*
%3 = alloca i8**
%4 = alloca %struct.passwd*
store %struct.group* %0, %struct.group** %2
%5 = load %struct.group*, %struct.group** %2
%6 = getelementptr inbounds %struct.group, %struct.group* %5, i32 0, i32 0
%7 = load i8**, i8*** %6
store i8** %7, i8*** %3
br label %8
8: ; preds = %40, %1
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %43
12: ; preds = %8
store i64 0, i64* @errno
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call %struct.passwd* @getpwnam(i8* %14)
store %struct.passwd* %15, %struct.passwd** %4
%16 = load %struct.passwd*, %struct.passwd** %4
%17 = icmp ne %struct.passwd* %16, null
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = load %struct.passwd*, %struct.passwd** %4
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.passwd*, %struct.passwd** %4
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = call i32 @print_entry(i32 %21, i64 %24)
br label %39
26: ; preds = %12
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %3
%29 = load i8*, i8** %28
%30 = load i64, i64* @errno
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i64, i64* @errno
%34 = call i8* @strerror(i64 %33)
br label %36
35: ; preds = %26
br label %36
36: ; preds = %35, %32
%37 = phi i8* [ %34, %32 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %35 ]
%38 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %37)
br label %39
39: ; preds = %36, %18
br label %40
40: ; preds = %39
%41 = load i8**, i8*** %3
%42 = getelementptr inbounds i8*, i8** %41, i32 1
store i8** %42, i8*** %3
br label %8
43: ; preds = %8
ret void
}

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