#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 uid_t;
typedef int gid_t;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ _SC_NGROUPS_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
int getgroups(long, int *);
scalar_t__ getresgid(int *, int *, int *);
scalar_t__ getresuid(int *, int *, int *);
scalar_t__ malloc(long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sysconf(int /*<<< orphan*/);
int display(void) {
  int i;
  uid_t ruid, euid, suid;
  gid_t rgid, egid, sgid;
  gid_t *groups = NULL;
  int ngroups = 0;
  long ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1;
  if (getresuid(&ruid, &euid, &suid) < 0) {
    perror("Could not getresuid");
    exit(1);
  }
  if (getresgid(&rgid, &egid, &sgid) < 0) {
    perror("Could not getresgid");
    exit(1);
  }
  groups = (gid_t *)malloc(ngroups_max * sizeof(gid_t));
  if (groups == NULL) {
    printf("Could not allocate memory\n");
    exit(EXIT_FAILURE);
  }
  ngroups = getgroups(ngroups_max, groups);
  if (ngroups < 0) {
    perror("getgroups");
    free(groups);
    exit(1);
  }
  printf("ruid=%d, euid=%d, suid=%d, ", ruid, euid, suid);
  printf("rgid=%d, egid=%d, sgid=%d, ", rgid, egid, sgid);
  printf("groups=");
  for (i = 0; i < ngroups; i++) {
    printf("%d", groups[i]);
    if (i < ngroups - 1)
      printf(",");
  }
  printf("\n");
  free(groups);
  return 0;
}


x86 assembly (clang, -O0):
<display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <getresuid@plt>
cmp    $0x0,%rax
jge    11ef <display+0x5f>
lea    0xe20(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <getresgid@plt>
cmp    $0x0,%rax
jge    1220 <display+0x90>
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1258 <display+0xc8>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <getgroups@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1291 <display+0x101>
lea    0xdca(%rip),%rdi
call   1090 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    132b <display+0x19b>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1318 <display+0x188>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    131d <display+0x18d>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12d4 <display+0x144>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %eax,%ebx
lea    0x1c(%rsp),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1080 <getresuid@plt>
test   %rax,%rax
js     12ea <display+0x13a>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <getresgid@plt>
test   %rax,%rax
js     12f3 <display+0x143>
add    $0x1,%ebx
movslq %ebx,%rbx
lea    0x0(,%rbx,4),%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1309 <display+0x159>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <getgroups@plt>
test   %eax,%eax
js     1323 <display+0x173>
mov    %eax,%r14d
mov    0x1c(%rsp),%esi
mov    0x18(%rsp),%edx
mov    0x14(%rsp),%ecx
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r14d,%r14d
je     12c8 <display+0x118>
lea    -0x1(%r14),%r12d
mov    %r14d,%r13d
lea    0xde1(%rip),%r14
xor    %ebx,%ebx
jmp    12a9 <display+0xf9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     12c8 <display+0x118>
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    %r12,%rbx
jae    12a0 <display+0xf0>
mov    $0x2c,%edi
call   1040 <putchar@plt>
jmp    12a0 <display+0xf0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd0f(%rip),%rdi
jmp    12fa <display+0x14a>
lea    0xd1a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd65(%rip),%rdi
call   1060 <puts@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xcfe(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@_SC_NGROUPS_MAX = global i32 0
@.str = [20 x i8] c"Could not getresuid\00"
@.str.1 = [20 x i8] c"Could not getresgid\00"
@.str.2 = [27 x i8] c"Could not allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"getgroups\00"
@.str.4 = [28 x i8] c"ruid=%d, euid=%d, suid=%d, \00"
@.str.5 = [28 x i8] c"rgid=%d, egid=%d, sgid=%d, \00"
@.str.6 = [8 x i8] c"groups=\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [2 x i8] c",\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @display() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
store i32* null, i32** %8
store i32 0, i32* %9
%11 = load i32, i32* @_SC_NGROUPS_MAX
%12 = call i32 @sysconf(i32 %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
store i64 %14, i64* %10
%15 = call i64 @getresuid(i32* %2, i32* %3, i32* %4)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i64 @getresgid(i32* %5, i32* %6, i32* %7)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i64, i64* %10
%28 = mul i64 %27, 4
%29 = call i64 @malloc(i64 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %8
%31 = load i32*, i32** %8
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %26
%38 = load i64, i64* %10
%39 = load i32*, i32** %8
%40 = call i32 @getgroups(i64 %38, i32* %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32*, i32** %8
%46 = call i32 @free(i32* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %37
%49 = load i32, i32* %2
%50 = load i32, i32* %3
%51 = load i32, i32* %4
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %49, i32 %50, i32 %51)
%53 = load i32, i32* %5
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %53, i32 %54, i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %58
58: ; preds = %76, %48
%59 = load i32, i32* %1
%60 = load i32, i32* %9
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %79
62: ; preds = %58
%63 = load i32*, i32** %8
%64 = load i32, i32* %1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %1
%70 = load i32, i32* %9
%71 = sub nsw i32 %70, 1
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %75
73: ; preds = %62
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %75
75: ; preds = %73, %62
br label %76
76: ; preds = %75
%77 = load i32, i32* %1
%78 = add nsw i32 %77, 1
store i32 %78, i32* %1
br label %58
79: ; preds = %58
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%81 = load i32*, i32** %8
%82 = call i32 @free(i32* %81)
ret i32 0
}

LLVM IR (-O2):
@_SC_NGROUPS_MAX = global i32 0
@.str = [20 x i8] c"Could not getresuid\00"
@.str.1 = [20 x i8] c"Could not getresgid\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [10 x i8] c"getgroups\00"
@.str.4 = [28 x i8] c"ruid=%d, euid=%d, suid=%d, \00"
@.str.5 = [28 x i8] c"rgid=%d, egid=%d, sgid=%d, \00"
@.str.6 = [8 x i8] c"groups=\00"
@.str.7 = [3 x i8] c"%d\00"
@str = [26 x i8] c"Could not allocate memory\00"
define i32 @display() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i32, i32* @_SC_NGROUPS_MAX
%14 = tail call i32 @sysconf(i32 %13)
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = call i64 @getresuid(i32* %1, i32* %2, i32* %3)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i64 @getresgid(i32* %4, i32* %5, i32* %6)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = shl nsw i64 %16, 2
%30 = call i64 @malloc(i64 %29)
%31 = inttoptr i64 %30 to i32*
%32 = icmp eq i64 %30, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
%38 = call i32 @getgroups(i64 %16, i32* %31)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @free(i32* %31)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = load i32, i32* %1
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %45, i32 %46, i32 %47)
%49 = load i32, i32* %4
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50, i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%54 = icmp eq i32 %38, 0
br i1 %54, label %70, label %55
55: ; preds = %44
%56 = add nsw i32 %38, -1
%57 = zext i32 %56 to i64
%58 = zext i32 %38 to i64
br label %59
59: ; preds = %55, %67
%60 = phi i64 [ 0, %55 ], [ %68, %67 ]
%61 = getelementptr inbounds i32, i32* %31, i64 %60
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %62)
%64 = icmp ult i64 %60, %57
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = call i32 @putchar(i32 44)
br label %67
67: ; preds = %59, %65
%68 = add nuw nsw i64 %60, 1
%69 = icmp eq i64 %68, %58
br i1 %69, label %70, label %59
70: ; preds = %67, %44
%71 = call i32 @putchar(i32 10)
%72 = call i32 @free(i32* %31)
ret i32 0
}