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

/* Variables and functions */
int EINTR;
int getgrgid_r(int /*<<< orphan*/, struct group *, char *, size_t,
               struct group **);
int _getgrgid_r(gid_t gid, struct group *grp, char *buf, size_t bufsiz,
                struct group **result) {
  int rc;
  while (1) {
    rc = getgrgid_r(gid, grp, buf, bufsiz, result);
    if (rc == EINTR)
      continue;
    if (rc != 0)
      *result = NULL;
    break;
  }
  return rc;
}


x86 assembly (clang, -O0):
<_getgrgid_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <getgrgid_r@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%eax
jne    115d <_getgrgid_r+0x4d>
jmp    112b <_getgrgid_r+0x1b>
cmpl   $0x0,-0x2c(%rbp)
je     1172 <_getgrgid_r+0x62>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    1177 <_getgrgid_r+0x67>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getgrgid_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,%rbx
mov    %edi,%ebp
mov    0x2eb0(%rip),%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <getgrgid_r@plt>
cmp    0x0(%r13),%eax
je     1130 <_getgrgid_r+0x20>
test   %eax,%eax
je     1154 <_getgrgid_r+0x44>
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 @_getgrgid_r(i32 %0, %struct.group* %1, i8* %2, i64 %3, %struct.group** %4) {
%6 = alloca i32
%7 = alloca %struct.group*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.group**
%11 = alloca i32
store i32 %0, i32* %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 i32, i32* %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 @getgrgid_r(i32 %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 @_getgrgid_r(i32 %0, %struct.group* %1, i8* %2, i64 %3, %struct.group** %4) {
br label %6
6: ; preds = %6, %5
%7 = tail call i32 @getgrgid_r(i32 %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
}