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

/* Variables and functions */
int expect_gez(int /*<<< orphan*/, int);
int expect_gid(int /*<<< orphan*/, scalar_t__);
int expect_val(scalar_t__, scalar_t__);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(scalar_t__ *);
scalar_t__ getgid_test();
int getgroups_test(int, scalar_t__ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ testbreak();
scalar_t__ xmalloc(int);
int BasicGroups(void) {
  int size;
  gid_t *groups = NULL;
  gid_t gid;
  int i;
  gid_t found = 0;
  int block = 0;
  int passed;
  testbreak();
  passed = expect_gid(0, gid = getgid_test());
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  };
  passed = expect_gez(0, size = getgroups_test(0, groups));
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  };
  if (size != 0) {
    groups = (gid_t *)xmalloc(sizeof(gid_t) * size);
    passed = expect_gez(0, getgroups_test(size, groups));
    if (passed != 0) {
      printf("\tFailed Phase 2: This call did something unexpected.\n");
      fflush(NULL);
      block = -1;
    };
    for (i = 0; i < size; i++) {
      if (gid == groups[i]) {
        found = gid;
        break;
      }
    }
    free(groups);
    passed = expect_val(gid, found);
    if (passed != 0) {
      printf("\tFailed Phase 2: This call did something unexpected.\n");
      fflush(NULL);
      block = -1;
    };
  }
  testbreak();
  return block;
}


