#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 {
  scalar_t__ gr_gid;
};
typedef scalar_t__ gid_t;
typedef enum nss_status { ____Placeholder_nss_status } nss_status;

/* Variables and functions */
int NSS_STATUS_NOTFOUND;
scalar_t__ NSS_STATUS_SUCCESS;
int /*<<< orphan*/ _nss_exfiles_endgrent();
scalar_t__ _nss_exfiles_getgrent_r(struct group *, char *, size_t, int *);
scalar_t__ _nss_exfiles_setgrent();
int /*<<< orphan*/ exfiles_trace_msg(char *);
enum nss_status _nss_exfiles_getgrgid_r(gid_t gid, struct group *grbuf,
                                        char *buffer, size_t buflen,
                                        int *errnop) {
  enum nss_status status = NSS_STATUS_NOTFOUND;
  exfiles_trace_msg("Entering _nss_exfiles_getgrgid_r");
  if (NSS_STATUS_SUCCESS == _nss_exfiles_setgrent()) {
    while (NSS_STATUS_SUCCESS ==
           _nss_exfiles_getgrent_r(grbuf, buffer, buflen, errnop)) {
      if (gid == grbuf->gr_gid) {
        status = NSS_STATUS_SUCCESS;
        break;
      }
    }
  }
  _nss_exfiles_endgrent();
  return status;
}


x86 assembly (clang, -O0):
<_nss_exfiles_getgrgid_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe91(%rip),%rdi
call   1040 <exfiles_trace_msg@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <_nss_exfiles_setgrent@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jne    11fe <_nss_exfiles_getgrgid_r+0xbe>
jmp    119e <_nss_exfiles_getgrgid_r+0x5e>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <_nss_exfiles_getgrent_r@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    11f9 <_nss_exfiles_getgrgid_r+0xb9>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    11f4 <_nss_exfiles_getgrgid_r+0xb4>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x2c(%rbp)
jmp    11f9 <_nss_exfiles_getgrgid_r+0xb9>
jmp    119e <_nss_exfiles_getgrgid_r+0x5e>
jmp    11fe <_nss_exfiles_getgrgid_r+0xbe>
mov    $0x0,%al
call   1060 <_nss_exfiles_endgrent@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_exfiles_getgrgid_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2e77(%rip),%rax
mov    (%rax),%r14d
lea    0xe95(%rip),%rdi
call   1040 <exfiles_trace_msg@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
xor    %eax,%eax
call   1030 <_nss_exfiles_setgrent@plt>
cmp    %rax,(%rsp)
jne    11c6 <_nss_exfiles_getgrgid_r+0x86>
mov    %r14d,(%rsp)
nop
mov    0x2e51(%rip),%rax
mov    (%rax),%r14
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1050 <_nss_exfiles_getgrent_r@plt>
cmp    %rax,%r14
jne    11c2 <_nss_exfiles_getgrgid_r+0x82>
cmp    %rbx,0x0(%rbp)
jne    1190 <_nss_exfiles_getgrgid_r+0x50>
mov    0x2e2b(%rip),%rax
mov    (%rax),%r14d
jmp    11c6 <_nss_exfiles_getgrgid_r+0x86>
mov    (%rsp),%r14d
xor    %eax,%eax
call   1060 <_nss_exfiles_endgrent@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i64 }
@NSS_STATUS_NOTFOUND = global i32 0
@.str = [33 x i8] c"Entering _nss_exfiles_getgrgid_r\00"
@NSS_STATUS_SUCCESS = global i64 0
define i32 @_nss_exfiles_getgrgid_r(i64 %0, %struct.group* %1, i8* %2, i64 %3, i32* %4) {
%6 = alloca i64
%7 = alloca %struct.group*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
store i64 %0, i64* %6
store %struct.group* %1, %struct.group** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32* %4, i32** %10
%12 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %12, i32* %11
%13 = call i32 @exfiles_trace_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%14 = load i64, i64* @NSS_STATUS_SUCCESS
%15 = call i64 (...) @_nss_exfiles_setgrent()
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %5
br label %18
18: ; preds = %35, %17
%19 = load i64, i64* @NSS_STATUS_SUCCESS
%20 = load %struct.group*, %struct.group** %7
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = load i32*, i32** %10
%24 = call i64 @_nss_exfiles_getgrent_r(%struct.group* %20, i8* %21, i64 %22, i32* %23)
%25 = icmp eq i64 %19, %24
br i1 %25, label %26, label %36
26: ; preds = %18
%27 = load i64, i64* %6
%28 = load %struct.group*, %struct.group** %7
%29 = getelementptr inbounds %struct.group, %struct.group* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = icmp eq i64 %27, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i64, i64* @NSS_STATUS_SUCCESS
%34 = trunc i64 %33 to i32
store i32 %34, i32* %11
br label %36
35: ; preds = %26
br label %18
36: ; preds = %32, %18
br label %37
37: ; preds = %36, %5
%38 = call i32 (...) @_nss_exfiles_endgrent()
%39 = load i32, i32* %11
ret i32 %39
}

LLVM IR (-O2):
%struct.group = type { i64 }
@NSS_STATUS_NOTFOUND = global i32 0
@.str = [33 x i8] c"Entering _nss_exfiles_getgrgid_r\00"
@NSS_STATUS_SUCCESS = global i64 0
define i32 @_nss_exfiles_getgrgid_r(i64 %0, %struct.group* %1, i8* %2, i64 %3, i32* %4) {
%6 = load i32, i32* @NSS_STATUS_NOTFOUND
%7 = tail call i32 @exfiles_trace_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = load i64, i64* @NSS_STATUS_SUCCESS
%9 = tail call i64 (...) @_nss_exfiles_setgrent()
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %5
%12 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 0
br label %13
13: ; preds = %11, %17
%14 = load i64, i64* @NSS_STATUS_SUCCESS
%15 = tail call i64 @_nss_exfiles_getgrent_r(%struct.group* %1, i8* %2, i64 %3, i32* %4)
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i64, i64* %12
%19 = icmp eq i64 %18, %0
br i1 %19, label %20, label %13
20: ; preds = %17
%21 = load i64, i64* @NSS_STATUS_SUCCESS
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %13, %20, %5
%24 = phi i32 [ %22, %20 ], [ %6, %5 ], [ %6, %13 ]
%25 = tail call i32 (...) @_nss_exfiles_endgrent()
ret i32 %24
}