#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 gid_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int getgroups(int, int *);
int handle_gez(int);
int /*<<< orphan*/ printf(char *, ...);
int getgroups_test(int ngroups, gid_t *grouplist) {
  int ret, save_errno;
  int passed;
  int i;
  printf("getgroups(): ngroups=%d, grouplist=0x%p\n", ngroups, grouplist);
  fflush(NULL);
  passed = handle_gez(ret = getgroups(ngroups, grouplist));
  save_errno = errno;
  switch (passed) {
  case -1:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case 0:
    if (ngroups != 0) {
      for (i = 0; i < ret; i++) {
        printf("\t\t\tgrouplist[%i] = %u\n", i, grouplist[i]);
        fflush(NULL);
      }
    }
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<getgroups_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xea3(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <getgroups@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1060 <handle_gez@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xfffffffe,%eax
je     127a <getgroups_test+0x13a>
jmp    11aa <getgroups_test+0x6a>
mov    -0x24(%rbp),%eax
sub    $0xffffffff,%eax
je     11cb <getgroups_test+0x8b>
jmp    11bb <getgroups_test+0x7b>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     11f8 <getgroups_test+0xb8>
jmp    1299 <getgroups_test+0x159>
mov    -0x14(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    12b3 <getgroups_test+0x173>
cmpl   $0x0,-0x4(%rbp)
je     124d <getgroups_test+0x10d>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1248 <getgroups_test+0x108>
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1209 <getgroups_test+0xc9>
jmp    124d <getgroups_test+0x10d>
mov    -0x14(%rbp),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    12b3 <getgroups_test+0x173>
mov    -0x14(%rbp),%esi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    12b3 <getgroups_test+0x173>
mov    -0x1c(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d23(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getgroups_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe99(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <getgroups@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1070 <handle_gez@plt>
mov    0x2e4b(%rip),%r15
mov    (%r15),%r13d
cmp    $0xfffffffe,%eax
je     1235 <getgroups_test+0xe5>
test   %eax,%eax
je     11d0 <getgroups_test+0x80>
cmp    $0xffffffff,%eax
jne    1241 <getgroups_test+0xf1>
lea    0xe74(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
jmp    1251 <getgroups_test+0x101>
test   %ebp,%ebp
je     120f <getgroups_test+0xbf>
test   %r14d,%r14d
jle    120f <getgroups_test+0xbf>
mov    %r14d,%r12d
lea    0xe52(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%rbp,4),%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11f0 <getgroups_test+0xa0>
lea    0xe13(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dad(%rip),%r15
jmp    1251 <getgroups_test+0x101>
lea    0xe10(%rip),%rdi
mov    %r14d,%esi
jmp    124a <getgroups_test+0xfa>
lea    0xe39(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %r13d,(%r15)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"getgroups(): ngroups=%d, grouplist=0x%p\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [23 x i8] c"\09\09\09grouplist[%i] = %u\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @getgroups_test(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%9 = load i32, i32* %3
%10 = load i32*, i32** %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %9, i32* %10)
%12 = call i32 @fflush(i32* null)
%13 = load i32, i32* %3
%14 = load i32*, i32** %4
%15 = call i32 @getgroups(i32 %13, i32* %14)
store i32 %15, i32* %5
%16 = call i32 @handle_gez(i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* @errno
store i32 %17, i32* %6
%18 = load i32, i32* %7
switch i32 %18, label %54 [
i32 -1, label %19
i32 0, label %24
i32 -2, label %50
]
19: ; preds = %2
%20 = load i32, i32* %5
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @fflush(i32* null)
br label %58
24: ; preds = %2
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %45
27: ; preds = %24
store i32 0, i32* %8
br label %28
28: ; preds = %41, %27
%29 = load i32, i32* %8
%30 = load i32, i32* %5
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %28
%33 = load i32, i32* %8
%34 = load i32*, i32** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %38)
%40 = call i32 @fflush(i32* null)
br label %41
41: ; preds = %32
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %28
44: ; preds = %28
br label %45
45: ; preds = %44, %24
%46 = load i32, i32* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @fflush(i32* null)
br label %58
50: ; preds = %2
%51 = load i32, i32* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = call i32 @fflush(i32* null)
br label %58
54: ; preds = %2
%55 = load i32, i32* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%57 = call i32 @fflush(i32* null)
br label %58
58: ; preds = %54, %50, %45, %19
%59 = load i32, i32* %6
store i32 %59, i32* @errno
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
@.str = [41 x i8] c"getgroups(): ngroups=%d, grouplist=0x%p\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [23 x i8] c"\09\09\09grouplist[%i] = %u\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str.6 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @getgroups_test(i32 %0, i32* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %0, i32* %1)
%4 = tail call i32 @fflush(i32* null)
%5 = tail call i32 @getgroups(i32 %0, i32* %1)
%6 = tail call i32 @handle_gez(i32 %5)
%7 = load i32, i32* @errno
switch i32 %6, label %31 [
i32 -1, label %8
i32 0, label %11
i32 -2, label %29
]
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %33
11: ; preds = %2
%12 = icmp ne i32 %0, 0
%13 = icmp sgt i32 %5, 0
%14 = and i1 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = zext i32 %5 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %24, %17 ]
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = load i32, i32* %19
%21 = trunc i64 %18 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %20)
%23 = tail call i32 @fflush(i32* null)
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %16
br i1 %25, label %26, label %17
26: ; preds = %17, %11
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %33
29: ; preds = %2
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %5)
br label %33
31: ; preds = %2
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %6)
br label %33
33: ; preds = %31, %29, %26, %8
%34 = tail call i32 @fflush(i32* null)
store i32 %7, i32* @errno
ret i32 %5
}