#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_north(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 - c;
  if (r > 0) {
    r = r - 1;
  } else if (f == 0) {
    f = 2;
    r = t;
    c = m;
  } else if (f == 1) {
    f = 2;
    r = c;
    c = 0;
  } else if (f == 2) {
    f = 5;
    r = 0;
    c = t;
  } else if (f == 3) {
    f = 4;
    r = m;
  } else if (f == 4) {
    f = 2;
    r = m;
  } else {
    f = 2;
    r = 0;
    c = t;
  }
  return scm_page_index(f, l, r, c);
}


x86 assembly (clang, -O0):
<scm_page_north>:
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    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11d4 <scm_page_north+0x84>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12bd <scm_page_north+0x16d>
cmpq   $0x0,-0x18(%rbp)
jne    11fc <scm_page_north+0xac>
movq   $0x2,-0x18(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12b8 <scm_page_north+0x168>
cmpq   $0x1,-0x18(%rbp)
jne    1224 <scm_page_north+0xd4>
movq   $0x2,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
jmp    12b3 <scm_page_north+0x163>
cmpq   $0x2,-0x18(%rbp)
jne    124c <scm_page_north+0xfc>
movq   $0x5,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12ae <scm_page_north+0x15e>
cmpq   $0x3,-0x18(%rbp)
jne    126c <scm_page_north+0x11c>
movq   $0x4,-0x18(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12a9 <scm_page_north+0x159>
cmpq   $0x4,-0x18(%rbp)
jne    128c <scm_page_north+0x13c>
movq   $0x2,-0x18(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    12a4 <scm_page_north+0x154>
movq   $0x2,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12a9 <scm_page_north+0x159>
jmp    12ae <scm_page_north+0x15e>
jmp    12b3 <scm_page_north+0x163>
jmp    12b8 <scm_page_north+0x168>
jmp    12bd <scm_page_north+0x16d>
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_north>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <scm_page_level@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <scm_page_root@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <scm_page_row@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1070 <scm_page_col@plt>
mov    $0xffffffffffffffff,%rdx
mov    %r14d,%ecx
shl    %cl,%rdx
test   %r12,%r12
jle    11b3 <scm_page_north+0x63>
add    $0xffffffffffffffff,%r12
mov    %rax,%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <scm_page_index@plt>
not    %rdx
mov    %rdx,%r12
sub    %rax,%r12
mov    $0x2,%edi
cmp    $0x4,%r15
ja     11e6 <scm_page_north+0x96>
lea    0xe32(%rip),%rcx
movslq (%rcx,%r15,4),%rsi
add    %rcx,%rsi
mov    %rdx,%rcx
jmp    *%rsi
xor    %ecx,%ecx
mov    %rax,%r12
jmp    119d <scm_page_north+0x4d>
mov    $0x5,%edi
mov    %r12,%rcx
xor    %r12d,%r12d
jmp    119d <scm_page_north+0x4d>
mov    $0x4,%edi
mov    %rax,%rcx
mov    %rdx,%r12
jmp    119d <scm_page_north+0x4d>

LLVM IR (-O0):
define i64 @scm_page_north(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* %6
%24 = sub nsw i64 %22, %23
store i64 %24, i64* %9
%25 = load i64, i64* %5
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %1
%28 = load i64, i64* %5
%29 = sub nsw i64 %28, 1
store i64 %29, i64* %5
br label %63
30: ; preds = %1
%31 = load i64, i64* %4
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
store i64 2, i64* %4
%34 = load i64, i64* %9
store i64 %34, i64* %5
%35 = load i64, i64* %8
store i64 %35, i64* %6
br label %62
36: ; preds = %30
%37 = load i64, i64* %4
%38 = icmp eq i64 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %36
store i64 2, i64* %4
%40 = load i64, i64* %6
store i64 %40, i64* %5
store i64 0, i64* %6
br label %61
41: ; preds = %36
%42 = load i64, i64* %4
%43 = icmp eq i64 %42, 2
br i1 %43, label %44, label %46
44: ; preds = %41
store i64 5, i64* %4
store i64 0, i64* %5
%45 = load i64, i64* %9
store i64 %45, i64* %6
br label %60
46: ; preds = %41
%47 = load i64, i64* %4
%48 = icmp eq i64 %47, 3
br i1 %48, label %49, label %51
49: ; preds = %46
store i64 4, i64* %4
%50 = load i64, i64* %8
store i64 %50, i64* %5
br label %59
51: ; preds = %46
%52 = load i64, i64* %4
%53 = icmp eq i64 %52, 4
br i1 %53, label %54, label %56
54: ; preds = %51
store i64 2, i64* %4
%55 = load i64, i64* %8
store i64 %55, i64* %5
br label %58
56: ; preds = %51
store i64 2, i64* %4
store i64 0, i64* %5
%57 = load i64, i64* %9
store i64 %57, i64* %6
br label %58
58: ; preds = %56, %54
br label %59
59: ; preds = %58, %49
br label %60
60: ; preds = %59, %44
br label %61
61: ; preds = %60, %39
br label %62
62: ; preds = %61, %33
br label %63
63: ; preds = %62, %27
%64 = load i64, i64* %4
%65 = load i64, i64* %3
%66 = load i64, i64* %5
%67 = load i64, i64* %6
%68 = call i64 @scm_page_index(i64 %64, i64 %65, i64 %66, i64 %67)
ret i64 %68
}

LLVM IR (-O2):
define i64 @scm_page_north(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, %5
%9 = icmp sgt i64 %4, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = add nsw i64 %4, -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 [ %5, %10 ], [ 0, %13 ], [ %8, %14 ], [ %5, %15 ], [ %5, %16 ], [ %8, %17 ], [ %7, %12 ]
%20 = phi i64 [ %11, %10 ], [ %5, %13 ], [ 0, %14 ], [ %7, %15 ], [ %7, %16 ], [ 0, %17 ], [ %8, %12 ]
%21 = phi i64 [ %3, %10 ], [ 2, %13 ], [ 5, %14 ], [ 4, %15 ], [ 2, %16 ], [ 2, %17 ], [ 2, %12 ]
%22 = tail call i64 @scm_page_index(i64 %21, i64 %2, i64 %20, i64 %19)
ret i64 %22
}