#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 group {
  char *gr_name;
  char *gr_passwd;
  int gr_gid;
  char **gr_mem;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ getgrent_r(struct group *, char *, int, struct group **);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  struct group gr, *tmp;
  char buf[1000];
  while (getgrent_r(&gr, buf, sizeof(buf), &tmp) == 0) {
    int i;
    printf("name %s\tpassword %s\tgid %u\t[", gr.gr_name, gr.gr_passwd,
           gr.gr_gid);
    for (i = 0; i < 8; ++i) {
      if (gr.gr_mem[i])
        printf("%s%s", gr.gr_mem[i], gr.gr_mem[i + 1] ? "," : "");
      else
        break;
    }
    printf("]\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x420(%rbp),%rsi
lea    -0x28(%rbp),%rdi
mov    $0x3e8,%edx
lea    -0x30(%rbp),%rcx
call   1030 <getgrent_r@plt>
cmp    $0x0,%rax
jne    1218 <main+0xf8>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0x8,-0x424(%rbp)
jge    1205 <main+0xe5>
mov    -0x10(%rbp),%rax
movslq -0x424(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e7 <main+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x424(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x10(%rbp),%rax
mov    -0x424(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe61(%rip),%rdx
lea    0xe56(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ec <main+0xcc>
jmp    1205 <main+0xe5>
jmp    11f1 <main+0xd1>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1178 <main+0x58>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1132 <main+0x12>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rcx
mov    $0x3e8,%edx
call   1030 <getgrent_r@plt>
test   %rax,%rax
je     1173 <main+0x43>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%r12
lea    0x30(%rsp),%r13
lea    0x28(%rsp),%rbx
lea    0xe9a(%rip),%r14
lea    0xe92(%rip),%r15
lea    0xe86(%rip),%rbp
jmp    11c4 <main+0x94>
nopl   0x0(%rax)
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x3e8,%edx
mov    %rbx,%rcx
call   1030 <getgrent_r@plt>
test   %rax,%rax
jne    115f <main+0x2f>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%ecx
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x8(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x8(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x10(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x10(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x18(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x18(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x20(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x20(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x28(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x28(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x30(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x30(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x38(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x20(%rsp),%rax
mov    0x38(%rax),%rsi
test   %rsi,%rsi
je     11a0 <main+0x70>
cmpq   $0x0,0x40(%rax)
mov    %r15,%rdx
cmove  %r14,%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <main+0x70>

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i8** }
@.str = [29 x i8] c"name %s\09password %s\09gid %u\09[\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.group
%3 = alloca %struct.group*
%4 = alloca [1000 x i8]
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %52, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i64 @getgrent_r(%struct.group* %2, i8* %7, i32 1000, %struct.group** %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %54
10: ; preds = %6
%11 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 2
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14, i32 %16)
store i32 0, i32* %5
br label %18
18: ; preds = %49, %10
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 8
br i1 %20, label %21, label %52
21: ; preds = %18
%22 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 3
%23 = load i8**, i8*** %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %47
29: ; preds = %21
%30 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 3
%31 = load i8**, i8*** %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = getelementptr inbounds %struct.group, %struct.group* %2, i32 0, i32 3
%37 = load i8**, i8*** %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %37, i64 %40
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
%44 = zext i1 %43 to i64
%45 = select i1 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %45)
br label %48
47: ; preds = %21
br label %52
48: ; preds = %29
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %18
52: ; preds = %47, %18
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %6
54: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i8** }
@.str = [29 x i8] c"name %s\09password %s\09gid %u\09[\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [1 x i8] zeroinitializer
@str = [2 x i8] c"]\00"
define i32 @main() {
%1 = alloca %struct.group
%2 = alloca %struct.group*
%3 = alloca [1000 x i8]
%4 = bitcast %struct.group* %1 to i8*
%5 = bitcast %struct.group** %2 to i8*
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = call i64 @getgrent_r(%struct.group* %1, i8* %6, i32 1000, %struct.group** %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %102
9: ; preds = %0
%10 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 0
%11 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 1
%12 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 2
%13 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 3
br label %14
14: ; preds = %9, %98
%15 = load i8*, i8** %10
%16 = load i8*, i8** %11
%17 = load i32, i32* %12
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16, i32 %17)
%19 = load i8**, i8*** %13
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %98, label %22
22: ; preds = %14
%23 = getelementptr inbounds i8*, i8** %19, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
%26 = select i1 %25, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %26)
%28 = load i8**, i8*** %13
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %98, label %32
32: ; preds = %22
%33 = getelementptr inbounds i8*, i8** %28, i64 2
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
%36 = select i1 %35, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %36)
%38 = load i8**, i8*** %13
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %98, label %42
42: ; preds = %32
%43 = getelementptr inbounds i8*, i8** %38, i64 3
%44 = load i8*, i8** %43
%45 = icmp eq i8* %44, null
%46 = select i1 %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %46)
%48 = load i8**, i8*** %13
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
br i1 %51, label %98, label %52
52: ; preds = %42
%53 = getelementptr inbounds i8*, i8** %48, i64 4
%54 = load i8*, i8** %53
%55 = icmp eq i8* %54, null
%56 = select i1 %55, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %56)
%58 = load i8**, i8*** %13
%59 = getelementptr inbounds i8*, i8** %58, i64 4
%60 = load i8*, i8** %59
%61 = icmp eq i8* %60, null
br i1 %61, label %98, label %62
62: ; preds = %52
%63 = getelementptr inbounds i8*, i8** %58, i64 5
%64 = load i8*, i8** %63
%65 = icmp eq i8* %64, null
%66 = select i1 %65, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %60, i8* %66)
%68 = load i8**, i8*** %13
%69 = getelementptr inbounds i8*, i8** %68, i64 5
%70 = load i8*, i8** %69
%71 = icmp eq i8* %70, null
br i1 %71, label %98, label %72
72: ; preds = %62
%73 = getelementptr inbounds i8*, i8** %68, i64 6
%74 = load i8*, i8** %73
%75 = icmp eq i8* %74, null
%76 = select i1 %75, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %70, i8* %76)
%78 = load i8**, i8*** %13
%79 = getelementptr inbounds i8*, i8** %78, i64 6
%80 = load i8*, i8** %79
%81 = icmp eq i8* %80, null
br i1 %81, label %98, label %82
82: ; preds = %72
%83 = getelementptr inbounds i8*, i8** %78, i64 7
%84 = load i8*, i8** %83
%85 = icmp eq i8* %84, null
%86 = select i1 %85, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %80, i8* %86)
%88 = load i8**, i8*** %13
%89 = getelementptr inbounds i8*, i8** %88, i64 7
%90 = load i8*, i8** %89
%91 = icmp eq i8* %90, null
br i1 %91, label %98, label %92
92: ; preds = %82
%93 = getelementptr inbounds i8*, i8** %88, i64 8
%94 = load i8*, i8** %93
%95 = icmp eq i8* %94, null
%96 = select i1 %95, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %90, i8* %96)
br label %98
98: ; preds = %92, %82, %72, %62, %52, %42, %32, %22, %14
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%100 = call i64 @getgrent_r(%struct.group* %1, i8* %6, i32 1000, %struct.group** %2)
%101 = icmp eq i64 %100, 0
br i1 %101, label %14, label %102
102: ; preds = %98, %0
ret i32 0
}