#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 setresuid(int, int, int);
void priv_cred_setresuid(int asroot, int injail, struct test *test) {
  int error;
  error = setresuid(200, 200, 200);
  if (asroot && injail)
    expect("priv_setresuid(asroot, injail)", error, 0, 0);
  if (asroot && !injail)
    expect("priv_setresuid(asroot, !injail)", error, 0, 0);
  if (!asroot && injail)
    expect("priv_setresuid(!asroot, injail)", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_setresuid(!asroot, !injail)", error, -1, EPERM);
}


x86 assembly (clang, -O0):
<priv_cred_setresuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0xc8,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <setresuid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     116a <priv_cred_setresuid+0x4a>
cmpl   $0x0,-0x8(%rbp)
je     116a <priv_cred_setresuid+0x4a>
mov    -0x14(%rbp),%esi
lea    0xe9f(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     1191 <priv_cred_setresuid+0x71>
cmpl   $0x0,-0x8(%rbp)
jne    1191 <priv_cred_setresuid+0x71>
mov    -0x14(%rbp),%esi
lea    0xe97(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c2 <priv_cred_setresuid+0xa2>
cmpl   $0x0,-0x8(%rbp)
je     11c2 <priv_cred_setresuid+0xa2>
mov    -0x14(%rbp),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%ecx
lea    0xe87(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11f3 <priv_cred_setresuid+0xd3>
cmpl   $0x0,-0x8(%rbp)
jne    11f3 <priv_cred_setresuid+0xd3>
mov    -0x14(%rbp),%esi
mov    0x2df8(%rip),%rax
mov    (%rax),%ecx
lea    0xe76(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_cred_setresuid>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0xc8,%edi
mov    $0xc8,%esi
mov    $0xc8,%edx
call   1030 <setresuid@plt>
mov    %eax,%r14d
test   %ebp,%ebp
je     115a <priv_cred_setresuid+0x3a>
test   %ebx,%ebx
je     115a <priv_cred_setresuid+0x3a>
lea    0xeb2(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <expect@plt>
test   %ebp,%ebp
je     1175 <priv_cred_setresuid+0x55>
test   %ebx,%ebx
jne    1175 <priv_cred_setresuid+0x55>
lea    0xeb6(%rip),%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <expect@plt>
test   %ebp,%ebp
jne    119a <priv_cred_setresuid+0x7a>
test   %ebx,%ebx
je     119a <priv_cred_setresuid+0x7a>
mov    0x2e54(%rip),%rax
mov    (%rax),%ecx
lea    0xeb2(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
or     %ebp,%ebx
je     11a3 <priv_cred_setresuid+0x83>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
lea    0xeac(%rip),%rdi
mov    %r14d,%esi
mov    $0xffffffff,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <expect@plt>

LLVM IR (-O0):
%struct.test = type { i32 }
@.str = [31 x i8] c"priv_setresuid(asroot, injail)\00"
@.str.1 = [32 x i8] c"priv_setresuid(asroot, !injail)\00"
@.str.2 = [32 x i8] c"priv_setresuid(!asroot, injail)\00"
@EPERM = global i32 0
@.str.3 = [33 x i8] c"priv_setresuid(!asroot, !injail)\00"
define void @priv_cred_setresuid(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 @setresuid(i32 200, 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 ([31 x i8], [31 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 ([32 x i8], [32 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 ([32 x i8], [32 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 ([33 x i8], [33 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 = [31 x i8] c"priv_setresuid(asroot, injail)\00"
@.str.1 = [32 x i8] c"priv_setresuid(asroot, !injail)\00"
@.str.2 = [32 x i8] c"priv_setresuid(!asroot, injail)\00"
@EPERM = global i32 0
@.str.3 = [33 x i8] c"priv_setresuid(!asroot, !injail)\00"
define void @priv_cred_setresuid(i32 %0, i32 %1, %struct.test* nocapture readnone %2) {
%4 = tail call i32 @setresuid(i32 200, 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 ([31 x i8], [31 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 ([32 x i8], [32 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 ([32 x i8], [32 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 ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 -1, i32 %24)
br label %26
26: ; preds = %23, %20
ret void
}