x86 assembly (clang, -O0):
<BasicGroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1090 <testbreak@plt>
mov    $0x0,%al
call   1060 <getgid_test@plt>
mov    %rax,%rsi
mov    %rsi,-0x18(%rbp)
xor    %edi,%edi
call   10b0 <expect_gid@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1204 <BasicGroups+0x64>
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1070 <getgroups_test@plt>
mov    %eax,%esi
mov    %esi,-0x4(%rbp)
xor    %edi,%edi
call   10c0 <expect_gez@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1244 <BasicGroups+0xa4>
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movl   $0xffffffff,-0x2c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     132c <BasicGroups+0x18c>
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <getgroups_test@plt>
mov    %eax,%esi
xor    %edi,%edi
call   10c0 <expect_gez@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     129f <BasicGroups+0xff>
lea    0xd76(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movl   $0xffffffff,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12e8 <BasicGroups+0x148>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    12d5 <BasicGroups+0x135>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12e8 <BasicGroups+0x148>
jmp    12da <BasicGroups+0x13a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a6 <BasicGroups+0x106>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <expect_val@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1327 <BasicGroups+0x187>
lea    0xcee(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    132c <BasicGroups+0x18c>
mov    $0x0,%al
call   1090 <testbreak@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasicGroups>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <testbreak@plt>
xor    %eax,%eax
call   1060 <getgid_test@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %rax,%rsi
call   10b0 <expect_gid@plt>
test   %eax,%eax
je     11e2 <BasicGroups+0x42>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%r14d
xor    %edi,%edi
xor    %esi,%esi
call   1070 <getgroups_test@plt>
mov    %eax,%r15d
xor    %edi,%edi
mov    %eax,%esi
call   10c0 <expect_gez@plt>
test   %eax,%eax
je     1214 <BasicGroups+0x74>
lea    0xdfe(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%r14d
test   %r15d,%r15d
je     12ba <BasicGroups+0x11a>
lea    0x0(,%r15,8),%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %rax,%rsi
call   1070 <getgroups_test@plt>
xor    %edi,%edi
mov    %eax,%esi
call   10c0 <expect_gez@plt>
test   %eax,%eax
je     125e <BasicGroups+0xbe>
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%r14d
test   %r15d,%r15d
jle    1282 <BasicGroups+0xe2>
mov    %r15d,%eax
xor    %r15d,%r15d
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
cmp    0x0(%rbp,%rcx,8),%rbx
je     1287 <BasicGroups+0xe7>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1270 <BasicGroups+0xd0>
jmp    128a <BasicGroups+0xea>
xor    %r15d,%r15d
jmp    128a <BasicGroups+0xea>
mov    %rbx,%r15
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <expect_val@plt>
test   %eax,%eax
je     12ba <BasicGroups+0x11a>
lea    0xd58(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    $0xffffffff,%r14d
xor    %eax,%eax
call   1090 <testbreak@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"\09Failed Phase 2: This call did something unexpected.\0A\00"
define i32 @BasicGroups() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i64* null, i64** %2
store i64 0, i64* %5
store i32 0, i32* %6
%8 = call i32 (...) @testbreak()
%9 = call i64 (...) @getgid_test()
store i64 %9, i64* %3
%10 = call i32 @expect_gid(i32 0, i64 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @fflush(i32* null)
store i32 -1, i32* %6
br label %16
16: ; preds = %13, %0
%17 = load i64*, i64** %2
%18 = call i32 @getgroups_test(i32 0, i64* %17)
store i32 %18, i32* %1
%19 = call i32 @expect_gez(i32 0, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @fflush(i32* null)
store i32 -1, i32* %6
br label %25
25: ; preds = %22, %16
%26 = load i32, i32* %1
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %75
28: ; preds = %25
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = mul i64 8, %30
%32 = trunc i64 %31 to i32
%33 = call i64 @xmalloc(i32 %32)
%34 = inttoptr i64 %33 to i64*
store i64* %34, i64** %2
%35 = load i32, i32* %1
%36 = load i64*, i64** %2
%37 = call i32 @getgroups_test(i32 %35, i64* %36)
%38 = call i32 @expect_gez(i32 0, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %28
%42 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @fflush(i32* null)
store i32 -1, i32* %6
br label %44
44: ; preds = %41, %28
store i32 0, i32* %4
br label %45
45: ; preds = %60, %44
%46 = load i32, i32* %4
%47 = load i32, i32* %1
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %63
49: ; preds = %45
%50 = load i64, i64* %3
%51 = load i64*, i64** %2
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i64, i64* %51, i64 %53
%55 = load i64, i64* %54
%56 = icmp eq i64 %50, %55
br i1 %56, label %57, label %59
57: ; preds = %49
%58 = load i64, i64* %3
store i64 %58, i64* %5
br label %63
59: ; preds = %49
br label %60
60: ; preds = %59
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %45
63: ; preds = %57, %45
%64 = load i64*, i64** %2
%65 = call i32 @free(i64* %64)
%66 = load i64, i64* %3
%67 = load i64, i64* %5
%68 = call i32 @expect_val(i64 %66, i64 %67)
store i32 %68, i32* %7
%69 = load i32, i32* %7
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%73 = call i32 @fflush(i32* null)
store i32 -1, i32* %6
br label %74
74: ; preds = %71, %63
br label %75
75: ; preds = %74, %25
%76 = call i32 (...) @testbreak()
%77 = load i32, i32* %6
ret i32 %77
}

LLVM IR (-O2):
@str.3 = [53 x i8] c"\09Failed Phase 2: This call did something unexpected.\00"
define i32 @BasicGroups() {
%1 = tail call i32 (...) @testbreak()
%2 = tail call i64 (...) @getgid_test()
%3 = tail call i32 @expect_gid(i32 0, i64 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @fflush(i32* null)
br label %8
8: ; preds = %5, %0
%9 = phi i32 [ -1, %5 ], [ 0, %0 ]
%10 = tail call i32 @getgroups_test(i32 0, i64* null)
%11 = tail call i32 @expect_gez(i32 0, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.3, i64 0, i64 0))
%15 = tail call i32 @fflush(i32* null)
br label %16
16: ; preds = %13, %8
%17 = phi i32 [ -1, %13 ], [ %9, %8 ]
%18 = icmp eq i32 %10, 0
br i1 %18, label %50, label %19
19: ; preds = %16
%20 = shl i32 %10, 3
%21 = tail call i64 @xmalloc(i32 %20)
%22 = inttoptr i64 %21 to i64*
%23 = tail call i32 @getgroups_test(i32 %10, i64* %22)
%24 = tail call i32 @expect_gez(i32 0, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.3, i64 0, i64 0))
%28 = tail call i32 @fflush(i32* null)
br label %29
29: ; preds = %26, %19
%30 = phi i32 [ -1, %26 ], [ %17, %19 ]
%31 = icmp sgt i32 %10, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = zext i32 %10 to i64
br label %36
34: ; preds = %36
%35 = icmp eq i64 %41, %33
br i1 %35, label %42, label %36
36: ; preds = %32, %34
%37 = phi i64 [ 0, %32 ], [ %41, %34 ]
%38 = getelementptr inbounds i64, i64* %22, i64 %37
%39 = load i64, i64* %38
%40 = icmp eq i64 %2, %39
%41 = add nuw nsw i64 %37, 1
br i1 %40, label %42, label %34
42: ; preds = %34, %36, %29
%43 = phi i64 [ 0, %29 ], [ %2, %36 ], [ 0, %34 ]
%44 = tail call i32 @free(i64* %22)
%45 = tail call i32 @expect_val(i64 %2, i64 %43)
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %42
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.3, i64 0, i64 0))
%49 = tail call i32 @fflush(i32* null)
br label %50
50: ; preds = %42, %47, %16
%51 = phi i32 [ -1, %47 ], [ %30, %42 ], [ %17, %16 ]
%52 = tail call i32 (...) @testbreak()
ret i32 %51
}