// File: /workspace/github_cpp_makefile_star2_O1/JainamS1996[P]Btree_DataStructure/final.cpp
// Function: insertNode(Node*, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void insertNode(Node *curNode, double k,string val) {
    if (curNode->isleaf) {
		//cout << "leaf root insert" << endl;
		
		curNode->record.push_back(make_tuple(k,val));
        sort(curNode->record.begin(),curNode->record.end());
		
        curNode->nNodes++;

        //for (int i = 0; i<curNode->record.size();i++) cout<<get<0>(curNode->record.at(i)) << " ";
		//cout << endl;

        if (curNode->record.size() > order-1) {
			//cout << "leaf split" << endl;			
            curNode->nNodes--;
            splitNode(curNode);
        }

		//cout << "leaf root had space" << endl;
    }
    else {
        int flag = 0;
        for (int i = 0; i<curNode->keys.size();i++) {
            if (k < curNode->keys.at(i)) {
                flag = 1;
                insertNode(curNode->children.at(i),k,val);
                break;
            }
        }
        if (flag == 0) {
            insertNode(curNode->children.at(curNode->children.size()-1),k,val);        
        }
        
        // sort(curNode->keys.begin(),curNode->keys.end());
        // if (curNode->keys.size()>order-1) {
        //     curNode->nNodes--;
        //     cout<<"Split karte hai bhai log";
        //     splitNode(curNode);
        
    }
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rdi, %rbx
cmpb $0x0, 0x88(%rdi)
movsd %xmm0, -0x28(%rbp)
je 0x2e89
leaq 0x40(%rbx), %r14
leaq -0x80(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x90(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x440e
movsd -0x28(%rbp), %xmm0
movsd %xmm0, 0x20(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5344
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2e05
callq 0x2180
movq 0x40(%rbx), %r14
movq 0x48(%rbx), %r15
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
cmpq %r15, %r14
je 0x2e4d
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
imulq %r12, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x558e
movq %r14, %rdi
movq %r15, %rsi
callq 0x566c
movl 0x20(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq 0x48(%rbx), %rcx
subq 0x40(%rbx), %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
movslq 0x7323(%rip), %rdx      # 0xa190
decq %rdx
cmpq %rdx, %rcx
jbe 0x2f65
movl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x2532
jmp 0x2f65
movq 0x58(%rbx), %rcx
movq 0x60(%rbx), %rdx
subq %rcx, %rdx
je 0x2eb7
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %eax, %eax
movsd (%rcx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x2f0e
incq %rax
cmpq %rax, %rdx
jne 0x2ea4
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rax, %rcx
je 0x2f72
movq -0x8(%rax,%rdx,8), %rbx
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x440e
movq %rbx, %rdi
movsd -0x28(%rbp), %xmm0
movq %r14, %rsi
callq 0x2d91
movq -0x48(%rbp), %rdi
jmp 0x2f5b
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x2f7f
movq (%rcx,%rax,8), %rbx
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x440e
movq %rbx, %rdi
movsd -0x28(%rbp), %xmm0
movq %r14, %rsi
callq 0x2d91
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x2f65
callq 0x2180
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1(%rdx), %rsi
leaq 0x40f8(%rip), %rdi      # 0x7075
jmp 0x2f89
leaq 0x40ef(%rip), %rdi      # 0x7075
movq %rax, %rsi
xorl %eax, %eax
callq 0x2250
movq %rax, %rbx
movq -0x68(%rbp), %rdi
jmp 0x2fa0
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x2fb6
jmp 0x2fbb
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2fbb
callq 0x2180
movq %rbx, %rdi
callq 0x22c0