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

/* Variables and functions */
scalar_t__ EFAULT;
scalar_t__ EPERM;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int getresgid(int *, int *, int *);
int setresgid(int, int, int);
int /*<<< orphan*/ setresuid(int, int, int);
int test_get_set_gid(void) {
  gid_t rgid, egid, sgid;
  int error;
  error = getresgid((void *)1, (void *)1, (void *)1);
  assert(error < 0 && errno == EFAULT);
  error = getresgid(&rgid, &egid, &sgid);
  assert(error == 0);
  assert(rgid == 0 && egid == 0 && sgid == 0);
  rgid = 1, egid = 2, sgid = 3;
  error = setresgid(rgid, egid, sgid);
  assert(error == 0);
  getresgid(&rgid, &egid, &sgid);
  assert(rgid == 1 && egid == 2 && sgid == 3);
  setresuid(1, 1, 1);
  rgid = -1, egid = 3, sgid = -1;
  error = setresgid(rgid, egid, sgid);
  assert(error == 0);
  getresgid(&rgid, &egid, &sgid);
  assert(rgid == 1 && egid == 3 && sgid == 3);
  rgid = -1, egid = 2, sgid = -1;
  error = setresgid(rgid, egid, sgid);
  assert(error < 0 && errno == EPERM);
  getresgid(&rgid, &egid, &sgid);
  assert(rgid == 1 && egid == 3 && sgid == 3);
  return 0;
}


