#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 /*<<< orphan*/ cleanup();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free_hugepage_region(void *);
scalar_t__ mincore(void *, int, unsigned char *);
int /*<<< orphan*/ printf(char *, int);
void free_and_confirm_region_free(void *p, int line) {
  unsigned char vec = 0;
  free_hugepage_region(p);
  if (mincore(p, 4, &vec) == 0 || vec)
    do {
      cleanup();
      printf("FAIL\t"
             "free_hugepage_region did not free region at line %d"
             "\n",
             line);
      exit(2);
    } while (0);
}


x86 assembly (clang, -O0):
<free_and_confirm_region_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free_hugepage_region@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
lea    -0xd(%rbp),%rdx
call   1050 <mincore@plt>
cmp    $0x0,%rax
je     1195 <free_and_confirm_region_free+0x45>
movzbl -0xd(%rbp),%eax
cmp    $0x0,%eax
je     11ba <free_and_confirm_region_free+0x6a>
jmp    119a <free_and_confirm_region_free+0x4a>
mov    $0x0,%al
call   1060 <cleanup@plt>
mov    -0xc(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<free_and_confirm_region_free>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movb   $0x0,0x7(%rsp)
call   1030 <free_hugepage_region@plt>
lea    0x7(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <mincore@plt>
test   %rax,%rax
je     1187 <free_and_confirm_region_free+0x37>
cmpb   $0x0,0x7(%rsp)
jne    1187 <free_and_confirm_region_free+0x37>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1060 <cleanup@plt>
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [58 x i8] c"FAIL\09free_hugepage_region did not free region at line %d\0A\00"
define void @free_and_confirm_region_free(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* %5
%6 = load i8*, i8** %3
%7 = call i32 @free_hugepage_region(i8* %6)
%8 = load i8*, i8** %3
%9 = call i64 @mincore(i8* %8, i32 4, i8* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8, i8* %5
%13 = zext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %11, %2
br label %16
16: ; preds = %15
%17 = call i32 (...) @cleanup()
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %11
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"FAIL\09free_hugepage_region did not free region at line %d\0A\00"
define void @free_and_confirm_region_free(i8* %0, i32 %1) {
%3 = alloca i8
store i8 0, i8* %3
%4 = tail call i32 @free_hugepage_region(i8* %0)
%5 = call i64 @mincore(i8* %0, i32 4, i8* %3)
%6 = icmp eq i64 %5, 0
%7 = load i8, i8* %3
%8 = icmp ne i8 %7, 0
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (...) @cleanup()
%12 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %1)
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %2
ret void
}