#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;
scalar_t__ getgrouplist(char const *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        int *);
int setgroups(int, int /*<<< orphan*/ *);
int initgroups(const char *user, gid_t gid) {
  gid_t groups[NGROUPS_MAX];
  int count;
  if (getgrouplist(user, gid, groups, &count) < 0)
    return -1;
  return setgroups(count, groups);
}


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
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    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x2c(%rbp),%rcx
call   1040 <getgrouplist@plt>
cmp    $0x0,%rax
jge    1189 <initgroups+0x69>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    119f <initgroups+0x7f>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%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
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0xc(%rbp),%rcx
mov    %rbx,%rdx
call   1040 <getgrouplist@plt>
test   %rax,%rax
js     1162 <initgroups+0x42>
mov    -0xc(%rbp),%edi
mov    %rbx,%rsi
call   1030 <setgroups@plt>
jmp    1167 <initgroups+0x47>
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 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i32, i64 %11
store i64 %11, i64* %7
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i64 @getgrouplist(i8* %14, i32 %15, i32* %13, i32* %8)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %9
br label %22
19: ; preds = %2
%20 = load i32, i32* %8
%21 = call i32 @setgroups(i32 %20, i32* %13)
store i32 %21, i32* %3
store i32 1, i32* %9
br label %22
22: ; preds = %19, %18
%23 = load i8*, i8** %6
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
define i32 @initgroups(i8* %0, i32 %1) {
%3 = alloca i32
%4 = load i32, i32* @NGROUPS_MAX
%5 = zext i32 %4 to i64
%6 = alloca i32, i64 %5
%7 = bitcast i32* %3 to i8*
%8 = call i64 @getgrouplist(i8* %0, i32 %1, i32* %6, i32* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %3
%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
}