x86 assembly (clang, -O0):
<test_get_set_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edx
mov    %rdx,%rdi
mov    %rdx,%rsi
call   1030 <getresgid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1184 <test_get_set_gid+0x44>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <getresgid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x12(%rbp)
jne    11de <test_get_set_gid+0x9e>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x12(%rbp)
jne    11de <test_get_set_gid+0x9e>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <setresgid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <getresgid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x13(%rbp)
jne    125b <test_get_set_gid+0x11b>
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x13(%rbp)
jne    125b <test_get_set_gid+0x11b>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x1,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1040 <setresuid@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <setresgid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <getresgid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x14(%rbp)
jne    12e6 <test_get_set_gid+0x1a6>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x14(%rbp)
jne    12e6 <test_get_set_gid+0x1a6>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <setresgid@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
jge    1342 <test_get_set_gid+0x202>
mov    0x2ca9(%rip),%rax
mov    (%rax),%rax
mov    0x2c8f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <getresgid@plt>
xor    %eax,%eax
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x16(%rbp)
jne    1388 <test_get_set_gid+0x248>
xor    %eax,%eax
cmpl   $0x3,-0x8(%rbp)
mov    %al,-0x16(%rbp)
jne    1388 <test_get_set_gid+0x248>
cmpl   $0x3,-0xc(%rbp)
sete   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_set_gid>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <getresgid@plt>
test   %eax,%eax
sets   %al
mov    0x2e6d(%rip),%r12
mov    (%r12),%rcx
mov    0x2e82(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
lea    0x14(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <getresgid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    0x14(%rsp),%eax
or     0x10(%rsp),%eax
xor    %edi,%edi
or     0xc(%rsp),%eax
sete   %dil
call   1060 <assert@plt>
movl   $0x1,0x14(%rsp)
movl   $0x2,0x10(%rsp)
movl   $0x3,0xc(%rsp)
mov    $0x1,%edi
mov    $0x2,%esi
mov    $0x3,%edx
call   1050 <setresgid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <getresgid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x2,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1060 <assert@plt>
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <setresuid@plt>
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0x3,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0xffffffff,%edi
mov    $0x3,%esi
mov    $0xffffffff,%edx
call   1050 <setresgid@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <getresgid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x3,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1060 <assert@plt>
movl   $0xffffffff,0x14(%rsp)
ff
movl   $0x2,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0xffffffff,%edi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1050 <setresgid@plt>
test   %eax,%eax
sets   %al
mov    (%r12),%rcx
mov    0x2cdb(%rip),%rdx
cmp    (%rdx),%rcx
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <getresgid@plt>
mov    0x14(%rsp),%eax
xor    $0x1,%eax
mov    0x10(%rsp),%ecx
xor    $0x3,%ecx
or     %eax,%ecx
mov    0xc(%rsp),%eax
xor    $0x3,%eax
xor    %edi,%edi
or     %ecx,%eax
sete   %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EFAULT = global i64 0
@EPERM = global i64 0
define i32 @test_get_set_gid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @getresgid(i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*))
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EFAULT
%11 = icmp eq i64 %9, %10
br label %12
12: ; preds = %8, %0
%13 = phi i1 [ false, %0 ], [ %11, %8 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %12
%24 = load i32, i32* %2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 0
br label %29
29: ; preds = %26, %23, %12
%30 = phi i1 [ false, %23 ], [ false, %12 ], [ %28, %26 ]
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%33 = load i32, i32* %1
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = call i32 @setresgid(i32 %33, i32 %34, i32 %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%42 = load i32, i32* %1
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %50
44: ; preds = %29
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, 2
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 3
br label %50
50: ; preds = %47, %44, %29
%51 = phi i1 [ false, %44 ], [ false, %29 ], [ %49, %47 ]
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = call i32 @setresuid(i32 1, i32 1, i32 1)
store i32 -1, i32* %1
store i32 3, i32* %2
store i32 -1, i32* %3
%55 = load i32, i32* %1
%56 = load i32, i32* %2
%57 = load i32, i32* %3
%58 = call i32 @setresgid(i32 %55, i32 %56, i32 %57)
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = icmp eq i32 %59, 0
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%64 = load i32, i32* %1
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %72
66: ; preds = %50
%67 = load i32, i32* %2
%68 = icmp eq i32 %67, 3
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %3
%71 = icmp eq i32 %70, 3
br label %72
72: ; preds = %69, %66, %50
%73 = phi i1 [ false, %66 ], [ false, %50 ], [ %71, %69 ]
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
store i32 -1, i32* %1
store i32 2, i32* %2
store i32 -1, i32* %3
%76 = load i32, i32* %1
%77 = load i32, i32* %2
%78 = load i32, i32* %3
%79 = call i32 @setresgid(i32 %76, i32 %77, i32 %78)
store i32 %79, i32* %4
%80 = load i32, i32* %4
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %72
%83 = load i64, i64* @errno
%84 = load i64, i64* @EPERM
%85 = icmp eq i64 %83, %84
br label %86
86: ; preds = %82, %72
%87 = phi i1 [ false, %72 ], [ %85, %82 ]
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%91 = load i32, i32* %1
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %99
93: ; preds = %86
%94 = load i32, i32* %2
%95 = icmp eq i32 %94, 3
br i1 %95, label %96, label %99
96: ; preds = %93
%97 = load i32, i32* %3
%98 = icmp eq i32 %97, 3
br label %99
99: ; preds = %96, %93, %86
%100 = phi i1 [ false, %93 ], [ false, %86 ], [ %98, %96 ]
%101 = zext i1 %100 to i32
%102 = call i32 @assert(i32 %101)
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@EFAULT = global i64 0
@EPERM = global i64 0
define i32 @test_get_set_gid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @getresgid(i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*), i32* inttoptr (i64 1 to i32*))
%8 = icmp slt i32 %7, 0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EFAULT
%11 = icmp eq i64 %9, %10
%12 = select i1 %8, i1 %11, i1 false
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 0
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
%23 = select i1 %20, i1 %22, i1 false
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
%26 = select i1 %23, i1 %25, i1 false
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%29 = call i32 @setresgid(i32 1, i32 2, i32 3)
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%34 = load i32, i32* %1
%35 = icmp eq i32 %34, 1
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 2
%38 = select i1 %35, i1 %37, i1 false
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 3
%41 = select i1 %38, i1 %40, i1 false
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @setresuid(i32 1, i32 1, i32 1)
store i32 -1, i32* %1
store i32 3, i32* %2
store i32 -1, i32* %3
%45 = call i32 @setresgid(i32 -1, i32 3, i32 -1)
%46 = icmp eq i32 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%50 = load i32, i32* %1
%51 = icmp eq i32 %50, 1
%52 = load i32, i32* %2
%53 = icmp eq i32 %52, 3
%54 = select i1 %51, i1 %53, i1 false
%55 = load i32, i32* %3
%56 = icmp eq i32 %55, 3
%57 = select i1 %54, i1 %56, i1 false
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
store i32 -1, i32* %1
store i32 2, i32* %2
store i32 -1, i32* %3
%60 = call i32 @setresgid(i32 -1, i32 2, i32 -1)
%61 = icmp slt i32 %60, 0
%62 = load i64, i64* @errno
%63 = load i64, i64* @EPERM
%64 = icmp eq i64 %62, %63
%65 = select i1 %61, i1 %64, i1 false
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = call i32 @getresgid(i32* %1, i32* %2, i32* %3)
%69 = load i32, i32* %1
%70 = icmp eq i32 %69, 1
%71 = load i32, i32* %2
%72 = icmp eq i32 %71, 3
%73 = select i1 %70, i1 %72, i1 false
%74 = load i32, i32* %3
%75 = icmp eq i32 %74, 3
%76 = select i1 %73, i1 %75, i1 false
%77 = zext i1 %76 to i32
%78 = call i32 @assert(i32 %77)
ret i32 0
}