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

/* Variables and functions */
int /*<<< orphan*/ endgrent();
struct group *getgrent();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setgrent();
scalar_t__ strchr(int /*<<< orphan*/, char);
int main(int argc, char **argv) {
  struct group *gr;
  int found = 0;
  int num_users, i;
  for (i = 0; i < 100; i++) {
    gr = getgrent();
  }
  num_users = 0;
  setgrent();
  while (1) {
    gr = getgrent();
    num_users++;
    if (gr == NULL)
      break;
    if (strchr(gr->gr_name, '/')) {
      found = 1;
      break;
    }
  }
  if (!found) {
    printf("FAIL: could not find any domain groups\n");
    return 1;
  }
  endgrent();
  setgrent();
  for (i = 0; i < (num_users - 1); i++) {
    getgrent();
  }
  endgrent();
  for (i = 0; i < 100; i++) {
    setgrent();
  }
  for (i = 0; i < 100; i++) {
    endgrent();
  }
  printf("PASS\n");
  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,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    1197 <main+0x47>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1174 <main+0x24>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1070 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <main+0x79>
jmp    11f4 <main+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x2f,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11ef <main+0x9f>
movl   $0x1,-0x1c(%rbp)
jmp    11f4 <main+0xa4>
jmp    11a5 <main+0x55>
cmpl   $0x0,-0x1c(%rbp)
jne    1216 <main+0xc6>
lea    0xdfb(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x167>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    $0x0,%al
call   1070 <setgrent@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1251 <main+0x101>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122b <main+0xdb>
mov    $0x0,%al
call   1030 <endgrent@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    127e <main+0x12e>
mov    $0x0,%al
call   1070 <setgrent@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125f <main+0x10f>
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    12a4 <main+0x154>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1285 <main+0x135>
lea    0xd7d(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x64,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getgrent@plt>
add    $0xffffffff,%ebx
jne    1160 <main+0x10>
xor    %eax,%eax
call   1070 <setgrent@plt>
mov    $0xffffffff,%ebp
lea    0xe81(%rip),%r14
nop
xor    %eax,%eax
call   1040 <getgrent@plt>
test   %rax,%rax
je     120e <main+0xbe>
mov    (%rax),%edi
mov    $0x2f,%esi
call   1060 <strchr@plt>
add    $0x1,%ebp
test   %rax,%rax
je     1180 <main+0x30>
xor    %eax,%eax
call   1030 <endgrent@plt>
xor    %eax,%eax
call   1070 <setgrent@plt>
test   %ebp,%ebp
je     11cc <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getgrent@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x70>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    $0x64,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <setgrent@plt>
add    $0xffffffff,%ebx
jne    11e0 <main+0x90>
mov    $0x64,%ebx
lea    0xe2f(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <endgrent@plt>
add    $0xffffffff,%ebx
jne    1200 <main+0xb0>
jmp    1213 <main+0xc3>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [40 x i8] c"FAIL: could not find any domain groups\0A\00"
@.str.1 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.group*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %15, %2
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 100
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call %struct.group* (...) @getgrent()
store %struct.group* %14, %struct.group** %6
br label %15
15: ; preds = %13
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 1
store i32 %17, i32* %9
br label %10
18: ; preds = %10
store i32 0, i32* %8
%19 = call i32 (...) @setgrent()
br label %20
20: ; preds = %18, %34
%21 = call %struct.group* (...) @getgrent()
store %struct.group* %21, %struct.group** %6
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = load %struct.group*, %struct.group** %6
%25 = icmp eq %struct.group* %24, null
br i1 %25, label %26, label %27
26: ; preds = %20
br label %35
27: ; preds = %20
%28 = load %struct.group*, %struct.group** %6
%29 = getelementptr inbounds %struct.group, %struct.group* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @strchr(i32 %30, i8 signext 47)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 1, i32* %7
br label %35
34: ; preds = %27
br label %20
35: ; preds = %33, %26
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %74
40: ; preds = %35
%41 = call i32 (...) @endgrent()
%42 = call i32 (...) @setgrent()
store i32 0, i32* %9
br label %43
43: ; preds = %50, %40
%44 = load i32, i32* %9
%45 = load i32, i32* %8
%46 = sub nsw i32 %45, 1
%47 = icmp slt i32 %44, %46
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = call %struct.group* (...) @getgrent()
br label %50
50: ; preds = %48
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %43
53: ; preds = %43
%54 = call i32 (...) @endgrent()
store i32 0, i32* %9
br label %55
55: ; preds = %60, %53
%56 = load i32, i32* %9
%57 = icmp slt i32 %56, 100
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = call i32 (...) @setgrent()
br label %60
60: ; preds = %58
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %55
63: ; preds = %55
store i32 0, i32* %9
br label %64
64: ; preds = %69, %63
%65 = load i32, i32* %9
%66 = icmp slt i32 %65, 100
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = call i32 (...) @endgrent()
br label %69
69: ; preds = %67
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %64
72: ; preds = %64
%73 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %74
74: ; preds = %72, %38
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.group = type { i32 }
@str = [39 x i8] c"FAIL: could not find any domain groups\00"
@str.2 = [5 x i8] c"PASS\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %6, %3 ]
%5 = tail call %struct.group* (...) @getgrent()
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 100
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = tail call i32 (...) @setgrent()
br label %10
10: ; preds = %14, %8
%11 = phi i32 [ 0, %8 ], [ %15, %14 ]
%12 = tail call %struct.group* (...) @getgrent()
%13 = icmp eq %struct.group* %12, null
br i1 %13, label %41, label %14
14: ; preds = %10
%15 = add nuw nsw i32 %11, 1
%16 = getelementptr inbounds %struct.group, %struct.group* %12, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i64 @strchr(i32 %17, i8 signext 47)
%19 = icmp eq i64 %18, 0
br i1 %19, label %10, label %20
20: ; preds = %14
%21 = tail call i32 (...) @endgrent()
%22 = tail call i32 (...) @setgrent()
%23 = icmp eq i32 %11, 0
br i1 %23, label %29, label %24
24: ; preds = %20, %24
%25 = phi i32 [ %27, %24 ], [ 0, %20 ]
%26 = tail call %struct.group* (...) @getgrent()
%27 = add nuw nsw i32 %25, 1
%28 = icmp eq i32 %27, %11
br i1 %28, label %29, label %24
29: ; preds = %24, %20
%30 = tail call i32 (...) @endgrent()
br label %31
31: ; preds = %29, %31
%32 = phi i32 [ 0, %29 ], [ %34, %31 ]
%33 = tail call i32 (...) @setgrent()
%34 = add nuw nsw i32 %32, 1
%35 = icmp eq i32 %34, 100
br i1 %35, label %36, label %31
36: ; preds = %31, %36
%37 = phi i32 [ %39, %36 ], [ 0, %31 ]
%38 = tail call i32 (...) @endgrent()
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %36
41: ; preds = %10, %36
%42 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.2, i64 0, i64 0), %36 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0), %10 ]
%43 = phi i32 [ 0, %36 ], [ 1, %10 ]
%44 = tail call i32 @puts(i8* dereferenceable(1) %42)
ret i32 %43
}