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

/* Variables and functions */
int /*<<< orphan*/ endgrent();
struct group *getgrent();
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
gid_t piphoned_userinfo_get_gid(const char *groupname) {
  struct group *p_group = NULL;
  gid_t gid = -1;
  while ((p_group = getgrent())) {
    if (strcmp(p_group->gr_name, groupname) == 0) {
      gid = p_group->gr_gid;
      break;
    }
  }
  endgrent();
  return gid;
}


x86 assembly (clang, -O0):
<piphoned_userinfo_get_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getgrent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118d <piphoned_userinfo_get_gid+0x5d>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1188 <piphoned_userinfo_get_gid+0x58>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    118d <piphoned_userinfo_get_gid+0x5d>
jmp    114b <piphoned_userinfo_get_gid+0x1b>
mov    $0x0,%al
call   1030 <endgrent@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piphoned_userinfo_get_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getgrent@plt>
test   %rax,%rax
je     1163 <piphoned_userinfo_get_gid+0x33>
mov    %rax,%rbx
mov    0x4(%rax),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1140 <piphoned_userinfo_get_gid+0x10>
mov    (%rbx),%ebx
jmp    1168 <piphoned_userinfo_get_gid+0x38>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   1030 <endgrent@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.group = type { i32, i32 }
define i32 @piphoned_userinfo_get_gid(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.group*
%4 = alloca i32
store i8* %0, i8** %2
store %struct.group* null, %struct.group** %3
store i32 -1, i32* %4
br label %5
5: ; preds = %19, %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 %20
8: ; preds = %5
%9 = load %struct.group*, %struct.group** %3
%10 = getelementptr inbounds %struct.group, %struct.group* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load i8*, i8** %2
%13 = call i64 @strcmp(i32 %11, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load %struct.group*, %struct.group** %3
%17 = getelementptr inbounds %struct.group, %struct.group* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %4
br label %20
19: ; preds = %8
br label %5
20: ; preds = %15, %5
%21 = call i32 (...) @endgrent()
%22 = load i32, i32* %4
ret i32 %22
}

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