#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;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int _getgroups(int, int *);
int /*<<< orphan*/ msg(char *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char *);
void show_groups(char *s) {
  gid_t g[32];
  int n, i;
  char buf[256];
  snprintf(buf, sizeof(buf), "getgroups ");
  n = _getgroups(1, g);
  for (i = 0; i < n; i++)
    snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%d ", g[i]);
  msg("%s: %s", s, buf);
}


x86 assembly (clang, -O0):
<show_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    $0x100,%esi
lea    0xe9e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rsi
mov    $0x1,%edi
call   1050 <_getgroups@plt>
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x94(%rbp),%eax
jge    121c <show_groups+0xdc>
lea    -0x1a0(%rbp),%rax
mov    %rax,-0x1b0(%rbp)
lea    -0x1a0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1b0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1a8(%rbp)
lea    -0x1a0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1a8(%rbp),%rdi
movslq %eax,%rcx
mov    $0x100,%eax
sub    %rcx,%rax
mov    %eax,%esi
movslq -0x98(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%ecx
lea    0xe0a(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    118a <show_groups+0x4a>
mov    -0x8(%rbp),%rsi
lea    -0x1a0(%rbp),%rdx
lea    0xde1(%rip),%rdi
call   1060 <msg@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_groups>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x188,%rsp
mov    %rdi,%r14
lea    0xea5(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x100(%rsp),%rsi
mov    $0x1,%edi
call   1050 <_getgroups@plt>
test   %eax,%eax
jle    11ca <show_groups+0x8a>
mov    %eax,%r13d
mov    %rsp,%r12
lea    0xe7e(%rip),%r15
xor    %ebp,%ebp
nop
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    $0x100,%esi
sub    %eax,%esi
mov    0x100(%rsp,%rbp,4),%ecx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1190 <show_groups+0x50>
lea    0xe3e(%rip),%rdi
mov    %rsp,%rdx
mov    %r14,%rsi
call   1060 <msg@plt>
add    $0x188,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"getgroups \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [7 x i8] c"%s: %s\00"
define void @show_groups(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
store i8* %0, i8** %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%10 = call i32 @_getgroups(i32 1, i32* %9)
store i32 %10, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %31, %1
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = sub i64 256, %23
%25 = trunc i64 %24 to i32
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %20, i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %15
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %11
34: ; preds = %11
%35 = load i8*, i8** %2
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%37 = call i32 @msg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"getgroups \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [7 x i8] c"%s: %s\00"
define void @show_groups(i8* %0) {
%2 = alloca [32 x i32]
%3 = alloca [256 x i8]
%4 = bitcast [32 x i32]* %2 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%8 = call i32 @_getgroups(i32 1, i32* %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %22, %12 ]
%14 = call i32 @strlen(i8* %5)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %15
%17 = call i32 @strlen(i8* %5)
%18 = sub i32 256, %17
%19 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %13
%20 = load i32, i32* %19
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %13, 1
%23 = icmp eq i64 %22, %11
br i1 %23, label %24, label %12
24: ; preds = %12, %1
%25 = call i32 @msg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %5)
ret void
}