#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 */
struct test {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ expect(char *, int, int, int /*<<< orphan*/);
int setregid(int, int);
void priv_cred_setregid(int asroot, int injail, struct test *test) {
  int error;
  error = setregid(200, 200);
  if (asroot && injail)
    expect("priv_setregid(asroot, injail)", error, 0, 0);
  if (asroot && !injail)
    expect("priv_setregid(asroot, !injail)", error, 0, 0);
  if (!asroot && injail)
    expect("priv_setregid(!asroot, injail)", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_setregid(!asroot, !injail)", error, -1, EPERM);
}


x86 assembly (clang, -O0):
<priv_cred_setregid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0xc8,%esi
mov    %esi,%edi
call   1040 <setregid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1168 <priv_cred_setregid+0x48>
cmpl   $0x0,-0x8(%rbp)
je     1168 <priv_cred_setregid+0x48>
mov    -0x14(%rbp),%esi
lea    0xea1(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     118f <priv_cred_setregid+0x6f>
cmpl   $0x0,-0x8(%rbp)
jne    118f <priv_cred_setregid+0x6f>
mov    -0x14(%rbp),%esi
lea    0xe98(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c0 <priv_cred_setregid+0xa0>
cmpl   $0x0,-0x8(%rbp)
je     11c0 <priv_cred_setregid+0xa0>
mov    -0x14(%rbp),%esi
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
lea    0xe87(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11f1 <priv_cred_setregid+0xd1>
cmpl   $0x0,-0x8(%rbp)
jne    11f1 <priv_cred_setregid+0xd1>
mov    -0x14(%rbp),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%ecx
lea    0xe75(%rip),%rdi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_cred_setregid>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0xc8,%edi
mov    $0xc8,%esi
call   1040 <setregid@plt>
mov    %eax,%r14d
test   %ebx,%ebx
je     1155 <priv_cred_setregid+0x35>
test   %ebp,%ebp
je     1155 <priv_cred_setregid+0x35>
lea    0xeb7(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <expect@plt>
test   %ebx,%ebx
je     1170 <priv_cred_setregid+0x50>
test   %ebp,%ebp
jne    1170 <priv_cred_setregid+0x50>
lea    0xeba(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <expect@plt>
test   %ebx,%ebx
jne    1195 <priv_cred_setregid+0x75>
test   %ebp,%ebp
je     1195 <priv_cred_setregid+0x75>
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
lea    0xeb5(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1030 <expect@plt>
or     %ebx,%ebp
je     119e <priv_cred_setregid+0x7e>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <expect@plt>

LLVM IR (-O0):
%struct.test = type { i32 }
@.str = [30 x i8] c"priv_setregid(asroot, injail)\00"
@.str.1 = [31 x i8] c"priv_setregid(asroot, !injail)\00"
@.str.2 = [31 x i8] c"priv_setregid(!asroot, injail)\00"
@EPERM = global i32 0
@.str.3 = [32 x i8] c"priv_setregid(!asroot, !injail)\00"
define void @priv_cred_setregid(i32 %0, i32 %1, %struct.test* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.test*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store %struct.test* %2, %struct.test** %6
%8 = call i32 @setregid(i32 200, i32 200)
store i32 %8, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %7
%16 = call i32 @expect(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %15, i32 0, i32 0)
br label %17
17: ; preds = %14, %11, %3
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %7
%25 = call i32 @expect(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 0, i32 0)
br label %26
26: ; preds = %23, %20, %17
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %7
%34 = load i32, i32* @EPERM
%35 = call i32 @expect(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 -1, i32 %34)
br label %36
36: ; preds = %32, %29, %26
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* %7
%44 = load i32, i32* @EPERM
%45 = call i32 @expect(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 -1, i32 %44)
br label %46
46: ; preds = %42, %39, %36
ret void
}

LLVM IR (-O2):
%struct.test = type { i32 }
@.str = [30 x i8] c"priv_setregid(asroot, injail)\00"
@.str.1 = [31 x i8] c"priv_setregid(asroot, !injail)\00"
@.str.2 = [31 x i8] c"priv_setregid(!asroot, injail)\00"
@EPERM = global i32 0
@.str.3 = [32 x i8] c"priv_setregid(!asroot, !injail)\00"
define void @priv_cred_setregid(i32 %0, i32 %1, %struct.test* nocapture readnone %2) {
%4 = tail call i32 @setregid(i32 200, i32 200)
%5 = icmp ne i32 %0, 0
%6 = icmp ne i32 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @expect(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0, i32 0)
br label %10
10: ; preds = %8, %3
%11 = icmp eq i32 %0, 0
%12 = or i1 %11, %6
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @expect(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 0, i32 0)
br label %15
15: ; preds = %13, %10
%16 = and i1 %11, %6
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* @EPERM
%19 = tail call i32 @expect(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 -1, i32 %18)
br label %20
20: ; preds = %17, %15
%21 = or i32 %1, %0
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EPERM
%25 = tail call i32 @expect(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 -1, i32 %24)
br label %26
26: ; preds = %23, %20
ret void
}