#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 /*<<< orphan*/ flockfile(int /*<<< orphan*/ *);
int fprintf(int /*<<< orphan*/ *, char *, char *, char *, ...);
int fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/ *);
int putgrent(const struct group *gr, FILE *f) {
  int r;
  size_t i;
  flockfile(f);
  if ((r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid)) < 0)
    goto done;
  if (gr->gr_mem)
    for (i = 0; gr->gr_mem[i]; i++)
      if ((r = fprintf(f, "%s%s", i ? "," : "", gr->gr_mem[i])) < 0)
        goto done;
  r = fputc('\n', f);
done:
  funlockfile(f);
  return r < 0 ? -1 : 0;
}


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
call   1040 <flockfile@plt>
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    0xe85(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1193 <putgrent+0x53>
jmp    123a <putgrent+0xfa>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1229 <putgrent+0xe9>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1224 <putgrent+0xe4>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
lea    0xe40(%rip),%rdx
lea    0xe38(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120e <putgrent+0xce>
jmp    123a <putgrent+0xfa>
jmp    1213 <putgrent+0xd3>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11aa <putgrent+0x6a>
jmp    1229 <putgrent+0xe9>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <funlockfile@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putgrent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <flockfile@plt>
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8d
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %eax,%eax
js     11e1 <putgrent+0xa1>
mov    0x18(%rbx),%rax
test   %rax,%rax
je     11d4 <putgrent+0x94>
mov    (%rax),%rcx
test   %rcx,%rcx
je     11d4 <putgrent+0x94>
lea    0xe7e(%rip),%r13
lea    0xe72(%rip),%r15
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
test   %r12,%r12
mov    %r13,%rdx
lea    0xe63(%rip),%rax
cmove  %rax,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %eax,%eax
js     11e1 <putgrent+0xa1>
mov    0x18(%rbx),%rax
mov    0x8(%rax,%r12,8),%rcx
add    $0x1,%r12
test   %rcx,%rcx
jne    11a0 <putgrent+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <funlockfile@plt>
sar    $0x1f,%ebp
mov    %ebp,%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, i64* }
@.str = [10 x i8] c"%s:%s:%d:\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @putgrent(%struct.group* %0, i32* %1) {
%3 = alloca %struct.group*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
store %struct.group* %0, %struct.group** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = call i32 @flockfile(i32* %7)
%9 = load i32*, i32** %4
%10 = load %struct.group*, %struct.group** %3
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = load %struct.group*, %struct.group** %3
%14 = getelementptr inbounds %struct.group, %struct.group* %13, i32 0, i32 1
%15 = load i8*, i8** %14
%16 = load %struct.group*, %struct.group** %3
%17 = getelementptr inbounds %struct.group, %struct.group* %16, i32 0, i32 2
%18 = load i32, i32* %17
%19 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %15, i32 %18)
store i32 %19, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %2
br label %60
22: ; preds = %2
%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 = icmp ne i64* %25, null
br i1 %26, label %27, label %57
27: ; preds = %22
store i64 0, i64* %6
br label %28
28: ; preds = %53, %27
%29 = load %struct.group*, %struct.group** %3
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i32 0, i32 3
%31 = load i64*, i64** %30
%32 = load i64, i64* %6
%33 = getelementptr inbounds i64, i64* %31, i64 %32
%34 = load i64, i64* %33
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %56
36: ; preds = %28
%37 = load i32*, i32** %4
%38 = load i64, i64* %6
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%42 = load %struct.group*, %struct.group** %3
%43 = getelementptr inbounds %struct.group, %struct.group* %42, i32 0, i32 3
%44 = load i64*, i64** %43
%45 = load i64, i64* %6
%46 = getelementptr inbounds i64, i64* %44, i64 %45
%47 = load i64, i64* %46
%48 = inttoptr i64 %47 to i8*
%49 = call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %48)
store i32 %49, i32* %5
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %36
br label %60
52: ; preds = %36
br label %53
53: ; preds = %52
%54 = load i64, i64* %6
%55 = add i64 %54, 1
store i64 %55, i64* %6
br label %28
56: ; preds = %28
br label %57
57: ; preds = %56, %22
%58 = load i32*, i32** %4
%59 = call i32 @fputc(i8 signext 10, i32* %58)
store i32 %59, i32* %5
br label %60
60: ; preds = %57, %51, %21
%61 = load i32*, i32** %4
%62 = call i32 @funlockfile(i32* %61)
%63 = load i32, i32* %5
%64 = icmp slt i32 %63, 0
%65 = zext i1 %64 to i64
%66 = select i1 %64, i32 -1, i32 0
ret i32 %66
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i64* }
@.str = [10 x i8] c"%s:%s:%d:\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @putgrent(%struct.group* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 @flockfile(i32* %1)
%4 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 2
%9 = load i32, i32* %8
%10 = tail call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %7, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %35, label %12
12: ; preds = %2
%13 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 3
%14 = load i64*, i64** %13
%15 = icmp eq i64* %14, null
br i1 %15, label %33, label %16
16: ; preds = %12
%17 = load i64, i64* %14
%18 = icmp eq i64 %17, 0
br i1 %18, label %33, label %24
19: ; preds = %24
%20 = load i64*, i64** %13
%21 = getelementptr inbounds i64, i64* %20, i64 %32
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %16, %19
%25 = phi i64 [ %22, %19 ], [ %17, %16 ]
%26 = phi i64 [ %32, %19 ], [ 0, %16 ]
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%29 = inttoptr i64 %25 to i8*
%30 = tail call i32 (i32*, i8*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
%31 = icmp slt i32 %30, 0
%32 = add i64 %26, 1
br i1 %31, label %35, label %19
33: ; preds = %19, %16, %12
%34 = tail call i32 @fputc(i8 signext 10, i32* %1)
br label %35
35: ; preds = %24, %2, %33
%36 = phi i32 [ %10, %2 ], [ %34, %33 ], [ %30, %24 ]
%37 = tail call i32 @funlockfile(i32* %1)
%38 = ashr i32 %36, 31
ret i32 %38
}