#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();
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
struct group *getgrnam(const char *name) {
  struct group *gr;
  endgrent();
  while ((gr = getgrent()) != 0 && strcmp(gr->gr_name, name) != 0) {
  }
  endgrent();
  return gr;
}


x86 assembly (clang, -O0):
<getgrnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1179 <getgrnam+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1189 <getgrnam+0x59>
jmp    118e <getgrnam+0x5e>
jmp    1143 <getgrnam+0x13>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getgrnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <endgrent@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getgrent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115e <getgrnam+0x2e>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1140 <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* @getgrnam(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.group*
store i8* %0, i8** %2
%4 = call i32 (...) @endgrent()
br label %5
5: ; preds = %17, %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 %15
8: ; preds = %5
%9 = load %struct.group*, %struct.group** %3
%10 = getelementptr inbounds %struct.group, %struct.group* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i64 @strcmp(i32 %11, i8* %12)
%14 = icmp ne i64 %13, 0
br label %15
15: ; preds = %8, %5
%16 = phi i1 [ false, %5 ], [ %14, %8 ]
br i1 %16, label %17, label %18
17: ; preds = %15
br label %5
18: ; preds = %15
%19 = call i32 (...) @endgrent()
%20 = load %struct.group*, %struct.group** %3
ret %struct.group* %20
}

LLVM IR (-O2):
%struct.group = type { i32 }
define %struct.group* @getgrnam(i8* %0) {
%2 = tail call i32 (...) @endgrent()
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(i32 %8, i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %3, %6
%12 = tail call i32 (...) @endgrent()
ret %struct.group* %4
}