#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 */
struct group *getgrnam(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: test-group <name>\n");
    return -1;
  }
  char *name = argv[1];
  struct group *result = getgrnam(name);
  if (!result) {
    printf("Group %s not found.\n", name);
    return -1;
  }
  printf("Name      : %s\n", result->gr_name);
  printf("Password  : %s\n", result->gr_passwd);
  printf("GID       : %d\n", result->gr_gid);
  char **member = result->gr_mem;
  while (member != NULL && (*member) != NULL) {
    printf("Member    : %s\n", (*member));
    member++;
  }
  printf("\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)
cmpl   $0x2,-0x8(%rbp)
je     115a <main+0x3a>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <main+0x7c>
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <main+0x131>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     1206 <main+0xe6>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1216 <main+0xf6>
jmp    123c <main+0x11c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11e8 <main+0xc8>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <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
cmp    $0x2,%edi
jne    11e3 <main+0xa3>
mov    0x8(%rsi),%rbp
mov    %rbp,%rdi
call   1060 <getgrnam@plt>
test   %rax,%rax
je     11f1 <main+0xb1>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xea6(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rsi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%esi
lea    0xea0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%rbp
test   %rbp,%rbp
je     11d7 <main+0x97>
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     11d7 <main+0x97>
add    $0x8,%rbp
lea    0xe8c(%rip),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    11c0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1208 <main+0xc8>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
jmp    1202 <main+0xc2>
lea    0xe08(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i8** }
@.str = [26 x i8] c"Usage: test-group <name>\0A\00"
@.str.1 = [21 x i8] c"Group %s not found.\0A\00"
@.str.2 = [16 x i8] c"Name : %s\0A\00"
@.str.3 = [16 x i8] c"Password : %s\0A\00"
@.str.4 = [16 x i8] c"GID : %d\0A\00"
@.str.5 = [16 x i8] c"Member : %s\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.group*
%8 = alloca i8**
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 %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %57
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call %struct.group* @getgrnam(i8* %17)
store %struct.group* %18, %struct.group** %7
%19 = load %struct.group*, %struct.group** %7
%20 = icmp ne %struct.group* %19, null
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %57
24: ; preds = %13
%25 = load %struct.group*, %struct.group** %7
%26 = getelementptr inbounds %struct.group, %struct.group* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load %struct.group*, %struct.group** %7
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load %struct.group*, %struct.group** %7
%34 = getelementptr inbounds %struct.group, %struct.group* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load %struct.group*, %struct.group** %7
%38 = getelementptr inbounds %struct.group, %struct.group* %37, i32 0, i32 3
%39 = load i8**, i8*** %38
store i8** %39, i8*** %8
br label %40
40: ; preds = %49, %24
%41 = load i8**, i8*** %8
%42 = icmp ne i8** %41, null
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i8**, i8*** %8
%45 = load i8*, i8** %44
%46 = icmp ne i8* %45, null
br label %47
47: ; preds = %43, %40
%48 = phi i1 [ false, %40 ], [ %46, %43 ]
br i1 %48, label %49, label %55
49: ; preds = %47
%50 = load i8**, i8*** %8
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i8**, i8*** %8
%54 = getelementptr inbounds i8*, i8** %53, i32 1
store i8** %54, i8*** %8
br label %40
55: ; preds = %47
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %57
57: ; preds = %55, %21, %11
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i8** }
@.str.1 = [21 x i8] c"Group %s not found.\0A\00"
@.str.2 = [16 x i8] c"Name : %s\0A\00"
@.str.3 = [16 x i8] c"Password : %s\0A\00"
@.str.4 = [16 x i8] c"GID : %d\0A\00"
@.str.5 = [16 x i8] c"Member : %s\0A\00"
@str = [25 x i8] c"Usage: test-group <name>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %38
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call %struct.group* @getgrnam(i8* %8)
%10 = icmp eq %struct.group* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %38
13: ; preds = %6
%14 = getelementptr inbounds %struct.group, %struct.group* %9, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds %struct.group, %struct.group* %9, i64 0, i32 1
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.group, %struct.group* %9, i64 0, i32 2
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds %struct.group, %struct.group* %9, i64 0, i32 3
%24 = load i8**, i8*** %23
%25 = icmp eq i8** %24, null
br i1 %25, label %36, label %26
26: ; preds = %13
%27 = load i8*, i8** %24
%28 = icmp eq i8* %27, null
br i1 %28, label %36, label %29
29: ; preds = %26, %29
%30 = phi i8* [ %34, %29 ], [ %27, %26 ]
%31 = phi i8** [ %33, %29 ], [ %24, %26 ]
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%33 = getelementptr inbounds i8*, i8** %31, i64 1
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %29
36: ; preds = %29, %26, %13
%37 = tail call i32 @putchar(i32 10)
br label %38
38: ; preds = %11, %36, %4
%39 = phi i32 [ -1, %4 ], [ 0, %36 ], [ -1, %11 ]
ret i32 %39
}