#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 gr_gid;
  char *gr_name;
  char *gr_passwd;
  char **gr_mem;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ endgrent();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct group *getgrent();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setgrent();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  struct group *grp;
  char *user_name;
  if (argc < 2) {
    fprintf(stderr,
            "Usage: %s <user>\n\n"
            "find a <user> in the system.\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  user_name = argv[1];
  while ((grp = getgrent()) != NULL) {
    printf("%6d : %s : %1s : ", grp->gr_gid, grp->gr_name, grp->gr_passwd);
    int i = 0;
    while (grp->gr_mem[i]) {
      printf("%s, ", grp->gr_mem[i]);
      i++;
    }
    printf("\n");
  }
  setgrent();
  while ((grp = getgrent()) != NULL) {
    if (strcmp(user_name, grp->gr_name) == 0) {
      printf("\ngroup \'%s\' is in the system.\n", argv[1]);
      break;
    }
  }
  endgrent();
  return (EXIT_SUCCESS);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11ba <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     125c <main+0xec>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1249 <main+0xd9>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1206 <main+0x96>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11c6 <main+0x56>
mov    $0x0,%al
call   1060 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12b3 <main+0x143>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12b3 <main+0x143>
jmp    1263 <main+0xf3>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jle    127e <main+0xfe>
mov    0x8(%r14),%r12
xor    %eax,%eax
call   1050 <getgrent@plt>
test   %rax,%rax
je     121d <main+0x9d>
mov    %rax,%rbx
lea    0xe7f(%rip),%r15
lea    0xe8a(%rip),%r13
jmp    11d9 <main+0x59>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1050 <getgrent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121d <main+0x9d>
mov    (%rbx),%esi
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     11c0 <main+0x40>
mov    $0x8,%ebp
xchg   %ax,%ax
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%rax
mov    (%rax,%rbp,1),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1200 <main+0x80>
jmp    11c0 <main+0x40>
xor    %eax,%eax
call   1070 <setgrent@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getgrent@plt>
test   %rax,%rax
je     125f <main+0xdf>
mov    0x8(%rax),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1230 <main+0xb0>
mov    0x8(%r14),%rsi
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd6f(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.group = type { i32, i8*, i8*, i8** }
@stderr = global i32 0
@.str = [48 x i8] c"Usage: %s <user>\0A\0Afind a <user> in the system.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%6d : %s : %1s : \00"
@.str.2 = [5 x i8] c"%s, \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [31 x i8] c"\0Agroup '%s' is in the system.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.group*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %7
br label %23
23: ; preds = %57, %19
%24 = call %struct.group* (...) @getgrent()
store %struct.group* %24, %struct.group** %6
%25 = icmp ne %struct.group* %24, null
br i1 %25, label %26, label %59
26: ; preds = %23
%27 = load %struct.group*, %struct.group** %6
%28 = getelementptr inbounds %struct.group, %struct.group* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load %struct.group*, %struct.group** %6
%31 = getelementptr inbounds %struct.group, %struct.group* %30, i32 0, i32 1
%32 = load i8*, i8** %31
%33 = load %struct.group*, %struct.group** %6
%34 = getelementptr inbounds %struct.group, %struct.group* %33, i32 0, i32 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %29, i8* %32, i8* %35)
store i32 0, i32* %8
br label %37
37: ; preds = %46, %26
%38 = load %struct.group*, %struct.group** %6
%39 = getelementptr inbounds %struct.group, %struct.group* %38, i32 0, i32 3
%40 = load i8**, i8*** %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %57
46: ; preds = %37
%47 = load %struct.group*, %struct.group** %6
%48 = getelementptr inbounds %struct.group, %struct.group* %47, i32 0, i32 3
%49 = load i8**, i8*** %48
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %37
57: ; preds = %37
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %23
59: ; preds = %23
%60 = call i32 (...) @setgrent()
br label %61
61: ; preds = %76, %59
%62 = call %struct.group* (...) @getgrent()
store %struct.group* %62, %struct.group** %6
%63 = icmp ne %struct.group* %62, null
br i1 %63, label %64, label %77
64: ; preds = %61
%65 = load i8*, i8** %7
%66 = load %struct.group*, %struct.group** %6
%67 = getelementptr inbounds %struct.group, %struct.group* %66, i32 0, i32 1
%68 = load i8*, i8** %67
%69 = call i64 @strcmp(i8* %65, i8* %68)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %64
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %74)
br label %77
76: ; preds = %64
br label %61
77: ; preds = %71, %61
%78 = call i32 (...) @endgrent()
%79 = load i32, i32* @EXIT_SUCCESS
ret i32 %79
}

LLVM IR (-O2):
%struct.group = type { i32, i8*, i8*, i8** }
@stderr = global i32 0
@.str = [48 x i8] c"Usage: %s <user>\0A\0Afind a <user> in the system.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"%6d : %s : %1s : \00"
@.str.2 = [5 x i8] c"%s, \00"
@.str.4 = [31 x i8] c"\0Agroup '%s' is in the system.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.group* (...) @getgrent()
%14 = icmp eq %struct.group* %13, null
br i1 %14, label %41, label %15
15: ; preds = %10, %37
%16 = phi %struct.group* [ %39, %37 ], [ %13, %10 ]
%17 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 2
%22 = load i8*, i8** %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %20, i8* %22)
%24 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 3
%25 = load i8**, i8*** %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %28
28: ; preds = %15, %28
%29 = phi i64 [ %32, %28 ], [ 0, %15 ]
%30 = phi i8* [ %35, %28 ], [ %26, %15 ]
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = add nuw i64 %29, 1
%33 = load i8**, i8*** %24
%34 = getelementptr inbounds i8*, i8** %33, i64 %32
%35 = load i8*, i8** %34
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %28
37: ; preds = %28, %15
%38 = tail call i32 @putchar(i32 10)
%39 = tail call %struct.group* (...) @getgrent()
%40 = icmp eq %struct.group* %39, null
br i1 %40, label %41, label %15
41: ; preds = %37, %10
%42 = tail call i32 (...) @setgrent()
br label %43
43: ; preds = %46, %41
%44 = tail call %struct.group* (...) @getgrent()
%45 = icmp eq %struct.group* %44, null
br i1 %45, label %54, label %46
46: ; preds = %43
%47 = getelementptr inbounds %struct.group, %struct.group* %44, i64 0, i32 1
%48 = load i8*, i8** %47
%49 = tail call i64 @strcmp(i8* %12, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %43
51: ; preds = %46
%52 = load i8*, i8** %11
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %43, %51
%55 = tail call i32 (...) @endgrent()
%56 = load i32, i32* @EXIT_SUCCESS
ret i32 %56
}