#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*/ FAIL_IF(int /*<<< orphan*/);
unsigned long load_unaligned_zeropad(char *);
int /*<<< orphan*/ printf(char *, int, unsigned long, unsigned long);
int /*<<< orphan*/ protect_region();
int /*<<< orphan*/ unprotect_region();
int do_one_test(char *p, int page_offset) {
  unsigned long should;
  unsigned long got;
  FAIL_IF(unprotect_region());
  should = *(unsigned long *)p;
  FAIL_IF(protect_region());
  got = load_unaligned_zeropad(p);
  if (should != got) {
    printf("offset %u load_unaligned_zeropad returned 0x%lx, should be 0x%lx\n",
           page_offset, got, should);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_one_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1050 <unprotect_region@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <protect_region@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    -0x10(%rbp),%rdi
call   1070 <load_unaligned_zeropad@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11c4 <do_one_test+0x74>
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cb <do_one_test+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_one_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <unprotect_region@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    0x0(%rbp),%rbx
xor    %eax,%eax
call   1060 <protect_region@plt>
mov    %eax,%edi
call   1040 <FAIL_IF@plt>
mov    %rbp,%rdi
call   1070 <load_unaligned_zeropad@plt>
cmp    %rax,%rbx
je     11a8 <do_one_test+0x58>
lea    0xe6c(%rip),%rdi
mov    %r14d,%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <printf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"offset %u load_unaligned_zeropad returned 0x%lx, should be 0x%lx\0A\00"
define i32 @do_one_test(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 (...) @unprotect_region()
%9 = call i32 @FAIL_IF(i32 %8)
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i64*
%12 = load i64, i64* %11
store i64 %12, i64* %6
%13 = call i32 (...) @protect_region()
%14 = call i32 @FAIL_IF(i32 %13)
%15 = load i8*, i8** %4
%16 = call i64 @load_unaligned_zeropad(i8* %15)
store i64 %16, i64* %7
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* %5
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %21, i64 %22, i64 %23)
store i32 1, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [66 x i8] c"offset %u load_unaligned_zeropad returned 0x%lx, should be 0x%lx\0A\00"
define i32 @do_one_test(i8* %0, i32 %1) {
%3 = tail call i32 (...) @unprotect_region()
%4 = tail call i32 @FAIL_IF(i32 %3)
%5 = bitcast i8* %0 to i64*
%6 = load i64, i64* %5
%7 = tail call i32 (...) @protect_region()
%8 = tail call i32 @FAIL_IF(i32 %7)
%9 = tail call i64 @load_unaligned_zeropad(i8* %0)
%10 = icmp eq i64 %6, %9
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %1, i64 %9, i64 %6)
br label %13
13: ; preds = %2, %11
%14 = phi i32 [ 1, %11 ], [ 0, %2 ]
ret i32 %14
}