#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 /*<<< orphan*/ getpagesize();
int munlock(int *, int /*<<< orphan*/);
void priv_vm_munlock(int asroot, int injail, struct test *test) {
  int error;
  error = munlock(&error, getpagesize());
  if (asroot && injail)
    expect("priv_vm_munlock(asroot, injail)", error, -1, EPERM);
  if (asroot && !injail)
    expect("priv_vm_munlock(asroot, !injail", error, 0, 0);
  if (!asroot && injail)
    expect("priv_vm_munlock(!asroot, injail", error, -1, EPERM);
  if (!asroot && !injail)
    expect("priv_vm_munlock(!asroot, !injail", error, -1, EPERM);
}


x86 assembly (clang, -O0):
<priv_vm_munlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getpagesize@plt>
mov    %eax,%esi
lea    -0x14(%rbp),%rdi
call   1030 <munlock@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1188 <priv_vm_munlock+0x58>
cmpl   $0x0,-0x8(%rbp)
je     1188 <priv_vm_munlock+0x58>
mov    -0x14(%rbp),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
lea    0xe82(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
je     11af <priv_vm_munlock+0x7f>
cmpl   $0x0,-0x8(%rbp)
jne    11af <priv_vm_munlock+0x7f>
mov    -0x14(%rbp),%esi
lea    0xe7a(%rip),%rdi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11e0 <priv_vm_munlock+0xb0>
cmpl   $0x0,-0x8(%rbp)
je     11e0 <priv_vm_munlock+0xb0>
mov    -0x14(%rbp),%esi
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
lea    0xe6a(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1211 <priv_vm_munlock+0xe1>
cmpl   $0x0,-0x8(%rbp)
jne    1211 <priv_vm_munlock+0xe1>
mov    -0x14(%rbp),%esi
mov    0x2dda(%rip),%rax
mov    (%rax),%ecx
lea    0xe59(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<priv_vm_munlock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <getpagesize@plt>
lea    0x4(%rsp),%rdi
mov    %eax,%esi
call   1030 <munlock@plt>
mov    %eax,0x4(%rsp)
test   %ebp,%ebp
je     1172 <priv_vm_munlock+0x42>
test   %ebx,%ebx
je     1172 <priv_vm_munlock+0x42>
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%ecx
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
test   %ebp,%ebp
je     118e <priv_vm_munlock+0x5e>
test   %ebx,%ebx
jne    118e <priv_vm_munlock+0x5e>
mov    0x4(%rsp),%esi
lea    0xe9b(%rip),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <expect@plt>
test   %ebp,%ebp
jne    11b4 <priv_vm_munlock+0x84>
test   %ebx,%ebx
je     11b4 <priv_vm_munlock+0x84>
mov    0x4(%rsp),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
lea    0xe96(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
or     %ebp,%ebx
jne    11d6 <priv_vm_munlock+0xa6>
mov    0x4(%rsp),%esi
mov    0x2e15(%rip),%rax
mov    (%rax),%ecx
lea    0xe94(%rip),%rdi
mov    $0xffffffff,%edx
call   1040 <expect@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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