#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__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int setegid(scalar_t__);
int setgid(scalar_t__);
int /*<<< orphan*/ warn(char *);
int setresgid(gid_t rgid, gid_t egid, gid_t sgid) {
  assert(rgid == egid && egid == sgid);
  if (setegid(egid) == -1) {
    warn("setegid");
    return -1;
  } else if (setgid(rgid) == -1) {
    warn("setgid");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setresgid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x21(%rbp)
jne    1175 <setresgid+0x35>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <setegid@plt>
cmp    $0xffffffff,%eax
jne    11ac <setresgid+0x6c>
lea    0xe65(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <setresgid+0xa2>
mov    -0x10(%rbp),%rdi
call   1050 <setgid@plt>
cmp    $0xffffffff,%eax
jne    11d6 <setresgid+0x96>
lea    0xe43(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <setresgid+0xa2>
jmp    11db <setresgid+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setresgid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rdi,%rax
xor    %rsi,%rax
xor    %rsi,%rdx
xor    %edi,%edi
or     %rax,%rdx
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1060 <setegid@plt>
cmp    $0xffffffff,%eax
je     1188 <setresgid+0x48>
mov    %r14,%rdi
call   1050 <setgid@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1199 <setresgid+0x59>
lea    0xe82(%rip),%rdi
jmp    118f <setresgid+0x4f>
lea    0xe71(%rip),%rdi
call   1030 <warn@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"setegid\00"
@.str.1 = [7 x i8] c"setgid\00"
define i32 @setresgid(i64 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %5
%9 = load i64, i64* %6
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = icmp eq i64 %12, %13
br label %15
15: ; preds = %11, %3
%16 = phi i1 [ false, %3 ], [ %14, %11 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %6
%20 = call i32 @setegid(i64 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %32
24: ; preds = %15
%25 = load i64, i64* %5
%26 = call i32 @setgid(i64 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %32
30: ; preds = %24
br label %31
31: ; preds = %30
store i32 0, i32* %4
br label %32
32: ; preds = %31, %28, %22
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [8 x i8] c"setegid\00"
@.str.1 = [7 x i8] c"setgid\00"
define i32 @setresgid(i64 %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %0, %1
%5 = icmp eq i64 %1, %2
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @setegid(i64 %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = tail call i32 @setgid(i64 %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11, %3
%15 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %11 ]
%16 = tail call i32 @warn(i8* %15)
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ 0, %11 ], [ -1, %14 ]
ret i32 %18
}