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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct group *getgrnam(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct group *gr;
  if (argc != 2) {
    printf("ERROR: no arg specified\n");
    exit(1);
  }
  if ((gr = getgrnam(argv[1])) == NULL) {
    printf("FAIL: group %s does not exist\n", argv[1]);
    exit(1);
  }
  printf("PASS: group %s exists\n", argv[1]);
  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     1168 <main+0x38>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a3 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     128b <main+0x15b>
movl   $0x0,-0x1c(%rbp)
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     127d <main+0x14d>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1278 <main+0x148>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121d <main+0xed>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1187 <main+0x37>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <getgrnam@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
jne    119d <main+0x4d>
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xee0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rsi
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rsi
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x18(%r14)
je     123f <main+0xef>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%r14),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1235 <main+0xe5>
mov    $0x8,%ebx
lea    0xe5b(%rip),%r15
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    1210 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1070 <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 = [31 x i8] c"FAIL: group %s does not exist\0A\00"
@.str.2 = [23 x i8] c"PASS: group %s exists\0A\00"
@.str.3 = [14 x i8] c"gr_name = %s\0A\00"
@.str.4 = [16 x i8] c"gr_passwd = %s\0A\00"
@.str.5 = [13 x i8] c"gr_gid = %d\0A\00"
@.str.6 = [10 x i8] c"gr_mem = \00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [2 x i8] c",\00"
@.str.9 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call %struct.group* @getgrnam(i8* %16)
store %struct.group* %17, %struct.group** %6
%18 = icmp eq %struct.group* %17, null
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %13
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load %struct.group*, %struct.group** %6
%31 = getelementptr inbounds %struct.group, %struct.group* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load %struct.group*, %struct.group** %6
%35 = getelementptr inbounds %struct.group, %struct.group* %34, i32 0, i32 1
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 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 2
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load %struct.group*, %struct.group** %6
%43 = getelementptr inbounds %struct.group, %struct.group* %42, i32 0, i32 3
%44 = load i8**, i8*** %43
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %77
46: ; preds = %25
store i32 0, i32* %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %74, %46
%49 = load %struct.group*, %struct.group** %6
%50 = getelementptr inbounds %struct.group, %struct.group* %49, i32 0, i32 3
%51 = load i8**, i8*** %50
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %75
57: ; preds = %48
%58 = load %struct.group*, %struct.group** %6
%59 = getelementptr inbounds %struct.group, %struct.group* %58, i32 0, i32 3
%60 = load i8**, i8*** %59
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
%68 = load %struct.group*, %struct.group** %6
%69 = getelementptr inbounds %struct.group, %struct.group* %68, i32 0, i32 3
%70 = load i8**, i8*** %69
%71 = icmp ne i8** %70, null
br i1 %71, label %72, label %74
72: ; preds = %57
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %74
74: ; preds = %72, %57
br label %48
75: ; preds = %48
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %77
77: ; preds = %75, %25
%78 = call i32 @exit(i32 0)
unreachable
}

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