#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int NGROUPS_MAX;
int _initgroups(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getgroups(int, int *);
int groupIdFromName(char *);
char *groupNameFromId(int);
int /*<<< orphan*/ helpAndLeave(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *user, *group;
  gid_t gid, suppGroups[(NGROUPS_MAX + 1)];
  int nGroups, i, status;
  if (argc != 3) {
    helpAndLeave(argv[0], EXIT_FAILURE);
  }
  user = argv[1];
  group = argv[2];
  status = groupIdFromName(group);
  if (status == -1) {
    fprintf(stderr, "Unknown group: %s\n", group);
    exit(EXIT_FAILURE);
  } else {
    gid = status;
  }
  if (_initgroups(user, gid) == -1) {
    pexit("_initgroups");
  }
  if ((nGroups = getgroups((NGROUPS_MAX + 1), suppGroups)) == -1) {
    pexit("getgroups");
  }
  printf("Supplementary groups are now:\n");
  for (i = 0; i < nGroups; ++i) {
    gid = suppGroups[i];
    group = groupNameFromId(gid);
    printf("%d - %s\n", gid, group);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
call   1070 <helpAndLeave@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <groupIdFromName@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    124a <main+0xba>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc9(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10b0 <_initgroups@plt>
cmp    $0xffffffff,%eax
jne    1271 <main+0xe1>
lea    0xda7(%rip),%rdi
call   10a0 <pexit@plt>
mov    -0x50(%rbp),%rsi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <getgroups@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    129e <main+0x10e>
lea    0xd86(%rip),%rdi
call   10a0 <pexit@plt>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    12fc <main+0x16c>
mov    -0x50(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1090 <groupNameFromId@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12b3 <main+0x123>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e30(%rip),%r13
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x3,%edi
je     11ea <main+0x4a>
mov    (%r14),%rdi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1080 <helpAndLeave@plt>
mov    0x8(%r14),%r12
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1040 <groupIdFromName@plt>
cmp    $0xffffffff,%eax
jne    1225 <main+0x85>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10c0 <_initgroups@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xa0>
lea    0xdd8(%rip),%rdi
call   10b0 <pexit@plt>
mov    0x0(%r13),%edi
add    $0x1,%edi
mov    %r15,%rsi
call   1070 <getgroups@plt>
cmp    $0xffffffff,%eax
jne    126e <main+0xce>
lea    0xdc4(%rip),%rdi
call   10b0 <pexit@plt>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
jmp    12b5 <main+0x115>
mov    %eax,%ebx
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    12b5 <main+0x115>
mov    %ebx,%r12d
lea    0xd9f(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%r13d
mov    %r13d,%edi
call   10a0 <groupNameFromId@plt>
mov    %r14,%rdi
mov    %r13d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1290 <main+0xf0>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@NGROUPS_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Unknown group: %s\0A\00"
@.str.1 = [12 x i8] c"_initgroups\00"
@.str.2 = [10 x i8] c"getgroups\00"
@.str.3 = [31 x i8] c"Supplementary groups are now:\0A\00"
@.str.4 = [9 x i8] c"%d - %s\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 i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @NGROUPS_MAX
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i32, i64 %16
store i64 %16, i64* %10
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @helpAndLeave(i8* %24, i32 %25)
br label %27
27: ; preds = %21, %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = call i32 @groupIdFromName(i8* %34)
store i32 %35, i32* %13
%36 = load i32, i32* %13
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %44
38: ; preds = %27
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %7
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %27
%45 = load i32, i32* %13
store i32 %45, i32* %8
br label %46
46: ; preds = %44
%47 = load i8*, i8** %6
%48 = load i32, i32* %8
%49 = call i32 @_initgroups(i8* %47, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %46
%54 = load i32, i32* @NGROUPS_MAX
%55 = add nsw i32 %54, 1
%56 = call i32 @getgroups(i32 %55, i32* %18)
store i32 %56, i32* %11
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @pexit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %12
br label %62
62: ; preds = %76, %60
%63 = load i32, i32* %12
%64 = load i32, i32* %11
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %79
66: ; preds = %62
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %18, i64 %68
%70 = load i32, i32* %69
store i32 %70, i32* %8
%71 = load i32, i32* %8
%72 = call i8* @groupNameFromId(i32 %71)
store i8* %72, i8** %7
%73 = load i32, i32* %8
%74 = load i8*, i8** %7
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %73, i8* %74)
br label %76
76: ; preds = %66
%77 = load i32, i32* %12
%78 = add nsw i32 %77, 1
store i32 %78, i32* %12
br label %62
79: ; preds = %62
%80 = load i32, i32* @EXIT_SUCCESS
%81 = call i32 @exit(i32 %80)
unreachable
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Unknown group: %s\0A\00"
@.str.1 = [12 x i8] c"_initgroups\00"
@.str.2 = [10 x i8] c"getgroups\00"
@.str.4 = [9 x i8] c"%d - %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [30 x i8] c"Supplementary groups are now:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @NGROUPS_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i32, i64 %5
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @helpAndLeave(i8* %9, i32 %10)
br label %12
12: ; preds = %8, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @groupIdFromName(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = tail call i32 @_initgroups(i8* %14, i32 %17)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @pexit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = load i32, i32* @NGROUPS_MAX
%31 = add nsw i32 %30, 1
%32 = call i32 @getgroups(i32 %31, i32* %6)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @pexit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %50
37: ; preds = %29
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%39 = icmp sgt i32 %32, 0
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = zext i32 %32 to i64
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ 0, %40 ], [ %48, %42 ]
%44 = getelementptr inbounds i32, i32* %6, i64 %43
%45 = load i32, i32* %44
%46 = call i8* @groupNameFromId(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %45, i8* %46)
%48 = add nuw nsw i64 %43, 1
%49 = icmp eq i64 %48, %41
br i1 %49, label %50, label %42
50: ; preds = %42, %34, %37
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
unreachable
}