#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 /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ NGROUPS_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getgroups(int /*<<< orphan*/, scalar_t__ *);
int my_initgroups(char *, scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  gid_t groupslist[NGROUPS_MAX + 1], group = 2000;
  int i = 0, num_groups = 0;
  int flag = 0;
  printf("Adding a new group id to list of supplemental group ids, output(0 "
         "for success, -1 for error): %d\n",
         my_initgroups("root", group));
  printf("Retrieving the list of supplemental group ids for this process to "
         "check for the new group id\n");
  num_groups = getgroups(NGROUPS_MAX, groupslist);
  for (; i < num_groups; i++) {
    if (group == groupslist[i]) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    printf("SUCCESS: Adding group id %d to supplemental group ids\n", group);
  } else {
    printf("FAILURE: Adding group id %d to supplemental group ids\n", group);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x7d0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xeb4(%rip),%rdi
call   1040 <my_initgroups@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1050 <getgroups@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1227 <main+0xe7>
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    1214 <main+0xd4>
movl   $0x1,-0x34(%rbp)
jmp    1227 <main+0xe7>
jmp    1219 <main+0xd9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e6 <main+0xa6>
cmpl   $0x0,-0x34(%rbp)
je     1248 <main+0x108>
mov    -0x28(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125a <main+0x11a>
mov    -0x28(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2e8a(%rip),%r14
mov    (%r14),%eax
add    $0x1,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xee2(%rip),%rdi
mov    $0x7d0,%esi
call   1050 <my_initgroups@plt>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
call   1060 <getgroups@plt>
lea    0xee6(%rip),%rdi
test   %eax,%eax
jle    11e8 <main+0x98>
mov    %eax,%eax
xor    %ecx,%ecx
lea    0xea0(%rip),%rdx
nopw   0x0(%rax,%rax,1)
cmpq   $0x7d0,(%rbx,%rcx,8)
je     11e5 <main+0x95>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11d0 <main+0x80>
jmp    11e8 <main+0x98>
mov    %rdx,%rdi
mov    $0x7d0,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@NGROUPS_MAX = global i32 0
@.str = [98 x i8] c"Adding a new group id to list of supplemental group ids, output(0 for success, -1 for error): %d\0A\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [94 x i8] c"Retrieving the list of supplemental group ids for this process to check for the new group id\0A\00"
@.str.3 = [55 x i8] c"SUCCESS: Adding group id %d to supplemental group ids\0A\00"
@.str.4 = [55 x i8] c"FAILURE: Adding group id %d to supplemental group ids\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @NGROUPS_MAX
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i64, i64 %14
store i64 %14, i64* %7
store i64 2000, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%17 = load i64, i64* %8
%18 = call i32 @my_initgroups(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @NGROUPS_MAX
%22 = call i32 @getgroups(i32 %21, i64* %16)
store i32 %22, i32* %10
br label %23
23: ; preds = %36, %2
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i64, i64* %8
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %16, i64 %30
%32 = load i64, i64* %31
%33 = icmp eq i64 %28, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 1, i32* %11
br label %39
35: ; preds = %27
br label %36
36: ; preds = %35
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %23
39: ; preds = %34, %23
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i64, i64* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i64 %43)
br label %48
45: ; preds = %39
%46 = load i64, i64* %8
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i64 %46)
br label %48
48: ; preds = %45, %42
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
@.str = [98 x i8] c"Adding a new group id to list of supplemental group ids, output(0 for success, -1 for error): %d\0A\00"
@.str.1 = [5 x i8] c"root\00"
@.str.3 = [55 x i8] c"SUCCESS: Adding group id %d to supplemental group ids\0A\00"
@.str.4 = [55 x i8] c"FAILURE: Adding group id %d to supplemental group ids\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [93 x i8] c"Retrieving the list of supplemental group ids for this process to check for the new group id\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @NGROUPS_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i64, i64 %5
%7 = tail call i32 @my_initgroups(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 2000)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @NGROUPS_MAX
%11 = call i32 @getgroups(i32 %10, i64* %6)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = zext i32 %11 to i64
br label %17
15: ; preds = %17
%16 = icmp eq i64 %22, %14
br i1 %16, label %23, label %17
17: ; preds = %13, %15
%18 = phi i64 [ 0, %13 ], [ %22, %15 ]
%19 = getelementptr inbounds i64, i64* %6, i64 %18
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 2000
%22 = add nuw nsw i64 %18, 1
br i1 %21, label %23, label %15
23: ; preds = %15, %17, %2
%24 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), %17 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), %15 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %24, i64 2000)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
}