#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 */
long long scm_page_col(long long);
long long scm_page_index(long long, long long, long long, long long);
long long scm_page_level(long long);
long long scm_page_root(long long);
long long scm_page_row(long long);
long long scm_page_east(long long i) {
  long long l = scm_page_level(i);
  long long f = scm_page_root(i);
  long long r = scm_page_row(i);
  long long c = scm_page_col(i);
  long long n = 1LL << l, m = n - 1, t = m - r;
  if (c < m) {
    c = c + 1;
  } else if (f == 0) {
    f = 5;
    c = 0;
  } else if (f == 1) {
    f = 4;
    c = 0;
  } else if (f == 2) {
    f = 0;
    c = t;
    r = 0;
  } else if (f == 3) {
    f = 0;
    c = r;
    r = m;
  } else if (f == 4) {
    f = 0;
    c = 0;
  } else {
    f = 1;
    c = 0;
  }
  return scm_page_index(f, l, r, c);
}


x86 assembly (clang, -O0):
<scm_page_east>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <scm_page_level@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <scm_page_root@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <scm_page_row@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <scm_page_col@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rcx
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    11d7 <scm_page_east+0x87>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12b0 <scm_page_east+0x160>
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <scm_page_east+0xa7>
movq   $0x5,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    12ab <scm_page_east+0x15b>
cmpq   $0x1,-0x18(%rbp)
jne    1217 <scm_page_east+0xc7>
movq   $0x4,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    12a6 <scm_page_east+0x156>
cmpq   $0x2,-0x18(%rbp)
jne    123f <scm_page_east+0xef>
movq   $0x0,-0x18(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
jmp    12a1 <scm_page_east+0x151>
cmpq   $0x3,-0x18(%rbp)
jne    1267 <scm_page_east+0x117>
movq   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    129c <scm_page_east+0x14c>
cmpq   $0x4,-0x18(%rbp)
jne    1287 <scm_page_east+0x137>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    1297 <scm_page_east+0x147>
movq   $0x1,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    129c <scm_page_east+0x14c>
jmp    12a1 <scm_page_east+0x151>
jmp    12a6 <scm_page_east+0x156>
jmp    12ab <scm_page_east+0x15b>
jmp    12b0 <scm_page_east+0x160>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <scm_page_index@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scm_page_east>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <scm_page_level@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <scm_page_root@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <scm_page_row@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <scm_page_col@plt>
mov    $0xffffffffffffffff,%rdx
mov    %r15d,%ecx
shl    %cl,%rdx
not    %rdx
cmp    %rdx,%rax
jge    119c <scm_page_east+0x4c>
add    $0x1,%rax
jmp    11e8 <scm_page_east+0x98>
cmp    $0x4,%r12
ja     11c3 <scm_page_east+0x73>
lea    0xe57(%rip),%rax
movslq (%rax,%r12,4),%rcx
add    %rax,%rcx
mov    %r12,%rax
mov    $0x5,%r12d
jmp    *%rcx
mov    $0x4,%r12d
jmp    11c9 <scm_page_east+0x79>
mov    $0x1,%r12d
xor    %eax,%eax
jmp    11e8 <scm_page_east+0x98>
sub    %r14,%rdx
xor    %r14d,%r14d
mov    %rdx,%rax
jmp    11e5 <scm_page_east+0x95>
xor    %r12d,%r12d
mov    %r14,%rax
mov    %rdx,%r14
jmp    11e8 <scm_page_east+0x98>
xor    %eax,%eax
xor    %r12d,%r12d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <scm_page_index@plt>

LLVM IR (-O0):
define i64 @scm_page_east(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %2
%10 = load i64, i64* %2
%11 = call i64 @scm_page_level(i64 %10)
store i64 %11, i64* %3
%12 = load i64, i64* %2
%13 = call i64 @scm_page_root(i64 %12)
store i64 %13, i64* %4
%14 = load i64, i64* %2
%15 = call i64 @scm_page_row(i64 %14)
store i64 %15, i64* %5
%16 = load i64, i64* %2
%17 = call i64 @scm_page_col(i64 %16)
store i64 %17, i64* %6
%18 = load i64, i64* %3
%19 = shl i64 1, %18
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = sub nsw i64 %20, 1
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = load i64, i64* %5
%24 = sub nsw i64 %22, %23
store i64 %24, i64* %9
%25 = load i64, i64* %6
%26 = load i64, i64* %8
%27 = icmp slt i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %1
%29 = load i64, i64* %6
%30 = add nsw i64 %29, 1
store i64 %30, i64* %6
br label %60
31: ; preds = %1
%32 = load i64, i64* %4
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i64 5, i64* %4
store i64 0, i64* %6
br label %59
35: ; preds = %31
%36 = load i64, i64* %4
%37 = icmp eq i64 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %35
store i64 4, i64* %4
store i64 0, i64* %6
br label %58
39: ; preds = %35
%40 = load i64, i64* %4
%41 = icmp eq i64 %40, 2
br i1 %41, label %42, label %44
42: ; preds = %39
store i64 0, i64* %4
%43 = load i64, i64* %9
store i64 %43, i64* %6
store i64 0, i64* %5
br label %57
44: ; preds = %39
%45 = load i64, i64* %4
%46 = icmp eq i64 %45, 3
br i1 %46, label %47, label %50
47: ; preds = %44
store i64 0, i64* %4
%48 = load i64, i64* %5
store i64 %48, i64* %6
%49 = load i64, i64* %8
store i64 %49, i64* %5
br label %56
50: ; preds = %44
%51 = load i64, i64* %4
%52 = icmp eq i64 %51, 4
br i1 %52, label %53, label %54
53: ; preds = %50
store i64 0, i64* %4
store i64 0, i64* %6
br label %55
54: ; preds = %50
store i64 1, i64* %4
store i64 0, i64* %6
br label %55
55: ; preds = %54, %53
br label %56
56: ; preds = %55, %47
br label %57
57: ; preds = %56, %42
br label %58
58: ; preds = %57, %38
br label %59
59: ; preds = %58, %34
br label %60
60: ; preds = %59, %28
%61 = load i64, i64* %4
%62 = load i64, i64* %3
%63 = load i64, i64* %5
%64 = load i64, i64* %6
%65 = call i64 @scm_page_index(i64 %61, i64 %62, i64 %63, i64 %64)
ret i64 %65
}

LLVM IR (-O2):
define i64 @scm_page_east(i64 %0) {
%2 = tail call i64 @scm_page_level(i64 %0)
%3 = tail call i64 @scm_page_root(i64 %0)
%4 = tail call i64 @scm_page_row(i64 %0)
%5 = tail call i64 @scm_page_col(i64 %0)
%6 = shl nsw i64 -1, %2
%7 = xor i64 %6, -1
%8 = sub nsw i64 %7, %4
%9 = icmp slt i64 %5, %7
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = add nsw i64 %5, 1
br label %18
12: ; preds = %1
switch i64 %3, label %17 [
i64 0, label %18
i64 1, label %13
i64 2, label %14
i64 3, label %15
i64 4, label %16
]
13: ; preds = %12
br label %18
14: ; preds = %12
br label %18
15: ; preds = %12
br label %18
16: ; preds = %12
br label %18
17: ; preds = %12
br label %18
18: ; preds = %12, %14, %16, %17, %15, %13, %10
%19 = phi i64 [ %11, %10 ], [ 0, %13 ], [ %8, %14 ], [ %4, %15 ], [ 0, %16 ], [ 0, %17 ], [ %3, %12 ]
%20 = phi i64 [ %4, %10 ], [ %4, %13 ], [ 0, %14 ], [ %7, %15 ], [ %4, %16 ], [ %4, %17 ], [ %4, %12 ]
%21 = phi i64 [ %3, %10 ], [ 4, %13 ], [ 0, %14 ], [ 0, %15 ], [ 0, %16 ], [ 1, %17 ], [ 5, %12 ]
%22 = tail call i64 @scm_page_index(i64 %21, i64 %2, i64 %20, i64 %19)
ret i64 %22
}