// File: zimpha[P]MiniSQL/indexManager.cc
// Function: BT::insertParent(std::map<long, long, std::less<long>, std::allocator<std::pair<long const, long>>>&, BTNode, element const&, BTNode)
void insertParent(map <long, long> &parent, BTNode p, const element &e, BTNode q) {
        if (p.isRoot) {
            BTNode w = newNode();
            w.n = 1;
            w.isRoot = true;
            //setRoot(name, bfm, w.offset);
            w.value[0] = e;
            w.ch[0] = p.offset;
            w.ch[1] = q.offset;
            save(w);
            return;
        }
        auto go = [&] (long off) { return blockToNode(*(bfm->BufferManagerRead(name, off))); };
        BTNode f = go(parent[p.offset]);
        if (f.n < SZ - 1) {
            int i = 0;
            while (i < f.n && p.offset != f.ch[i]) i++;
            for (int j = f.n + 1; j > i + 1; j--) {
                f.ch[j] = f.ch[j - 1];
                f.value[j - 1] = f.value[j - 2];
            }
            f.ch[i + 1] = q.offset;
            f.value[i] = q.value[0];
            save(f);
        } else { //split
            vector <element> ele(f.value, f.value + f.n);
            vector <long> off(f.offset, f.offset + f.n + 1);
            int i = 0;
            while (off[i] != p.offset) i++;
            off.insert(off.begin() + i + 1, q.offset);
            ele.insert(ele.begin() + i, e);
            int m = (SZ + 1) / 2;
            BTNode w = newNode();
            f.n = m - 1;
            w.n = ele.size() - m;
            for (i = 0; i < m - 1; i++) {
                f.value[i] = ele[i];
                f.ch[i] = off[i];
            }
            f.ch[m - 1] = off[m - 1];
            element cur = ele[m - 1];
            for (i = m; i < ele.size(); i++) {
                w.value[i] = ele[i];
                w.ch[i] = off[i];
            }
            w.ch[w.n] = off.back();
            save(w);
            save(f);
            insertParent(parent, f, cur, w);
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8fd0, %rsp           # imm = 0x8FD0
movq %rsi, -0x8f68(%rbp)
movq %rcx, -0x8f60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
testb $0x1, 0x1(%rsi)
je 0x124ab
leaq -0xff0(%rbp), %rdi
callq 0x121f0
movl $0x1, -0xfec(%rbp)
movb $0x1, -0xfef(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xda0(%rbp), %rdi
callq 0x14f30
jmp 0x12432
movq -0x8f60(%rbp), %rax
movq -0x8f68(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, -0xfe0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xfd8(%rbp)
leaq -0x1fd0(%rbp), %rdi
leaq -0xff0(%rbp), %rsi
callq 0x12340
jmp 0x1246b
leaq -0x1fd0(%rbp), %rdi
callq 0x14ee0
leaq -0xff0(%rbp), %rdi
callq 0x14ee0
jmp 0x12c3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
leaq -0xff0(%rbp), %rdi
callq 0x14ee0
jmp 0x12c52
movq -0x8f68(%rbp), %rsi
movq -0x8(%rbp), %rdi
addq $0x8, %rsi
callq 0x14f80
movq (%rax), %rdx
leaq -0x2fa8(%rbp), %rdi
leaq -0x1fd1(%rbp), %rsi
callq 0x12c60
cmpl $0x46, -0x2fa4(%rbp)
jge 0x12651
movl $0x0, -0x2fac(%rbp)
movl -0x2fac(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2fa4(%rbp), %ecx
movb %al, -0x8f69(%rbp)
jge 0x12525
movq -0x8f68(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2fac(%rbp), %rcx
cmpq -0x2f98(%rbp,%rcx,8), %rax
setne %al
movb %al, -0x8f69(%rbp)
movb -0x8f69(%rbp), %al
testb $0x1, %al
jne 0x12531
jmp 0x12542
movl -0x2fac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2fac(%rbp)
jmp 0x124ec
movl -0x2fa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2fb0(%rbp)
movl -0x2fb0(%rbp), %eax
movl -0x2fac(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x125ec
movslq -0x2fb0(%rbp), %rax
movl %eax, %ecx
decl %ecx
movslq %ecx, %rcx
movq -0x2f98(%rbp,%rcx,8), %rcx
movq %rcx, -0x2f98(%rbp,%rax,8)
movl -0x2fb0(%rbp), %eax
movl %eax, %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq -0x2d58(%rbp,%rcx), %rsi
decl %eax
cltq
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x2d58(%rbp,%rax), %rdi
callq 0x14f30
jmp 0x125bf
jmp 0x125c1
movl -0x2fb0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2fb0(%rbp)
jmp 0x12551
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
jmp 0x12c46
movq -0x8f60(%rbp), %rsi
movq 0x8(%rsi), %rcx
movslq -0x2fac(%rbp), %rax
movq %rcx, -0x2f90(%rbp,%rax,8)
addq $0x250, %rsi            # imm = 0x250
movslq -0x2fac(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x2d58(%rbp,%rax), %rdi
callq 0x14f30
jmp 0x1262b
leaq -0x3f80(%rbp), %rdi
leaq -0x2fa8(%rbp), %rsi
callq 0x12340
jmp 0x12640
leaq -0x3f80(%rbp), %rdi
callq 0x14ee0
jmp 0x12c31
leaq -0x2d58(%rbp), %rax
movq %rax, -0x8f88(%rbp)
movslq -0x2fa4(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x2d58(%rbp,%rax), %rax
movq %rax, -0x8f80(%rbp)
leaq -0x3f99(%rbp), %rdi
movq %rdi, -0x8f78(%rbp)
callq 0x15060
movq -0x8f88(%rbp), %rsi
movq -0x8f80(%rbp), %rdx
movq -0x8f78(%rbp), %rcx
leaq -0x3f98(%rbp), %rdi
callq 0x15080
jmp 0x126b3
leaq -0x3f99(%rbp), %rdi
callq 0xe050
movq -0x2fa0(%rbp), %rax
movq %rax, -0x8f98(%rbp)
movslq -0x2fa4(%rbp), %rcx
leaq 0x1(%rax,%rcx), %rax
movq %rax, -0x3fc0(%rbp)
leaq -0x3fc1(%rbp), %rdi
movq %rdi, -0x8f90(%rbp)
callq 0x7ce0
movq -0x8f98(%rbp), %rsi
movq -0x8f90(%rbp), %rcx
leaq -0x3fb8(%rbp), %rdi
leaq -0x3fc0(%rbp), %rdx
callq 0x15100
jmp 0x12716
leaq -0x3fc1(%rbp), %rdi
callq 0x7d70
movl $0x0, -0x3fc8(%rbp)
movslq -0x3fc8(%rbp), %rsi
leaq -0x3fb8(%rbp), %rdi
callq 0x15180
movq -0x8f68(%rbp), %rcx
movq (%rax), %rax
cmpq 0x8(%rcx), %rax
je 0x127a6
movl -0x3fc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3fc8(%rbp)
jmp 0x1272c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
leaq -0x3f99(%rbp), %rdi
callq 0xe050
jmp 0x12c46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
leaq -0x3fc1(%rbp), %rdi
callq 0x7d70
jmp 0x12c23
leaq -0x3fb8(%rbp), %rdi
movq %rdi, -0x8fa8(%rbp)
callq 0x7e60
movq %rax, -0x3fe8(%rbp)
movslq -0x3fc8(%rbp), %rsi
leaq -0x3fe8(%rbp), %rdi
callq 0x153a0
movq %rax, -0x3fe0(%rbp)
leaq -0x3fe0(%rbp), %rdi
movl $0x1, %esi
callq 0x153a0
movq %rax, -0x3fd8(%rbp)
leaq -0x3fd0(%rbp), %rdi
leaq -0x3fd8(%rbp), %rsi
callq 0x153e0
movq -0x8f60(%rbp), %rdx
movq -0x8fa8(%rbp), %rdi
addq $0x8, %rdx
movq -0x3fd0(%rbp), %rsi
callq 0x151a0
movq %rax, -0x8fa0(%rbp)
jmp 0x1282c
movq -0x8fa0(%rbp), %rax
movq %rax, -0x3ff0(%rbp)
leaq -0x3f98(%rbp), %rdi
movq %rdi, -0x8fb8(%rbp)
callq 0x15630
movq %rax, -0x4008(%rbp)
movslq -0x3fc8(%rbp), %rsi
leaq -0x4008(%rbp), %rdi
callq 0x15660
movq %rax, -0x4000(%rbp)
leaq -0x3ff8(%rbp), %rdi
leaq -0x4000(%rbp), %rsi
callq 0x156a0
movq -0x8fb8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x3ff8(%rbp), %rsi
callq 0x15420
movq %rax, -0x8fb0(%rbp)
jmp 0x128a1
movq -0x8fb0(%rbp), %rax
movq %rax, -0x4010(%rbp)
movl $0x24, -0x4014(%rbp)
leaq -0x4fe8(%rbp), %rdi
callq 0x121f0
jmp 0x128c7
movl -0x4014(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2fa4(%rbp)
leaq -0x3f98(%rbp), %rdi
callq 0x8230
movslq -0x4014(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4fe4(%rbp)
movl $0x0, -0x3fc8(%rbp)
movl -0x3fc8(%rbp), %eax
movl -0x4014(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x129ae
movslq -0x3fc8(%rbp), %rsi
leaq -0x3f98(%rbp), %rdi
callq 0x14b40
movq %rax, %rsi
movslq -0x3fc8(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x2d58(%rbp,%rax), %rdi
callq 0x14f30
jmp 0x12947
movslq -0x3fc8(%rbp), %rsi
leaq -0x3fb8(%rbp), %rdi
callq 0x15180
movq (%rax), %rcx
movslq -0x3fc8(%rbp), %rax
movq %rcx, -0x2f98(%rbp,%rax,8)
movl -0x3fc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3fc8(%rbp)
jmp 0x128fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
jmp 0x12c17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
jmp 0x12c0b
movl -0x4014(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x3fb8(%rbp), %rdi
callq 0x15180
movq (%rax), %rcx
movl -0x4014(%rbp), %eax
decl %eax
cltq
movq %rcx, -0x2f98(%rbp,%rax,8)
movl -0x4014(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x3f98(%rbp), %rdi
callq 0x14b40
movq %rax, %rsi
leaq -0x5018(%rbp), %rdi
callq 0x7aa0
jmp 0x12a02
movl -0x4014(%rbp), %eax
movl %eax, -0x3fc8(%rbp)
movslq -0x3fc8(%rbp), %rax
movq %rax, -0x8fc0(%rbp)
leaq -0x3f98(%rbp), %rdi
callq 0x8230
movq %rax, %rcx
movq -0x8fc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x12abf
movslq -0x3fc8(%rbp), %rsi
leaq -0x3f98(%rbp), %rdi
callq 0x14b40
movq %rax, %rsi
movslq -0x3fc8(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x4d98(%rbp,%rax), %rdi
callq 0x14f30
jmp 0x12a6f
movslq -0x3fc8(%rbp), %rsi
leaq -0x3fb8(%rbp), %rdi
callq 0x15180
movq (%rax), %rcx
movslq -0x3fc8(%rbp), %rax
movq %rcx, -0x4fd8(%rbp,%rax,8)
movl -0x3fc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3fc8(%rbp)
jmp 0x12a0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
jmp 0x12bff
leaq -0x3fb8(%rbp), %rdi
callq 0x156e0
movq (%rax), %rcx
movslq -0x4fe4(%rbp), %rax
movq %rcx, -0x4fd8(%rbp,%rax,8)
leaq -0x5fe8(%rbp), %rdi
leaq -0x4fe8(%rbp), %rsi
callq 0x12340
jmp 0x12af2
leaq -0x5fe8(%rbp), %rdi
callq 0x14ee0
leaq -0x6fb8(%rbp), %rdi
leaq -0x2fa8(%rbp), %rsi
callq 0x12340
jmp 0x12b13
leaq -0x6fb8(%rbp), %rdi
callq 0x14ee0
movq -0x8(%rbp), %rax
movq %rax, -0x8fc8(%rbp)
leaq -0x7f88(%rbp), %rdi
leaq -0x2fa8(%rbp), %rsi
callq 0x15720
jmp 0x12b3f
leaq -0x8f58(%rbp), %rdi
leaq -0x4fe8(%rbp), %rsi
callq 0x15720
jmp 0x12b54
movq -0x8fc8(%rbp), %rdi
leaq -0x7f88(%rbp), %rsi
leaq -0x5018(%rbp), %rdx
leaq -0x8f58(%rbp), %rcx
callq 0x123d0
jmp 0x12b77
leaq -0x8f58(%rbp), %rdi
callq 0x14ee0
leaq -0x7f88(%rbp), %rdi
callq 0x14ee0
leaq -0x5018(%rbp), %rdi
callq 0x7af0
leaq -0x4fe8(%rbp), %rdi
callq 0x14ee0
leaq -0x3fb8(%rbp), %rdi
callq 0x7f30
leaq -0x3f98(%rbp), %rdi
callq 0xb6d0
jmp 0x12c31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
jmp 0x12bf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xff8(%rbp)
movl %eax, -0xffc(%rbp)
leaq -0x8f58(%rbp), %rdi
callq 0x14ee0
leaq -0x7f88(%rbp), %rdi
callq 0x14ee0
leaq -0x5018(%rbp), %rdi
callq 0x7af0
leaq -0x4fe8(%rbp), %rdi
callq 0x14ee0
leaq -0x3fb8(%rbp), %rdi
callq 0x7f30
leaq -0x3f98(%rbp), %rdi
callq 0xb6d0
jmp 0x12c46
leaq -0x2fa8(%rbp), %rdi
callq 0x14ee0
addq $0x8fd0, %rsp           # imm = 0x8FD0
popq %rbp
retq
leaq -0x2fa8(%rbp), %rdi
callq 0x14ee0
movq -0xff8(%rbp), %rdi
callq 0x34f0
nop