#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 */
struct group {
  char *gr_name;
};
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
struct group *getgrgid(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void print_gid(gid_t *groups, int len) {
  int i;
  for (i = 0; i < len; i++) {
    struct group *gr = getgrgid(groups[i]);
    if (gr != NULL)
      printf("%s ", gr->gr_name);
  }
  printf("\b\n");
}


x86 assembly (clang, -O0):
<print_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1189 <print_gid+0x69>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1176 <print_gid+0x56>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117b <print_gid+0x5b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <print_gid+0x16>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_gid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1176 <print_gid+0x46>
mov    %rdi,%r15
mov    %esi,%r12d
lea    0xeb7(%rip),%r14
xor    %ebx,%ebx
jmp    1159 <print_gid+0x29>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1176 <print_gid+0x46>
mov    (%r15,%rbx,4),%edi
call   1050 <getgrgid@plt>
test   %rax,%rax
je     1150 <print_gid+0x20>
mov    (%rax),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1150 <print_gid+0x20>
lea    0xe87(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.group = type { i8* }
@.str = [4 x i8] c"%s \00"
@.str.1 = [3 x i8] c"\08\0A\00"
define void @print_gid(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.group*
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call %struct.group* @getgrgid(i32 %16)
store %struct.group* %17, %struct.group** %6
%18 = load %struct.group*, %struct.group** %6
%19 = icmp ne %struct.group* %18, null
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = load %struct.group*, %struct.group** %6
%22 = getelementptr inbounds %struct.group, %struct.group* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %20, %11
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.group = type { i8* }
@.str = [4 x i8] c"%s \00"
@str = [2 x i8] c"\08\00"
define void @print_gid(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ 0, %4 ], [ %17, %16 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = tail call %struct.group* @getgrgid(i32 %9)
%11 = icmp eq %struct.group* %10, null
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = getelementptr inbounds %struct.group, %struct.group* %10, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %6
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %16, %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}