#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 */

/* Variables and functions */
int MCL_CURRENT;
int MCL_FUTURE;
scalar_t__ mlockall(int);
int /*<<< orphan*/ munlockall();
int /*<<< orphan*/ perror(char *);
int test_mlockall(int(test_function)(bool call_mlock)) {
  int ret = 1;
  if (mlockall(MCL_CURRENT | (MCL_FUTURE << 1) | MCL_FUTURE)) {
    perror("mlockall");
    return ret;
  }
  ret = test_function(false);
  munlockall();
  return ret;
}


x86 assembly (clang, -O0):
<test_mlockall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
or     %eax,%edi
mov    0x2e8f(%rip),%rax
or     (%rax),%edi
call   1030 <mlockall@plt>
cmp    $0x0,%rax
je     1189 <test_mlockall+0x59>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119e <test_mlockall+0x6e>
xor    %edi,%edi
call   *-0x10(%rbp)
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <munlockall@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mlockall>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e9d(%rip),%rax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%edi
lea    (%rdi,%rdi,1),%ecx
or     (%rax),%edi
or     %ecx,%edi
call   1030 <mlockall@plt>
test   %rax,%rax
jne    1166 <test_mlockall+0x36>
xor    %edi,%edi
call   *%rbx
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <munlockall@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe93(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [9 x i8] c"mlockall\00"
define i32 @test_mlockall(i32 (i32)* %0) {
%2 = alloca i32
%3 = alloca i32 (i32)*
%4 = alloca i32
store i32 (i32)* %0, i32 (i32)** %3
store i32 1, i32* %4
%5 = load i32, i32* @MCL_CURRENT
%6 = load i32, i32* @MCL_FUTURE
%7 = shl i32 %6, 1
%8 = or i32 %5, %7
%9 = load i32, i32* @MCL_FUTURE
%10 = or i32 %8, %9
%11 = call i64 @mlockall(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %21
16: ; preds = %1
%17 = load i32 (i32)*, i32 (i32)** %3
%18 = call i32 %17(i32 0)
store i32 %18, i32* %4
%19 = call i32 (...) @munlockall()
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %21
21: ; preds = %16, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@.str = [9 x i8] c"mlockall\00"
define i32 @test_mlockall(i32 (i32)* nocapture %0) {
%2 = load i32, i32* @MCL_CURRENT
%3 = load i32, i32* @MCL_FUTURE
%4 = shl i32 %3, 1
%5 = or i32 %3, %2
%6 = or i32 %5, %4
%7 = tail call i64 @mlockall(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %14
11: ; preds = %1
%12 = tail call i32 %0(i32 0)
%13 = tail call i32 (...) @munlockall()
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ 1, %9 ], [ %12, %11 ]
ret i32 %15
}