#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 /*<<< orphan*/ gid_t;

/* Variables and functions */
scalar_t__ setegid(int /*<<< orphan*/);
scalar_t__ setgid(int /*<<< orphan*/);
int setgroups(int, int /*<<< orphan*/ *);
int Privsep_SetGroup(gid_t gid) {
  if (setgroups(1, &gid) == -1)
    return (-1);
  if (setegid(gid) < 0)
    return (-1);
  if (setgid(gid) < 0)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<Privsep_SetGroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
call   1030 <setgroups@plt>
cmp    $0xffffffff,%eax
jne    115e <Privsep_SetGroup+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <Privsep_SetGroup+0x71>
mov    -0x8(%rbp),%edi
call   1050 <setegid@plt>
cmp    $0x0,%rax
jge    117c <Privsep_SetGroup+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <Privsep_SetGroup+0x71>
mov    -0x8(%rbp),%edi
call   1040 <setgid@plt>
cmp    $0x0,%rax
jge    119a <Privsep_SetGroup+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <Privsep_SetGroup+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Privsep_SetGroup>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x1,%edi
call   1030 <setgroups@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1170 <Privsep_SetGroup+0x40>
mov    0xc(%rsp),%edi
call   1050 <setegid@plt>
test   %rax,%rax
js     1170 <Privsep_SetGroup+0x40>
mov    0xc(%rsp),%edi
call   1040 <setgid@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @Privsep_SetGroup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @setgroups(i32 1, i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 -1, i32* %2
br label %18
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i64 @setegid(i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 -1, i32* %2
br label %18
12: ; preds = %7
%13 = load i32, i32* %3
%14 = call i64 @setgid(i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %2
br label %18
17: ; preds = %12
store i32 0, i32* %2
br label %18
18: ; preds = %17, %16, %11, %6
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @Privsep_SetGroup(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @setgroups(i32 1, i32* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = load i32, i32* %2
%7 = call i64 @setegid(i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = load i32, i32* %2
%11 = call i64 @setgid(i32 %10)
%12 = ashr i64 %11, 63
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %9, %5, %1
%15 = phi i32 [ -1, %1 ], [ -1, %5 ], [ %13, %9 ]
ret i32 %15
}