#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ endgrent();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
struct group *getgrent();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct group *grp;
  char **tmp_memb;
  FILE *fp;
  char file_grp[] = "group_db.txt";
  if ((fp = fopen(file_grp, "w+")) == NULL) {
    fprintf(stderr, "Err.(%s): %s\n", strerror(errno), file_grp);
    exit(EXIT_FAILURE);
  }
  while ((grp = getgrent()) != NULL) {
    fprintf(fp, "%30s | ", grp->gr_name);
    fprintf(fp, "%s | ", grp->gr_passwd);
    fprintf(fp, "%5d | ", grp->gr_gid);
    tmp_memb = grp->gr_mem;
    while (*tmp_memb != NULL) {
      fprintf(fp, "%s, ", *tmp_memb);
      tmp_memb++;
    }
    fprintf(fp, "\n");
  }
  printf("User Group file \'%s\' written.\n", file_grp);
  endgrent();
  fclose(fp);
  free(*tmp_memb);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe53(%rip),%rax
mov    %rax,-0x35(%rbp)
mov    0xe51(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe4c(%rip),%al
mov    %al,-0x29(%rbp)
lea    -0x35(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1224 <main+0x94>
mov    0x2df8(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
lea    -0x35(%rbp),%rcx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1229 <main+0x99>
mov    $0x0,%al
call   1050 <getgrent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12e5 <main+0x155>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     12ce <main+0x13e>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1296 <main+0x106>
mov    -0x28(%rbp),%rdi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1229 <main+0x99>
lea    -0x35(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <free@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x7478742e62645f,%rax
mov    %rax,0xd(%rsp)
movabs $0x62645f70756f7267,%rax
5f 64 62
mov    %rax,0x8(%rsp)
lea    0xe3a(%rip),%rsi
lea    0x8(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12dc <main+0x13c>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getgrent@plt>
test   %rax,%rax
je     129c <main+0xfc>
mov    %rax,%rbp
lea    0xe23(%rip),%r15
lea    0xe22(%rip),%r12
lea    0xe22(%rip),%r13
jmp    123c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
xor    %eax,%eax
call   1050 <getgrent@plt>
mov    %rax,%rbp
test   %rax,%rax
je     129c <main+0xfc>
mov    0x0(%rbp),%rdx
mov    %rbx,%rdi
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x8(%rbp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x10(%rbp),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x18(%rbp),%r14
mov    (%r14),%rdx
test   %rdx,%rdx
je     1220 <main+0x80>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x8(%r14),%rdx
add    $0x8,%r14
test   %rdx,%rdx
jne    1280 <main+0xe0>
jmp    1220 <main+0x80>
lea    0xd95(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <printf@plt>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    (%r14),%rdi
call   1040 <free@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfd(%rip),%rax
movslq (%rax),%rbx
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd15(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i8** }
@__const.main.file_grp = [13 x i8] c"group_db.txt\00"
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [14 x i8] c"Err.(%s): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"%30s | \00"
@.str.3 = [6 x i8] c"%s | \00"
@.str.4 = [7 x i8] c"%5d | \00"
@.str.5 = [5 x i8] c"%s, \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [31 x i8] c"User Group file '%s' written.\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 i8**
%8 = alloca i32*
%9 = alloca [13 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [13 x i8]* %9 to i8*
%11 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
br label %25
25: ; preds = %58, %24
%26 = call %struct.group* (...) @getgrent()
store %struct.group* %26, %struct.group** %6
%27 = icmp ne %struct.group* %26, null
br i1 %27, label %28, label %61
28: ; preds = %25
%29 = load i32*, i32** %8
%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 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32*, i32** %8
%35 = load %struct.group*, %struct.group** %6
%36 = getelementptr inbounds %struct.group, %struct.group* %35, i32 0, i32 1
%37 = load i8*, i8** %36
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %8
%40 = load %struct.group*, %struct.group** %6
%41 = getelementptr inbounds %struct.group, %struct.group* %40, i32 0, i32 2
%42 = load i32, i32* %41
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load %struct.group*, %struct.group** %6
%45 = getelementptr inbounds %struct.group, %struct.group* %44, i32 0, i32 3
%46 = load i8**, i8*** %45
store i8** %46, i8*** %7
br label %47
47: ; preds = %51, %28
%48 = load i8**, i8*** %7
%49 = load i8*, i8** %48
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %58
51: ; preds = %47
%52 = load i32*, i32** %8
%53 = load i8**, i8*** %7
%54 = load i8*, i8** %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i8**, i8*** %7
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %7
br label %47
58: ; preds = %47
%59 = load i32*, i32** %8
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %25
61: ; preds = %25
%62 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%63 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %62)
%64 = call i32 (...) @endgrent()
%65 = load i32*, i32** %8
%66 = call i32 @fclose(i32* %65)
%67 = load i8**, i8*** %7
%68 = load i8*, i8** %67
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* @EXIT_SUCCESS
ret i32 %70
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i8** }
@__const.main.file_grp = [13 x i8] c"group_db.txt\00"
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [14 x i8] c"Err.(%s): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [8 x i8] c"%30s | \00"
@.str.3 = [6 x i8] c"%s | \00"
@.str.4 = [7 x i8] c"%5d | \00"
@.str.5 = [5 x i8] c"%s, \00"
@.str.7 = [31 x i8] c"User Group file '%s' written.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [13 x i8]
%4 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call %struct.group* (...) @getgrent()
%9 = icmp eq %struct.group* %8, null
br i1 %9, label %46, label %19
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %4)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %7, %41
%20 = phi %struct.group* [ %44, %41 ], [ %8, %7 ]
%21 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 2
%28 = load i32, i32* %27
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds %struct.group, %struct.group* %20, i64 0, i32 3
%31 = load i8**, i8*** %30
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %41, label %34
34: ; preds = %19, %34
%35 = phi i8* [ %39, %34 ], [ %32, %19 ]
%36 = phi i8** [ %38, %34 ], [ %31, %19 ]
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%38 = getelementptr inbounds i8*, i8** %36, i64 1
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %34
41: ; preds = %34, %19
%42 = phi i8** [ %31, %19 ], [ %38, %34 ]
%43 = tail call i32 @fputc(i32 10, i32* %5)
%44 = tail call %struct.group* (...) @getgrent()
%45 = icmp eq %struct.group* %44, null
br i1 %45, label %46, label %19
46: ; preds = %41, %7
%47 = phi i8** [ undef, %7 ], [ %42, %41 ]
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%49 = call i32 (...) @endgrent()
%50 = call i32 @fclose(i32* %5)
%51 = load i8*, i8** %47
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}