#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 const *gr_name;
};
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 strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
enum nss_status _nss_exfiles_getgrnam_r(const char *grnam, struct group *grbuf,
                                        char *buffer, size_t buflen,
                                        int *errnop) {
  enum nss_status status = NSS_STATUS_NOTFOUND;
  int grname_length;
  grname_length = strlen(grnam);
  if (NSS_STATUS_SUCCESS == _nss_exfiles_setgrent()) {
    while (NSS_STATUS_SUCCESS ==
           _nss_exfiles_getgrent_r(grbuf, buffer, buflen, errnop)) {
      if (strlen(grbuf->gr_name) != grname_length)
        break;
      if (0 == strncmp(grnam, grbuf->gr_name, grname_length)) {
        status = NSS_STATUS_SUCCESS;
        break;
      }
    }
  }
  _nss_exfiles_endgrent();
  return status;
}


x86 assembly (clang, -O0):
<_nss_exfiles_getgrnam_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    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    0x2e5d(%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    1238 <_nss_exfiles_getgrnam_r+0xe8>
jmp    11ae <_nss_exfiles_getgrnam_r+0x5e>
mov    0x2e33(%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   1060 <_nss_exfiles_getgrent_r@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jne    1233 <_nss_exfiles_getgrnam_r+0xe3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    -0x30(%rbp),%eax
je     11fb <_nss_exfiles_getgrnam_r+0xab>
jmp    1233 <_nss_exfiles_getgrnam_r+0xe3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    122e <_nss_exfiles_getgrnam_r+0xde>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x2c(%rbp)
jmp    1233 <_nss_exfiles_getgrnam_r+0xe3>
jmp    11ae <_nss_exfiles_getgrnam_r+0x5e>
jmp    1238 <_nss_exfiles_getgrnam_r+0xe8>
mov    $0x0,%al
call   1070 <_nss_exfiles_endgrent@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nss_exfiles_getgrnam_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    0x2e5d(%rip),%r12
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1030 <_nss_exfiles_setgrent@plt>
cmp    %rax,0x8(%rsp)
jne    11f9 <_nss_exfiles_getgrnam_r+0xa9>
mov    %r15,0x8(%rsp)
mov    %r12,%rax
nopw   0x0(%rax,%rax,1)
mov    %rax,%r12
mov    (%rax),%r15
mov    %rbp,%rdi
mov    %r13,%rsi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
call   1060 <_nss_exfiles_getgrent_r@plt>
cmp    %rax,%r15
jne    11f9 <_nss_exfiles_getgrnam_r+0xa9>
mov    0x0(%rbp),%rdi
call   1050 <strlen@plt>
cmp    %r14d,%eax
jne    11f9 <_nss_exfiles_getgrnam_r+0xa9>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
mov    %r12,%rax
jne    11b0 <_nss_exfiles_getgrnam_r+0x60>
mov    (%rax),%ebx
jmp    11fd <_nss_exfiles_getgrnam_r+0xad>
mov    0x4(%rsp),%ebx
xor    %eax,%eax
call   1070 <_nss_exfiles_endgrent@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8* }
@NSS_STATUS_NOTFOUND = global i32 0
@NSS_STATUS_SUCCESS = global i64 0
define i32 @_nss_exfiles_getgrnam_r(i8* %0, %struct.group* %1, i8* %2, i64 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca %struct.group*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store %struct.group* %1, %struct.group** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32* %4, i32** %10
%13 = load i32, i32* @NSS_STATUS_NOTFOUND
store i32 %13, i32* %11
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %12
%16 = load i64, i64* @NSS_STATUS_SUCCESS
%17 = call i64 (...) @_nss_exfiles_setgrent()
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %5
br label %20
20: ; preds = %47, %19
%21 = load i64, i64* @NSS_STATUS_SUCCESS
%22 = load %struct.group*, %struct.group** %7
%23 = load i8*, i8** %8
%24 = load i64, i64* %9
%25 = load i32*, i32** %10
%26 = call i64 @_nss_exfiles_getgrent_r(%struct.group* %22, i8* %23, i64 %24, i32* %25)
%27 = icmp eq i64 %21, %26
br i1 %27, label %28, label %48
28: ; preds = %20
%29 = load %struct.group*, %struct.group** %7
%30 = getelementptr inbounds %struct.group, %struct.group* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = load i32, i32* %12
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %28
br label %48
36: ; preds = %28
%37 = load i8*, i8** %6
%38 = load %struct.group*, %struct.group** %7
%39 = getelementptr inbounds %struct.group, %struct.group* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = load i32, i32* %12
%42 = call i64 @strncmp(i8* %37, i8* %40, i32 %41)
%43 = icmp eq i64 0, %42
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = load i64, i64* @NSS_STATUS_SUCCESS
%46 = trunc i64 %45 to i32
store i32 %46, i32* %11
br label %48
47: ; preds = %36
br label %20
48: ; preds = %44, %35, %20
br label %49
49: ; preds = %48, %5
%50 = call i32 (...) @_nss_exfiles_endgrent()
%51 = load i32, i32* %11
ret i32 %51
}

LLVM IR (-O2):
%struct.group = type { i8* }
@NSS_STATUS_NOTFOUND = global i32 0
@NSS_STATUS_SUCCESS = global i64 0
define i32 @_nss_exfiles_getgrnam_r(i8* %0, %struct.group* %1, i8* %2, i64 %3, i32* %4) {
%6 = load i32, i32* @NSS_STATUS_NOTFOUND
%7 = tail call i32 @strlen(i8* %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 %28
11: ; preds = %5
%12 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 0
br label %13
13: ; preds = %11, %21
%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 %28
17: ; preds = %13
%18 = load i8*, i8** %12
%19 = tail call i32 @strlen(i8* %18)
%20 = icmp eq i32 %19, %7
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i8*, i8** %12
%23 = tail call i64 @strncmp(i8* %0, i8* %22, i32 %7)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %13
25: ; preds = %21
%26 = load i64, i64* @NSS_STATUS_SUCCESS
%27 = trunc i64 %26 to i32
br label %28
28: ; preds = %13, %17, %25, %5
%29 = phi i32 [ %27, %25 ], [ %6, %5 ], [ %6, %17 ], [ %6, %13 ]
%30 = tail call i32 (...) @_nss_exfiles_endgrent()
ret i32 %29
}