#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 NGROUPS_MAX;
char *get_group_name(scalar_t__);
size_t getgroups(int, scalar_t__ *);
int /*<<< orphan*/ printf(char *, long, char const *);
int print_groups(void) {
  gid_t groups[NGROUPS_MAX + 1];
  size_t num_groups;
  if ((num_groups = getgroups(NGROUPS_MAX + 1, groups)) == -1) {
    return -1;
  }
  for (int pos = 0; pos < num_groups; ++pos) {
    const char *name;
    gid_t gid = groups[pos];
    if ((name = get_group_name(gid)) == NULL) {
      name = "[unknown]";
    }
    printf("%ld:\t%s\n", (long)gid, name);
  }
}


x86 assembly (clang, -O0):
<print_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1040 <getgroups@plt>
mov    %rax,-0x20(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    119a <print_groups+0x6a>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    120a <print_groups+0xda>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1203 <print_groups+0xd3>
mov    -0x40(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <get_group_name@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11e1 <print_groups+0xb1>
lea    0xe23(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a1 <print_groups+0x71>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_groups>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    %rsp,%r12
lea    0xf(,%rdi,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rsi
call   1040 <getgroups@plt>
mov    %rax,%r14
add    $0x1,%rax
cmp    $0x2,%rax
jb     11b1 <print_groups+0x81>
xor    %ebx,%ebx
lea    0xe8d(%rip),%r15
nopl   (%rax)
mov    (%r12,%rbx,8),%r13
mov    %r13,%rdi
call   1050 <get_group_name@plt>
test   %rax,%rax
lea    0xe6a(%rip),%rcx
cmove  %rcx,%rax
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <print_groups+0x50>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NGROUPS_MAX = global i32 0
@.str = [10 x i8] c"[unknown]\00"
@.str.1 = [9 x i8] c"%ld:\09%s\0A\00"
define i32 @print_groups() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = load i32, i32* @NGROUPS_MAX
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %2
%13 = alloca i64, i64 %11
store i64 %11, i64* %3
%14 = load i32, i32* @NGROUPS_MAX
%15 = add nsw i32 %14, 1
%16 = call i64 @getgroups(i32 %15, i64* %13)
store i64 %16, i64* %4
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %0
store i32 -1, i32* %1
store i32 1, i32* %5
br label %42
19: ; preds = %0
store i32 0, i32* %6
br label %20
20: ; preds = %38, %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = load i64, i64* %4
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %20
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i64, i64* %13, i64 %27
%29 = load i64, i64* %28
store i64 %29, i64* %8
%30 = load i64, i64* %8
%31 = call i8* @get_group_name(i64 %30)
store i8* %31, i8** %7
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %25
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
br label %34
34: ; preds = %33, %25
%35 = load i64, i64* %8
%36 = load i8*, i8** %7
%37 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %35, i8* %36)
br label %38
38: ; preds = %34
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %20
41: ; preds = %20
store i32 0, i32* %5
br label %42
42: ; preds = %41, %18
%43 = load i8*, i8** %2
%44 = load i32, i32* %5
switch i32 %44, label %47 [
i32 0, label %45
i32 1, label %45
]
45: ; preds = %42, %42
%46 = load i32, i32* %1
ret i32 %46
47: ; preds = %42
unreachable
}

LLVM IR (-O2):
@NGROUPS_MAX = global i32 0
@.str = [10 x i8] c"[unknown]\00"
@.str.1 = [9 x i8] c"%ld:\09%s\0A\00"
define i32 @print_groups() {
%1 = load i32, i32* @NGROUPS_MAX
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i64, i64 %3
%5 = call i64 @getgroups(i32 %2, i64* %4)
switch i64 %5, label %6 [
i64 -1, label %16
i64 0, label %16
]
6: ; preds = %0, %6
%7 = phi i64 [ %14, %6 ], [ 0, %0 ]
%8 = getelementptr inbounds i64, i64* %4, i64 %7
%9 = load i64, i64* %8
%10 = call i8* @get_group_name(i64 %9)
%11 = icmp eq i8* %10, null
%12 = select i1 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %10
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %9, i8* %12)
%14 = add nuw i64 %7, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %6
16: ; preds = %6, %0, %0
ret i32 -1
}