#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__ uid_t;
typedef int /*<<< orphan*/ groups;
typedef scalar_t__ gid_t;

/* Variables and functions */
char *blurb();
int getgroups(int, scalar_t__ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, long);
int setgroups_needed_p(uid_t target_group) {
  gid_t groups[1024];
  int n, size;
  size = sizeof(groups) / sizeof(gid_t);
  n = getgroups(size - 1, groups);
  if (n < 0) {
    char buf[1024];
    sprintf(buf, "%s: getgroups(%ld, ...)", blurb(), (long int)(size - 1));
    perror(buf);
    return 1;
  } else if (n == 0)
    return 0;
  else if (n == 1 && groups[0] == target_group)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<setgroups_needed_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x400,-0x2018(%rbp)
mov    -0x2018(%rbp),%edi
sub    $0x1,%edi
lea    -0x2010(%rbp),%rsi
call   1040 <getgroups@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
jge    11d0 <setgroups_needed_p+0x90>
lea    -0x2420(%rbp),%rax
mov    %rax,-0x2428(%rbp)
mov    $0x0,%al
call   1030 <blurb@plt>
mov    -0x2428(%rbp),%rdi
mov    %rax,%rdx
mov    -0x2018(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0xe4d(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x2420(%rbp),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <setgroups_needed_p+0xda>
cmpl   $0x0,-0x2014(%rbp)
jne    11e9 <setgroups_needed_p+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    121a <setgroups_needed_p+0xda>
cmpl   $0x1,-0x2014(%rbp)
jne    1213 <setgroups_needed_p+0xd3>
mov    -0x2010(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1213 <setgroups_needed_p+0xd3>
movl   $0x0,-0x4(%rbp)
jmp    121a <setgroups_needed_p+0xda>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setgroups_needed_p>:
push   %rbx
sub    $0x2400,%rsp
mov    %rdi,%rbx
lea    0x400(%rsp),%rsi
mov    $0x3ff,%edi
call   1040 <getgroups@plt>
test   %eax,%eax
js     1176 <setgroups_needed_p+0x36>
je     11a4 <setgroups_needed_p+0x64>
cmp    $0x1,%eax
jne    119f <setgroups_needed_p+0x5f>
xor    %eax,%eax
cmp    %rbx,0x400(%rsp)
jne    119f <setgroups_needed_p+0x5f>
jmp    11a4 <setgroups_needed_p+0x64>
xor    %eax,%eax
call   1030 <blurb@plt>
lea    0xe7c(%rip),%rsi
mov    %rsp,%rbx
mov    $0x3ff,%ecx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
add    $0x2400,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"%s: getgroups(%ld, ...)\00"
define i32 @setgroups_needed_p(i64 %0) {
%2 = alloca [1024 x i64]
%3 = alloca [1024 x i8]
%4 = bitcast [1024 x i64]* %2 to i8*
%5 = getelementptr inbounds [1024 x i64], [1024 x i64]* %2, i64 0, i64 0
%6 = call i32 @getgroups(i32 1023, i64* %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i8* (...) @blurb()
%11 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %10, i64 1023)
%12 = call i32 @perror(i8* %9)
br label %18
13: ; preds = %1
switch i32 %6, label %17 [
i32 0, label %18
i32 1, label %14
]
14: ; preds = %13
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, %0
br i1 %16, label %18, label %17
17: ; preds = %13, %14
br label %18
18: ; preds = %14, %13, %17, %8
%19 = phi i32 [ 1, %8 ], [ 1, %17 ], [ %6, %13 ], [ 0, %14 ]
ret i32 %19
}