#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*/ _SC_PAGESIZE;
int /*<<< orphan*/ maybe_err(char *, ...);
size_t sysconf(int /*<<< orphan*/);
void assert_buffer_valid(const char *what, long addr) {
  static size_t pagesize = 0;
  if (!pagesize)
    pagesize = sysconf(_SC_PAGESIZE);
  if (addr < pagesize)
    maybe_err("Buffer address strange: 0x%08lx", addr);
  long leftovers = addr & (pagesize - 1);
  if (leftovers > 0)
    maybe_err("Buffer passed to '%s' is not on a page boundary: 0x%08lx "
              "(leftover is 0x%08lx)",
              what, addr, leftovers);
}


x86 assembly (clang, -O0):
<assert_buffer_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,0x2f00(%rip)
jne    1153 <assert_buffer_valid+0x33>
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1030 <sysconf@plt>
mov    %rax,0x2ee5(%rip)
mov    -0x10(%rbp),%rax
cmp    0x2eda(%rip),%rax
jae    1176 <assert_buffer_valid+0x56>
mov    -0x10(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <maybe_err@plt>
mov    -0x10(%rbp),%rax
mov    0x2eb7(%rip),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11b1 <assert_buffer_valid+0x91>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <maybe_err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assert_buffer_valid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2f07(%rip),%rcx
test   %rcx,%rcx
je     1177 <assert_buffer_valid+0x57>
cmp    %rbx,%rcx
jbe    1153 <assert_buffer_valid+0x33>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <maybe_err@plt>
mov    0x2ee5(%rip),%rcx
add    $0xffffffffffffffff,%rcx
and    %rbx,%rcx
jle    1196 <assert_buffer_valid+0x76>
lea    0xebd(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <maybe_err@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1030 <sysconf@plt>
mov    %rax,%rcx
mov    %rax,0x2ea9(%rip)
cmp    %rbx,%rcx
ja     113b <assert_buffer_valid+0x1b>
jmp    1153 <assert_buffer_valid+0x33>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@assert_buffer_valid.pagesize = internal global i64 0
@_SC_PAGESIZE = global i32 0
@.str = [32 x i8] c"Buffer address strange: 0x%08lx\00"
@.str.1 = [79 x i8] c"Buffer passed to '%s' is not on a page boundary: 0x%08lx (leftover is 0x%08lx)\00"
define void @assert_buffer_valid(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* @assert_buffer_valid.pagesize
%7 = icmp ne i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @_SC_PAGESIZE
%10 = call i64 @sysconf(i32 %9)
store i64 %10, i64* @assert_buffer_valid.pagesize
br label %11
11: ; preds = %8, %2
%12 = load i64, i64* %4
%13 = load i64, i64* @assert_buffer_valid.pagesize
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i64, i64* %4
%17 = call i32 (i8*, ...) @maybe_err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %16)
br label %18
18: ; preds = %15, %11
%19 = load i64, i64* %4
%20 = load i64, i64* @assert_buffer_valid.pagesize
%21 = sub i64 %20, 1
%22 = and i64 %19, %21
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8*, i8** %3
%27 = load i64, i64* %4
%28 = load i64, i64* %5
%29 = call i32 (i8*, ...) @maybe_err(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %26, i64 %27, i64 %28)
br label %30
30: ; preds = %25, %18
ret void
}

LLVM IR (-O2):
@assert_buffer_valid.pagesize = internal unnamed_addr global i64 0
@_SC_PAGESIZE = global i32 0
@.str = [32 x i8] c"Buffer address strange: 0x%08lx\00"
@.str.1 = [79 x i8] c"Buffer passed to '%s' is not on a page boundary: 0x%08lx (leftover is 0x%08lx)\00"
define void @assert_buffer_valid(i8* %0, i64 %1) {
%3 = load i64, i64* @assert_buffer_valid.pagesize
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @_SC_PAGESIZE
%7 = tail call i64 @sysconf(i32 %6)
store i64 %7, i64* @assert_buffer_valid.pagesize
br label %8
8: ; preds = %5, %2
%9 = phi i64 [ %7, %5 ], [ %3, %2 ]
%10 = icmp ugt i64 %9, %1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @maybe_err(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %1)
%13 = load i64, i64* @assert_buffer_valid.pagesize
br label %14
14: ; preds = %11, %8
%15 = phi i64 [ %13, %11 ], [ %9, %8 ]
%16 = add i64 %15, -1
%17 = and i64 %16, %1
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @maybe_err(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %1, i64 %17)
br label %21
21: ; preds = %19, %14
ret void
}