#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 */
scalar_t__ *__alloca(int);
int __getgroups(int, scalar_t__ *);
int __group_member(gid_t gid) {
  int n, size;
  gid_t *groups;
  size = 16;
  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)
movl   $0x10,-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     1133 <__group_member+0x13>
jmp    1181 <__group_member+0x61>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    11bc <__group_member+0x9c>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x10(%rbp),%rax
jne    11b7 <__group_member+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11c3 <__group_member+0xa3>
jmp    1181 <__group_member+0x61>
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    $0x10,%ebx
nopl   (%rax)
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     1130 <__group_member+0x10>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %eax,%eax
jle    1179 <__group_member+0x59>
lea    -0x1(%rax),%rcx
cmp    %r14,-0x8(%r15,%rax,8)
mov    %rcx,%rax
jne    1160 <__group_member+0x40>
mov    $0x1,%eax
jmp    117b <__group_member+0x5b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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