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

/* Variables and functions */
int fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int putgrent(const struct group *g, FILE *f) {
  int idx;
  fprintf(f, "%s:%s:%u:", g->gr_name, g->gr_passwd, g->gr_gid);
  if (g->gr_mem)
    for (idx = 0; g->gr_mem[idx]; idx++)
      fprintf(f, ((idx == 0) ? "%s" : ",%s"), g->gr_mem[idx]);
  fprintf(f, "\n");
  return fflush(f);
}


x86 assembly (clang, -O0):
<putgrent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%r8d
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     11cc <putgrent+0xac>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c7 <putgrent+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xe76(%rip),%rsi
lea    0xe70(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <putgrent+0x4f>
jmp    11cc <putgrent+0xac>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putgrent>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
mov    (%rdi),%rdx
mov    0x8(%rdi),%rcx
mov    0x10(%rdi),%r8d
lea    0xeaf(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x18(%r13),%rax
test   %rax,%rax
je     11a6 <putgrent+0x76>
mov    (%rax),%rdx
test   %rdx,%rdx
je     11a6 <putgrent+0x76>
lea    0xe98(%rip),%r15
lea    0xe90(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
test   %rbx,%rbx
mov    %r12,%rsi
cmove  %r15,%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x18(%r13),%rax
mov    0x8(%rax,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1180 <putgrent+0x50>
mov    $0xa,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fflush@plt>

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i64* }
@.str = [10 x i8] c"%s:%s:%u:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c",%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @putgrent(%struct.group* %0, i32* %1) {
%3 = alloca %struct.group*
%4 = alloca i32*
%5 = alloca i32
store %struct.group* %0, %struct.group** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = load %struct.group*, %struct.group** %3
%8 = getelementptr inbounds %struct.group, %struct.group* %7, i32 0, i32 0
%9 = load i8*, i8** %8
%10 = load %struct.group*, %struct.group** %3
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 1
%12 = load i8*, i8** %11
%13 = load %struct.group*, %struct.group** %3
%14 = getelementptr inbounds %struct.group, %struct.group* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %12, i32 %15)
%17 = load %struct.group*, %struct.group** %3
%18 = getelementptr inbounds %struct.group, %struct.group* %17, i32 0, i32 3
%19 = load i64*, i64** %18
%20 = icmp ne i64* %19, null
br i1 %20, label %21, label %49
21: ; preds = %2
store i32 0, i32* %5
br label %22
22: ; preds = %45, %21
%23 = load %struct.group*, %struct.group** %3
%24 = getelementptr inbounds %struct.group, %struct.group* %23, i32 0, i32 3
%25 = load i64*, i64** %24
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i64, i64* %25, i64 %27
%29 = load i64, i64* %28
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %22
%32 = load i32*, i32** %4
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%37 = load %struct.group*, %struct.group** %3
%38 = getelementptr inbounds %struct.group, %struct.group* %37, i32 0, i32 3
%39 = load i64*, i64** %38
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i64, i64* %39, i64 %41
%43 = load i64, i64* %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* %36, i64 %43)
br label %45
45: ; preds = %31
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %22
48: ; preds = %22
br label %49
49: ; preds = %48, %2
%50 = load i32*, i32** %4
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32*, i32** %4
%53 = call i32 @fflush(i32* %52)
ret i32 %53
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i64* }
@.str = [10 x i8] c"%s:%s:%u:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c",%s\00"
define i32 @putgrent(%struct.group* nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 0
%4 = load i8*, i8** %3
%5 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 2
%8 = load i32, i32* %7
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %6, i32 %8)
%10 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 3
%11 = load i64*, i64** %10
%12 = icmp eq i64* %11, null
br i1 %12, label %27, label %13
13: ; preds = %2
%14 = load i64, i64* %11
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13, %16
%17 = phi i64 [ %22, %16 ], [ 0, %13 ]
%18 = phi i64 [ %25, %16 ], [ %14, %13 ]
%19 = icmp eq i64 %17, 0
%20 = select i1 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* %20, i64 %18)
%22 = add nuw i64 %17, 1
%23 = load i64*, i64** %10
%24 = getelementptr inbounds i64, i64* %23, i64 %22
%25 = load i64, i64* %24
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %16
27: ; preds = %16, %13, %2
%28 = tail call i32 @fputc(i32 10, i32* %1)
%29 = tail call i32 @fflush(i32* %1)
ret i32 %29
}