#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;
  scalar_t__ *gr_mem;
  scalar_t__ gr_gid;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ _SC_GETGR_R_SIZE_MAX;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getgrnam_r(char *, struct group *, char *, size_t, struct group **);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
size_t sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct group pwd;
  struct group *result;
  char *buf;
  size_t bufsize;
  int s;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s groupname\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
  if (bufsize == -1)
    bufsize = 16384;
  buf = malloc(bufsize);
  if (buf == NULL) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  s = getgrnam_r(argv[1], &pwd, buf, bufsize, &result);
  if (result == NULL) {
    if (s == 0)
      printf("Not found\n");
    else {
      errno = s;
      perror("getgrnam_r");
    }
    exit(EXIT_FAILURE);
  }
  printf("Name: [%p] %s; GID: %ld\n", pwd.gr_name, pwd.gr_name,
         (long)pwd.gr_gid);
  for (int i = 0; pwd.gr_mem[i] != 0; ++i)
    printf("  [%p] %s\n", pwd.gr_mem[i], pwd.gr_mem[i]);
  char *p = buf;
  while (p && strlen(p) > 0) {
    printf("[%p] %s\n", p, p);
    p += strlen(p) + 1;
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ca <main+0x4a>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    11ef <main+0x6f>
movq   $0x4000,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1221 <main+0xa1>
lea    0xe07(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%r8
call   1090 <getgrnam_r@plt>
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    128f <main+0x10f>
cmpl   $0x0,-0x44(%rbp)
jne    1269 <main+0xe9>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1281 <main+0x101>
mov    -0x44(%rbp),%ecx
mov    0x2d5d(%rip),%rax
mov    %ecx,(%rax)
lea    0xdab(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12f7 <main+0x177>
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12b0 <main+0x130>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x50(%rbp)
mov    %al,-0x51(%rbp)
je     1322 <main+0x1a2>
mov    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1332 <main+0x1b2>
jmp    1362 <main+0x1e2>
mov    -0x50(%rbp),%rsi
mov    -0x50(%rbp),%rdx
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
add    -0x50(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    12ff <main+0x17f>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11d5 <main+0x45>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1090 <sysconf@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x4000,%r15d
cmovne %rax,%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
jne    11ef <main+0x5f>
lea    0xe42(%rip),%rdi
jmp    122b <main+0x9b>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe18(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1230 <main+0xa0>
mov    %rax,%r12
mov    0x8(%r14),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %rax,%rdx
mov    %r15,%rcx
call   10a0 <getgrnam_r@plt>
cmpq   $0x0,0x8(%rsp)
jne    123e <main+0xae>
test   %eax,%eax
je     12fa <main+0x16a>
mov    0x2dae(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf1(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0x10(%rsp),%rdx
mov    0x20(%rsp),%rcx
lea    0xdd8(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     129f <main+0x10f>
mov    $0x8,%ebx
lea    0xdce(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%rax
mov    (%rax,%rbx,1),%rdx
add    $0x8,%rbx
test   %rdx,%rdx
jne    1280 <main+0xf0>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    12ec <main+0x15c>
lea    0xd8f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jg     12c0 <main+0x130>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xd4a(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <main+0xa0>

LLVM IR (-O0):
%struct.group = type { i8*, i64*, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s groupname\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_GETGR_R_SIZE_MAX = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [11 x i8] c"Not found\0A\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"getgrnam_r\00"
@.str.4 = [25 x i8] c"Name: [%p] %s; GID: %ld\0A\00"
@.str.5 = [11 x i8] c" [%p] %s\0A\00"
@.str.6 = [9 x i8] c"[%p] %s\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 %struct.group*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* @_SC_GETGR_R_SIZE_MAX
%25 = call i64 @sysconf(i32 %24)
store i64 %25, i64* %9
%26 = load i64, i64* %9
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %23
store i64 16384, i64* %9
br label %29
29: ; preds = %28, %23
%30 = load i64, i64* %9
%31 = call i8* @malloc(i64 %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8*, i8** %8
%43 = load i64, i64* %9
%44 = call i32 @getgrnam_r(i8* %41, %struct.group* %6, i8* %42, i64 %43, %struct.group** %7)
store i32 %44, i32* %10
%45 = load %struct.group*, %struct.group** %7
%46 = icmp eq %struct.group* %45, null
br i1 %46, label %47, label %58
47: ; preds = %38
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %55
52: ; preds = %47
%53 = load i32, i32* %10
store i32 %53, i32* @errno
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %52, %50
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %38
%59 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 2
%64 = load i64, i64* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %60, i8* %62, i64 %64)
store i32 0, i32* %11
br label %66
66: ; preds = %88, %58
%67 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 1
%68 = load i64*, i64** %67
%69 = load i32, i32* %11
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i64, i64* %68, i64 %70
%72 = load i64, i64* %71
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %91
74: ; preds = %66
%75 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 1
%76 = load i64*, i64** %75
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i64, i64* %76, i64 %78
%80 = load i64, i64* %79
%81 = getelementptr inbounds %struct.group, %struct.group* %6, i32 0, i32 1
%82 = load i64*, i64** %81
%83 = load i32, i32* %11
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i64, i64* %82, i64 %84
%86 = load i64, i64* %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 %80, i64 %86)
br label %88
88: ; preds = %74
%89 = load i32, i32* %11
%90 = add nsw i32 %89, 1
store i32 %90, i32* %11
br label %66
91: ; preds = %66
%92 = load i8*, i8** %8
store i8* %92, i8** %12
br label %93
93: ; preds = %102, %91
%94 = load i8*, i8** %12
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %100
96: ; preds = %93
%97 = load i8*, i8** %12
%98 = call i64 @strlen(i8* %97)
%99 = icmp sgt i64 %98, 0
br label %100
100: ; preds = %96, %93
%101 = phi i1 [ false, %93 ], [ %99, %96 ]
br i1 %101, label %102, label %111
102: ; preds = %100
%103 = load i8*, i8** %12
%104 = load i8*, i8** %12
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %103, i8* %104)
%106 = load i8*, i8** %12
%107 = call i64 @strlen(i8* %106)
%108 = add nsw i64 %107, 1
%109 = load i8*, i8** %12
%110 = getelementptr inbounds i8, i8* %109, i64 %108
store i8* %110, i8** %12
br label %93
111: ; preds = %100
%112 = load i32, i32* @EXIT_SUCCESS
%113 = call i32 @exit(i32 %112)
unreachable
}

LLVM IR (-O2):
%struct.group = type { i8*, i64*, i64 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s groupname\0A\00"
@EXIT_FAILURE = global i32 0
@_SC_GETGR_R_SIZE_MAX = global i32 0
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"getgrnam_r\00"
@.str.4 = [25 x i8] c"Name: [%p] %s; GID: %ld\0A\00"
@.str.5 = [11 x i8] c" [%p] %s\0A\00"
@.str.6 = [9 x i8] c"[%p] %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [10 x i8] c"Not found\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.group
%4 = alloca %struct.group*
%5 = bitcast %struct.group* %3 to i8*
%6 = bitcast %struct.group** %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @_SC_GETGR_R_SIZE_MAX
%16 = tail call i64 @sysconf(i32 %15)
%17 = icmp eq i64 %16, -1
%18 = select i1 %17, i64 16384, i64 %16
%19 = tail call i8* @malloc(i64 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @getgrnam_r(i8* %27, %struct.group* %3, i8* %19, i64 %18, %struct.group** %4)
%29 = load %struct.group*, %struct.group** %4
%30 = icmp eq %struct.group* %29, null
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = icmp eq i32 %28, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %37
35: ; preds = %31
store i32 %28, i32* @errno
%36 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %25
%41 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 2
%44 = load i64, i64* %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %42, i64 %44)
%46 = getelementptr inbounds %struct.group, %struct.group* %3, i64 0, i32 1
%47 = load i64*, i64** %46
%48 = load i64, i64* %47
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %53, %40
%51 = call i64 @strlen(i8* dereferenceable(1) %19)
%52 = icmp sgt i64 %51, 0
br i1 %52, label %62, label %70
53: ; preds = %40, %53
%54 = phi i64 [ %57, %53 ], [ 0, %40 ]
%55 = phi i64 [ %60, %53 ], [ %48, %40 ]
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 %55, i64 %55)
%57 = add nuw i64 %54, 1
%58 = load i64*, i64** %46
%59 = getelementptr inbounds i64, i64* %58, i64 %57
%60 = load i64, i64* %59
%61 = icmp eq i64 %60, 0
br i1 %61, label %50, label %53
62: ; preds = %50, %62
%63 = phi i8* [ %67, %62 ], [ %19, %50 ]
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %63, i8* %63)
%65 = call i64 @strlen(i8* dereferenceable(1) %63)
%66 = add nsw i64 %65, 1
%67 = getelementptr inbounds i8, i8* %63, i64 %66
%68 = call i64 @strlen(i8* dereferenceable(1) %67)
%69 = icmp sgt i64 %68, 0
br i1 %69, label %62, label %70
70: ; preds = %62, %50
%71 = load i32, i32* @EXIT_SUCCESS
%72 = call i32 @exit(i32 %71)
unreachable
}