#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 dummy;
};

/* Variables and functions */
int EINTR;
int getgrnam_r(char const *, struct group *, char *, size_t, struct group **);
int _getgrnam_r(const char *name, struct group *grp, char *buf, size_t bufsiz,
                struct group **result) {
  int rc;
  while (1) {
    rc = getgrnam_r(name, grp, buf, bufsiz, result);
    if (rc == EINTR)
      continue;
    if (rc != 0)
      *result = NULL;
    break;
  }
  return (rc);
}


x86 assembly (clang, -O0):
<_getgrnam_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <getgrnam_r@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jne    115f <_getgrnam_r+0x4f>
jmp    112c <_getgrnam_r+0x1c>
cmpl   $0x0,-0x2c(%rbp)
je     1174 <_getgrnam_r+0x64>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    1179 <_getgrnam_r+0x69>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getgrnam_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    0x2eaf(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <getgrnam_r@plt>
cmp    0x0(%rbp),%eax
je     1140 <_getgrnam_r+0x30>
test   %eax,%eax
je     1164 <_getgrnam_r+0x54>
movq   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@EINTR = global i32 0
define i32 @_getgrnam_r(i8* %0, %struct.group* %1, i8* %2, i64 %3, %struct.group** %4) {
%6 = alloca i8*
%7 = alloca %struct.group*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.group**
%11 = 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 %struct.group** %4, %struct.group*** %10
br label %12
12: ; preds = %5, %22
%13 = load i8*, i8** %6
%14 = load %struct.group*, %struct.group** %7
%15 = load i8*, i8** %8
%16 = load i64, i64* %9
%17 = load %struct.group**, %struct.group*** %10
%18 = call i32 @getgrnam_r(i8* %13, %struct.group* %14, i8* %15, i64 %16, %struct.group** %17)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = load i32, i32* @EINTR
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %12
br label %12
23: ; preds = %12
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load %struct.group**, %struct.group*** %10
store %struct.group* null, %struct.group** %27
br label %28
28: ; preds = %26, %23
br label %29
29: ; preds = %28
%30 = load i32, i32* %11
ret i32 %30
}

LLVM IR (-O2):
%struct.group = type { i32 }
@EINTR = global i32 0
define i32 @_getgrnam_r(i8* %0, %struct.group* %1, i8* %2, i64 %3, %struct.group** %4) {
br label %6
6: ; preds = %6, %5
%7 = tail call i32 @getgrnam_r(i8* %0, %struct.group* %1, i8* %2, i64 %3, %struct.group** %4)
%8 = load i32, i32* @EINTR
%9 = icmp eq i32 %7, %8
br i1 %9, label %6, label %10
10: ; preds = %6
%11 = icmp eq i32 %7, 0
br i1 %11, label %13, label %12
12: ; preds = %10
store %struct.group* null, %struct.group** %4
br label %13
13: ; preds = %10, %12
ret i32 %7
}