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

/* Variables and functions */
int NGROUPS_MAX;
int getGroups(char const *, int, int /*<<< orphan*/ *);
int setgroups(int, int /*<<< orphan*/ *);
int _initgroups(const char *user, gid_t group) {
  gid_t suppGroups[(NGROUPS_MAX + 1)];
  int nGroups;
  suppGroups[0] = group;
  if ((nGroups = getGroups(user, (NGROUPS_MAX + 1) - 1, &suppGroups[1])) ==
      -1) {
    return -1;
  }
  return setgroups(nGroups + 1, suppGroups);
}


x86 assembly (clang, -O0):
<_initgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,(%rdx)
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
sub    $0x1,%esi
add    $0x4,%rdx
call   1040 <getGroups@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    119f <_initgroups+0x7f>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11b8 <_initgroups+0x98>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1030 <setgroups@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_initgroups>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
lea    0x1(%rax),%ecx
mov    %rsp,%rdx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rdx,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
neg    %rcx
mov    %esi,(%rdx,%rcx,1)
lea    0x4(%rbx),%rdx
mov    %eax,%esi
call   1040 <getGroups@plt>
cmp    $0xffffffff,%eax
je     116f <_initgroups+0x4f>
add    $0x1,%eax
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <setgroups@plt>
jmp    1174 <_initgroups+0x54>
mov    $0xffffffff,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@NGROUPS_MAX = global i32 0
define i32 @_initgroups(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* @NGROUPS_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i32, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %5
%16 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %15, i32* %16
%17 = load i8*, i8** %4
%18 = load i32, i32* @NGROUPS_MAX
%19 = add nsw i32 %18, 1
%20 = sub nsw i32 %19, 1
%21 = getelementptr inbounds i32, i32* %14, i64 1
%22 = call i32 @getGroups(i8* %17, i32 %20, i32* %21)
store i32 %22, i32* %8
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %9
br label %29
25: ; preds = %2
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
%28 = call i32 @setgroups(i32 %27, i32* %14)
store i32 %28, i32* %3
store i32 1, i32* %9
br label %29
29: ; preds = %25, %24
%30 = load i8*, i8** %6
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
define i32 @_initgroups(i8* %0, i32 %1) {
%3 = load i32, i32* @NGROUPS_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i32, i64 %5
store i32 %1, i32* %6
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = call i32 @getGroups(i8* %0, i32 %3, i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = add nuw nsw i32 %8, 1
%12 = call i32 @setgroups(i32 %11, i32* %6)
br label %13
13: ; preds = %2, %10
%14 = phi i32 [ %12, %10 ], [ -1, %2 ]
ret i32 %14
}