#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 gid_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
struct group *getgrgid(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct group *gr;
  gid_t gid;
  if (argc != 2) {
    printf("ERROR: no arg specified\n");
    exit(1);
  }
  if ((gid = atoi(argv[1])) == 0) {
    printf("ERROR: invalid gid specified\n");
    exit(1);
  }
  if ((gr = getgrgid(gid)) == NULL) {
    printf("FAIL: gid %d does not exist\n", gid);
    exit(1);
  }
  printf("PASS: gid %d exists\n", gid);
  printf("gr_name = %s\n", gr->gr_name);
  printf("gr_passwd = %s\n", gr->gr_passwd);
  printf("gr_gid = %d\n", gr->gr_gid);
  if (gr->gr_mem != NULL) {
    int i = 0;
    printf("gr_mem = ");
    while (gr->gr_mem[i] != NULL) {
      printf("%s", gr->gr_mem[i]);
      i++;
      if (gr->gr_mem != NULL) {
        printf(",");
      }
    }
    printf("\n");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11a9 <main+0x69>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x9a>
mov    -0x1c(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     12bd <main+0x17d>
movl   $0x0,-0x20(%rbp)
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12af <main+0x16f>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     12aa <main+0x16a>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124f <main+0x10f>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1180 <main+0x20>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
jne    1196 <main+0x36>
lea    0xeec(%rip),%rdi
jmp    1187 <main+0x27>
lea    0xf00(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <getgrgid@plt>
test   %rax,%rax
jne    11be <main+0x5e>
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%r14
lea    0xe55(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rsi
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%esi
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x18(%r14)
je     126f <main+0x10f>
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%r14),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1265 <main+0x105>
mov    $0x8,%ebx
lea    0xe34(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    0x18(%r14),%rax
mov    (%rax,%rbx,1),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1240 <main+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i8** }
@.str = [25 x i8] c"ERROR: no arg specified\0A\00"
@.str.1 = [30 x i8] c"ERROR: invalid gid specified\0A\00"
@.str.2 = [29 x i8] c"FAIL: gid %d does not exist\0A\00"
@.str.3 = [21 x i8] c"PASS: gid %d exists\0A\00"
@.str.4 = [14 x i8] c"gr_name = %s\0A\00"
@.str.5 = [16 x i8] c"gr_passwd = %s\0A\00"
@.str.6 = [13 x i8] c"gr_gid = %d\0A\00"
@.str.7 = [10 x i8] c"gr_mem = \00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [2 x i8] c",\00"
@.str.10 = [2 x i8] c"\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = load i32, i32* %7
%25 = call %struct.group* @getgrgid(i32 %24)
store %struct.group* %25, %struct.group** %6
%26 = icmp eq %struct.group* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load %struct.group*, %struct.group** %6
%35 = getelementptr inbounds %struct.group, %struct.group* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = load %struct.group*, %struct.group** %6
%39 = getelementptr inbounds %struct.group, %struct.group* %38, i32 0, i32 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = load %struct.group*, %struct.group** %6
%43 = getelementptr inbounds %struct.group, %struct.group* %42, i32 0, i32 2
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = load %struct.group*, %struct.group** %6
%47 = getelementptr inbounds %struct.group, %struct.group* %46, i32 0, i32 3
%48 = load i8**, i8*** %47
%49 = icmp ne i8** %48, null
br i1 %49, label %50, label %81
50: ; preds = %31
store i32 0, i32* %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %78, %50
%53 = load %struct.group*, %struct.group** %6
%54 = getelementptr inbounds %struct.group, %struct.group* %53, i32 0, i32 3
%55 = load i8**, i8*** %54
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %79
61: ; preds = %52
%62 = load %struct.group*, %struct.group** %6
%63 = getelementptr inbounds %struct.group, %struct.group* %62, i32 0, i32 3
%64 = load i8**, i8*** %63
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %68)
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
%72 = load %struct.group*, %struct.group** %6
%73 = getelementptr inbounds %struct.group, %struct.group* %72, i32 0, i32 3
%74 = load i8**, i8*** %73
%75 = icmp ne i8** %74, null
br i1 %75, label %76, label %78
76: ; preds = %61
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %78
78: ; preds = %76, %61
br label %52
79: ; preds = %52
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %81
81: ; preds = %79, %31
%82 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i8** }
@.str.2 = [29 x i8] c"FAIL: gid %d does not exist\0A\00"
@.str.3 = [21 x i8] c"PASS: gid %d exists\0A\00"
@.str.4 = [14 x i8] c"gr_name = %s\0A\00"
@.str.5 = [16 x i8] c"gr_passwd = %s\0A\00"
@.str.6 = [13 x i8] c"gr_gid = %d\0A\00"
@.str.7 = [10 x i8] c"gr_mem = \00"
@.str.8 = [3 x i8] c"%s\00"
@str = [29 x i8] c"ERROR: invalid gid specified\00"
@str.11 = [24 x i8] c"ERROR: no arg specified\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = tail call %struct.group* @getgrgid(i32 %10)
%17 = icmp eq %struct.group* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%23 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 1
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 2
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds %struct.group, %struct.group* %16, i64 0, i32 3
%33 = load i8**, i8*** %32
%34 = icmp eq i8** %33, null
br i1 %34, label %54, label %35
35: ; preds = %21
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%37 = load i8**, i8*** %32
%38 = load i8*, i8** %37
%39 = icmp eq i8* %38, null
br i1 %39, label %52, label %40
40: ; preds = %35, %40
%41 = phi i64 [ %44, %40 ], [ 0, %35 ]
%42 = phi i8* [ %50, %40 ], [ %38, %35 ]
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %42)
%44 = add nuw i64 %41, 1
%45 = load i8**, i8*** %32
%46 = icmp ne i8** %45, null
%47 = tail call i32 @putchar(i32 44)
%48 = load i8**, i8*** %32
%49 = getelementptr inbounds i8*, i8** %48, i64 %44
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %40
52: ; preds = %40, %35
%53 = tail call i32 @putchar(i32 10)
br label %54
54: ; preds = %52, %21
%55 = tail call i32 @exit(i32 0)
unreachable
}