#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 */
typedef int val;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
void test(unsigned val) {
  printf("pageStart(0x%x)      = 0x%x\n", val, ((((val) >> (12)) << (12))));
  printf("firstPageAfter(0x%x) = 0x%x\n", val,
         (val % 0x1000 == 0 ? val : (0x1000 + ((((val) >> (12)) << (12))))));
  printf("endPageBefore(0x%x)  = 0x%x\n", val,
         (((val) & ((1 << (12)) - 1)) == 0xfff
              ? val
              : ((((val) >> (12)) << (12))) - 1));
  printf("pageEnd(0x%x)        = 0x%x\n", val,
         (((((val) >> (12)) << (12))) | 0x0fff));
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
shr    $0xc,%edx
shl    $0xc,%edx
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xfff,%eax
cmp    $0x0,%eax
jne    1155 <test+0x45>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <test+0x56>
mov    -0x4(%rbp),%eax
shr    $0xc,%eax
shl    $0xc,%eax
add    $0x1000,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xfff,%eax
cmp    $0xfff,%eax
jne    119c <test+0x8c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ab <test+0x9b>
mov    -0x4(%rbp),%eax
shr    $0xc,%eax
shl    $0xc,%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
shr    $0xc,%edx
shl    $0xc,%edx
or     $0xfff,%edx
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    %edi,%ebx
and    $0xfffff000,%ebx
lea    0xedb(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %ebp,%r14d
and    $0xfff,%r14d
lea    0x1000(%rbx),%edx
test   %r14d,%r14d
cmove  %ebp,%edx
lea    0xed2(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0xffffffff,%ebx
cmp    $0xfff,%r14d
cmove  %ebp,%ebx
lea    0xed4(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %ebp,%edx
or     $0xfff,%edx
lea    0xed9(%rip),%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"pageStart(0x%x) = 0x%x\0A\00"
@.str.1 = [29 x i8] c"firstPageAfter(0x%x) = 0x%x\0A\00"
@.str.2 = [29 x i8] c"endPageBefore(0x%x) = 0x%x\0A\00"
@.str.3 = [29 x i8] c"pageEnd(0x%x) = 0x%x\0A\00"
define void @test(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* %2
%5 = lshr i32 %4, 12
%6 = shl i32 %5, 12
%7 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = urem i32 %9, 4096
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* %2
br label %19
14: ; preds = %1
%15 = load i32, i32* %2
%16 = lshr i32 %15, 12
%17 = shl i32 %16, 12
%18 = add i32 4096, %17
br label %19
19: ; preds = %14, %12
%20 = phi i32 [ %13, %12 ], [ %18, %14 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %20)
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = and i32 %23, 4095
%25 = icmp eq i32 %24, 4095
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i32, i32* %2
br label %33
28: ; preds = %19
%29 = load i32, i32* %2
%30 = lshr i32 %29, 12
%31 = shl i32 %30, 12
%32 = sub i32 %31, 1
br label %33
33: ; preds = %28, %26
%34 = phi i32 [ %27, %26 ], [ %32, %28 ]
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %34)
%36 = load i32, i32* %2
%37 = load i32, i32* %2
%38 = lshr i32 %37, 12
%39 = shl i32 %38, 12
%40 = or i32 %39, 4095
%41 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %40)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"pageStart(0x%x) = 0x%x\0A\00"
@.str.1 = [29 x i8] c"firstPageAfter(0x%x) = 0x%x\0A\00"
@.str.2 = [29 x i8] c"endPageBefore(0x%x) = 0x%x\0A\00"
@.str.3 = [29 x i8] c"pageEnd(0x%x) = 0x%x\0A\00"
define void @test(i32 %0) {
%2 = and i32 %0, -4096
%3 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2)
%4 = and i32 %0, 4095
%5 = icmp eq i32 %4, 0
%6 = add i32 %2, 4096
%7 = select i1 %5, i32 %0, i32 %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %7)
%9 = icmp eq i32 %4, 4095
%10 = add i32 %2, -1
%11 = select i1 %9, i32 %0, i32 %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %11)
%13 = or i32 %0, 4095
%14 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %13)
ret void
}