#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 {
  int /*<<< orphan*/ gr_name;
};

/* Variables and functions */
int /*<<< orphan*/ endgrent();
struct group *getgrent();
int /*<<< orphan*/ setgrent();
scalar_t__ strcmp(char const *, int /*<<< orphan*/);
struct group *my_getgrnam(char const *name) {
  struct group *ptr = 0;
  setgrent();
  while ((ptr = getgrent()) != NULL) {
    if (strcmp(name, ptr->gr_name) == 0)
      break;
  }
  endgrent();
  return (ptr);
}


x86 assembly (clang, -O0):
<my_getgrnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <setgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1193 <my_getgrnam+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    118e <my_getgrnam+0x4e>
jmp    1193 <my_getgrnam+0x53>
jmp    115b <my_getgrnam+0x1b>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getgrnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <setgrent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getgrent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116e <my_getgrnam+0x2e>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1150 <my_getgrnam+0x10>
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.group = type { i32 }
define %struct.group* @my_getgrnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.group*
store i8* %0, i8** %2
store %struct.group* null, %struct.group** %3
%4 = call i32 (...) @setgrent()
br label %5
5: ; preds = %16, %1
%6 = call %struct.group* (...) @getgrent()
store %struct.group* %6, %struct.group** %3
%7 = icmp ne %struct.group* %6, null
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load %struct.group*, %struct.group** %3
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @strcmp(i8* %9, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %17
16: ; preds = %8
br label %5
17: ; preds = %15, %5
%18 = call i32 (...) @endgrent()
%19 = load %struct.group*, %struct.group** %3
ret %struct.group* %19
}

LLVM IR (-O2):
%struct.group = type { i32 }
define %struct.group* @my_getgrnam(i8* %0) {
%2 = tail call i32 (...) @setgrent()
br label %3
3: ; preds = %6, %1
%4 = tail call %struct.group* (...) @getgrent()
%5 = icmp eq %struct.group* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.group, %struct.group* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @strcmp(i8* %0, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %6, %3
%12 = tail call i32 (...) @endgrent()
ret %struct.group* %4
}