#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 /*<<< orphan*/ _id_error(char *, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int getgroups(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
gid_t *_id_getgroups(int *n) {
  gid_t *groups;
  if ((*n = getgroups(0, NULL)) < 0) {
    _id_error("getgroups", 1);
    return NULL;
  }
  if (*n == 0)
    groups = NULL;
  else if ((groups = malloc(sizeof(*groups) * (*n))) == NULL) {
    _id_error("malloc", 1);
    return NULL;
  }
  if ((*n = getgroups(*n, groups)) < 0) {
    free(groups);
    _id_error("getgroups", 1);
    return NULL;
  }
  return groups;
}


x86 assembly (clang, -O0):
<_id_getgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <getgroups@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1184 <_id_getgroups+0x44>
lea    0xe93(%rip),%rdi
mov    $0x1,%esi
call   1040 <_id_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    122e <_id_getgroups+0xee>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    119e <_id_getgroups+0x5e>
movq   $0x0,-0x18(%rbp)
jmp    11e1 <_id_getgroups+0xa1>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11dc <_id_getgroups+0x9c>
lea    0xe45(%rip),%rdi
mov    $0x1,%esi
call   1040 <_id_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    122e <_id_getgroups+0xee>
jmp    11e1 <_id_getgroups+0xa1>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1050 <getgroups@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1226 <_id_getgroups+0xe6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xdf1(%rip),%rdi
mov    $0x1,%esi
call   1040 <_id_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    122e <_id_getgroups+0xee>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_id_getgroups>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %edi,%edi
xor    %esi,%esi
call   1050 <getgroups@plt>
mov    %eax,(%r15)
lea    0xea2(%rip),%r14
test   %eax,%eax
js     119f <_id_getgroups+0x5f>
mov    %eax,%ebx
je     1183 <_id_getgroups+0x43>
lea    0x0(,%rbx,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1186 <_id_getgroups+0x46>
lea    0xe89(%rip),%r14
jmp    119f <_id_getgroups+0x5f>
xor    %r12d,%r12d
mov    %ebx,%edi
mov    %r12,%rsi
call   1050 <getgroups@plt>
mov    %eax,(%r15)
test   %eax,%eax
jns    11af <_id_getgroups+0x6f>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <_id_error@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"getgroups\00"
@.str.1 = [7 x i8] c"malloc\00"
define i32* @_id_getgroups(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
%5 = call i32 @getgroups(i32 0, i32* null)
%6 = load i32*, i32** %3
store i32 %5, i32* %6
%7 = icmp slt i32 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @_id_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
store i32* null, i32** %2
br label %39
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32* null, i32** %4
br label %26
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i32* @malloc(i32 %20)
store i32* %21, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @_id_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32* null, i32** %2
br label %39
25: ; preds = %15
br label %26
26: ; preds = %25, %14
%27 = load i32*, i32** %3
%28 = load i32, i32* %27
%29 = load i32*, i32** %4
%30 = call i32 @getgroups(i32 %28, i32* %29)
%31 = load i32*, i32** %3
store i32 %30, i32* %31
%32 = icmp slt i32 %30, 0
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32*, i32** %4
%35 = call i32 @free(i32* %34)
%36 = call i32 @_id_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1)
store i32* null, i32** %2
br label %39
37: ; preds = %26
%38 = load i32*, i32** %4
store i32* %38, i32** %2
br label %39
39: ; preds = %37, %33, %23, %8
%40 = load i32*, i32** %2
ret i32* %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"getgroups\00"
@.str.1 = [7 x i8] c"malloc\00"
define i32* @_id_getgroups(i32* nocapture %0) {
%2 = tail call i32 @getgroups(i32 0, i32* null)
store i32 %2, i32* %0
%3 = icmp slt i32 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = icmp eq i32 %2, 0
br i1 %5, label %10, label %6
6: ; preds = %4
%7 = shl i32 %2, 2
%8 = tail call i32* @malloc(i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %4, %6
%11 = phi i32* [ %8, %6 ], [ null, %4 ]
%12 = tail call i32 @getgroups(i32 %2, i32* %11)
store i32 %12, i32* %0
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = tail call i32 @free(i32* %11)
br label %16
16: ; preds = %6, %1, %14
%17 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %14 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %6 ]
%18 = tail call i32 @_id_error(i8* %17, i32 1)
br label %19
19: ; preds = %16, %10
%20 = phi i32* [ %11, %10 ], [ null, %16 ]
ret i32* %20
}