#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 stat {
  scalar_t__ st_gid;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ getegid();
int getgroups(int, scalar_t__ *);
scalar_t__ malloc(int);
int Sfile_being_group_member(struct stat *stbuf, int flag) {
  int i, suppl_groups;
  gid_t *suppl_glist;
  if (getegid() == stbuf->st_gid)
    return (1);
  suppl_groups = getgroups(0, NULL);
  suppl_glist = (gid_t *)malloc((suppl_groups + 1) * sizeof(gid_t));
  if (suppl_glist == NULL)
    return (-1);
  suppl_groups = getgroups(suppl_groups + 1, suppl_glist);
  for (i = 0; i < suppl_groups; i++) {
    if (suppl_glist[i] == stbuf->st_gid) {
      free((char *)suppl_glist);
      return (1);
    }
  }
  free((char *)suppl_glist);
  return (0);
}


x86 assembly (clang, -O0):
<Sfile_being_group_member>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getegid@plt>
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    116f <Sfile_being_group_member+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1221 <Sfile_being_group_member+0xe1>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <getgroups@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ab <Sfile_being_group_member+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <Sfile_being_group_member+0xe1>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    -0x28(%rbp),%rsi
call   1040 <getgroups@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1211 <Sfile_being_group_member+0xd1>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    11fe <Sfile_being_group_member+0xbe>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <Sfile_being_group_member+0xe1>
jmp    1203 <Sfile_being_group_member+0xc3>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c4 <Sfile_being_group_member+0x84>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sfile_being_group_member>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <getegid@plt>
mov    $0x1,%r15d
cmp    (%r14),%rax
je     11ca <Sfile_being_group_member+0x8a>
xor    %r15d,%r15d
xor    %edi,%edi
xor    %esi,%esi
call   1040 <getgroups@plt>
mov    %eax,%r12d
lea    0x8(,%r12,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b4 <Sfile_being_group_member+0x74>
mov    %rax,%rbx
add    $0x1,%r12d
mov    %r12d,%edi
mov    %rax,%rsi
call   1040 <getgroups@plt>
test   %eax,%eax
jle    11c2 <Sfile_being_group_member+0x82>
mov    (%r14),%rcx
mov    %eax,%eax
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
cmp    %rcx,(%rbx,%rdx,8)
je     11bc <Sfile_being_group_member+0x7c>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11a0 <Sfile_being_group_member+0x60>
xor    %r15d,%r15d
jmp    11c2 <Sfile_being_group_member+0x82>
mov    $0xffffffff,%r15d
jmp    11ca <Sfile_being_group_member+0x8a>
mov    $0x1,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i32 @Sfile_being_group_member(%struct.stat* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.stat*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64*
store %struct.stat* %0, %struct.stat** %4
store i32 %1, i32* %5
%9 = call i64 (...) @getegid()
%10 = load %struct.stat*, %struct.stat** %4
%11 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %9, %12
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %58
15: ; preds = %2
%16 = call i32 @getgroups(i32 0, i64* null)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i64*
store i64* %23, i64** %8
%24 = load i64*, i64** %8
%25 = icmp eq i64* %24, null
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 -1, i32* %3
br label %58
27: ; preds = %15
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = load i64*, i64** %8
%31 = call i32 @getgroups(i32 %29, i64* %30)
store i32 %31, i32* %7
store i32 0, i32* %6
br label %32
32: ; preds = %51, %27
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %32
%37 = load i64*, i64** %8
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i64, i64* %37, i64 %39
%41 = load i64, i64* %40
%42 = load %struct.stat*, %struct.stat** %4
%43 = getelementptr inbounds %struct.stat, %struct.stat* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = icmp eq i64 %41, %44
br i1 %45, label %46, label %50
46: ; preds = %36
%47 = load i64*, i64** %8
%48 = bitcast i64* %47 to i8*
%49 = call i32 @free(i8* %48)
store i32 1, i32* %3
br label %58
50: ; preds = %36
br label %51
51: ; preds = %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %32
54: ; preds = %32
%55 = load i64*, i64** %8
%56 = bitcast i64* %55 to i8*
%57 = call i32 @free(i8* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %54, %46, %26, %14
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i32 @Sfile_being_group_member(%struct.stat* nocapture %0, i32 %1) {
%3 = tail call i64 (...) @getegid()
%4 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = icmp eq i64 %3, %5
br i1 %6, label %32, label %7
7: ; preds = %2
%8 = tail call i32 @getgroups(i32 0, i64* null)
%9 = add nsw i32 %8, 1
%10 = shl i32 %9, 3
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i64*
%13 = icmp eq i64 %11, 0
br i1 %13, label %32, label %14
14: ; preds = %7
%15 = tail call i32 @getgroups(i32 %9, i64* %12)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i64, i64* %4
%19 = zext i32 %15 to i64
br label %22
20: ; preds = %22
%21 = icmp eq i64 %27, %19
br i1 %21, label %28, label %22
22: ; preds = %17, %20
%23 = phi i64 [ 0, %17 ], [ %27, %20 ]
%24 = getelementptr inbounds i64, i64* %12, i64 %23
%25 = load i64, i64* %24
%26 = icmp eq i64 %25, %18
%27 = add nuw nsw i64 %23, 1
br i1 %26, label %28, label %20
28: ; preds = %20, %22, %14
%29 = phi i32 [ 0, %14 ], [ 1, %22 ], [ 0, %20 ]
%30 = inttoptr i64 %11 to i8*
%31 = tail call i32 @free(i8* %30)
br label %32
32: ; preds = %28, %7, %2
%33 = phi i32 [ 1, %2 ], [ -1, %7 ], [ %29, %28 ]
ret i32 %33
}