#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 */
typedef scalar_t__ gid_t;

/* Variables and functions */
int NGROUPS_MAX;
scalar_t__ *__alloca(int);
int __getgroups(int, scalar_t__ *);
int __group_member(gid_t gid) {
  int n, size;
  gid_t *groups;
  size = NGROUPS_MAX;
  do {
    groups = __alloca(size * sizeof *groups);
    n = __getgroups(size, groups);
    size *= 2;
  } while (n == size / 2);
  while (n > 0)
    if (groups[n--] == gid)
      return 1;
  return 0;
}


x86 assembly (clang, -O0):
<__group_member>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <__alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <__getgroups@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     1138 <__group_member+0x18>
jmp    1186 <__group_member+0x66>
cmpl   $0x0,-0x14(%rbp)
jle    11c1 <__group_member+0xa1>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x10(%rbp),%rax
jne    11bc <__group_member+0x9c>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <__group_member+0xa8>
jmp    1186 <__group_member+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__group_member>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2eb9(%rip),%rax
mov    (%rax),%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x0(,%rbx,8),%edi
call   1040 <__alloca@plt>
mov    %rax,%r15
mov    %ebx,%edi
mov    %rax,%rsi
call   1030 <__getgroups@plt>
lea    (%rbx,%rbx,1),%ecx
cmp    %ebx,%eax
mov    %ecx,%ebx
je     1140 <__group_member+0x20>
mov    %eax,%ecx
lea    (%r15,%rcx,8),%rcx
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
jle    118a <__group_member+0x6a>
add    $0xffffffff,%eax
lea    -0x8(%rcx),%rdx
cmp    %r14,(%rcx)
mov    %rdx,%rcx
jne    1170 <__group_member+0x50>
mov    $0x1,%eax
jmp    118c <__group_member+0x6c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@NGROUPS_MAX = global i32 0
define i32 @__group_member(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64*
store i64 %0, i64* %3
%7 = load i32, i32* @NGROUPS_MAX
store i32 %7, i32* %5
br label %8
8: ; preds = %19, %1
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i64* @__alloca(i32 %12)
store i64* %13, i64** %6
%14 = load i32, i32* %5
%15 = load i64*, i64** %6
%16 = call i32 @__getgroups(i32 %14, i64* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 2
store i32 %18, i32* %5
br label %19
19: ; preds = %8
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = sdiv i32 %21, 2
%23 = icmp eq i32 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %19
br label %25
25: ; preds = %38, %24
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load i64*, i64** %6
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i64, i64* %29, i64 %32
%34 = load i64, i64* %33
%35 = load i64, i64* %3
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %28
store i32 1, i32* %2
br label %40
38: ; preds = %28
br label %25
39: ; preds = %25
store i32 0, i32* %2
br label %40
40: ; preds = %39, %37
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
define i32 @__group_member(i64 %0) {
%2 = load i32, i32* @NGROUPS_MAX
br label %3
3: ; preds = %3, %1
%4 = phi i32 [ %2, %1 ], [ %8, %3 ]
%5 = shl i32 %4, 3
%6 = tail call i64* @__alloca(i32 %5)
%7 = tail call i32 @__getgroups(i32 %4, i64* %6)
%8 = shl nsw i32 %4, 1
%9 = icmp eq i32 %7, %4
br i1 %9, label %3, label %10
10: ; preds = %3, %13
%11 = phi i32 [ %14, %13 ], [ %7, %3 ]
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = add nsw i32 %11, -1
%15 = zext i32 %11 to i64
%16 = getelementptr inbounds i64, i64* %6, i64 %15
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, %0
br i1 %18, label %19, label %10
19: ; preds = %10, %13
%20 = phi i32 [ 1, %13 ], [ 0, %10 ]
ret i32 %20
}