#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;
  int /*<<< orphan*/ **gr_mem;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct group *getgrgid(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct group *p;
  int gid;
  while (--argc > 0) {
    gid = atoi(*++argv);
    if ((p = getgrgid(gid)) == NULL) {
      fprintf(stderr, "getgruid failed: %s\n", strerror(errno));
      continue;
    }
    printf("%s, %s, %d\n", p->gr_name, p->gr_passwd, p->gr_gid);
    while (*p->gr_mem != NULL) {
      printf("\t\t%s\n", *p->gr_mem++);
    }
  }
  return 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)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    123e <main+0xee>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x8a>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe30(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1166 <main+0x16>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%ecx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
cmpq   $0x0,(%rax)
je     1239 <main+0xe9>
mov    -0x18(%rbp),%rcx
mov    0x18(%rcx),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,0x18(%rcx)
mov    (%rax),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fe <main+0xae>
jmp    1166 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1221 <main+0xd1>
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe8f(%rip),%r15
lea    0xe9d(%rip),%r12
lea    0xea2(%rip),%r13
jmp    11c5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e49(%rip),%rax
mov    (%rax),%ebp
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
lea    -0x1(%r14),%eax
add    $0x8,%rbx
cmp    $0x2,%r14d
mov    %eax,%r14d
jle    1221 <main+0xd1>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
call   1040 <getgrgid@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %rax,%rbp
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%ecx
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11b4 <main+0x64>
lea    0x8(%rax),%rcx
mov    %rcx,0x18(%rbp)
mov    (%rax),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1200 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i32** }
@stderr = global i32 0
@.str = [21 x i8] c"getgruid failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"%s, %s, %d\0A\00"
@.str.2 = [6 x i8] c"\09\09%s\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
br label %8
8: ; preds = %50, %20, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call %struct.group* @getgrgid(i32 %17)
store %struct.group* %18, %struct.group** %6
%19 = icmp eq %struct.group* %18, null
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %8
25: ; preds = %12
%26 = load %struct.group*, %struct.group** %6
%27 = getelementptr inbounds %struct.group, %struct.group* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = load %struct.group*, %struct.group** %6
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = load %struct.group*, %struct.group** %6
%33 = getelementptr inbounds %struct.group, %struct.group* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %31, i32 %34)
br label %36
36: ; preds = %42, %25
%37 = load %struct.group*, %struct.group** %6
%38 = getelementptr inbounds %struct.group, %struct.group* %37, i32 0, i32 3
%39 = load i32**, i32*** %38
%40 = load i32*, i32** %39
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %50
42: ; preds = %36
%43 = load %struct.group*, %struct.group** %6
%44 = getelementptr inbounds %struct.group, %struct.group* %43, i32 0, i32 3
%45 = load i32**, i32*** %44
%46 = getelementptr inbounds i32*, i32** %45, i32 1
store i32** %46, i32*** %44
%47 = load i32*, i32** %45
%48 = bitcast i32* %47 to i8*
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %36
50: ; preds = %36
br label %8
51: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i32** }
@stderr = global i32 0
@.str = [21 x i8] c"getgruid failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"%s, %s, %d\0A\00"
@.str.2 = [6 x i8] c"\09\09%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %41
4: ; preds = %2, %18
%5 = phi i32 [ %7, %18 ], [ %0, %2 ]
%6 = phi i8** [ %8, %18 ], [ %1, %2 ]
%7 = add nsw i32 %5, -1
%8 = getelementptr inbounds i8*, i8** %6, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = tail call %struct.group* @getgrgid(i32 %10)
%12 = icmp eq %struct.group* %11, null
br i1 %12, label %13, label %20
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %32, %20, %13
%19 = icmp sgt i32 %5, 2
br i1 %19, label %4, label %41
20: ; preds = %4
%21 = getelementptr inbounds %struct.group, %struct.group* %11, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.group, %struct.group* %11, i64 0, i32 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.group, %struct.group* %11, i64 0, i32 2
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24, i32 %26)
%28 = getelementptr inbounds %struct.group, %struct.group* %11, i64 0, i32 3
%29 = load i32**, i32*** %28
%30 = load i32*, i32** %29
%31 = icmp eq i32* %30, null
br i1 %31, label %18, label %32
32: ; preds = %20, %32
%33 = phi i32** [ %38, %32 ], [ %29, %20 ]
%34 = getelementptr inbounds i32*, i32** %33, i64 1
store i32** %34, i32*** %28
%35 = bitcast i32** %33 to i8**
%36 = load i8*, i8** %35
%37 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32**, i32*** %28
%39 = load i32*, i32** %38
%40 = icmp eq i32* %39, null
br i1 %40, label %18, label %32
41: ; preds = %18, %2
ret i32 0
}