// File: /workspace/github_cpp_makefile_star2_O3/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 0x2de0
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 0x42a0
movsd -0x28(%rbp), %xmm0
movsd %xmm0, 0x20(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5172
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2d87
callq 0x2180
movq 0x40(%rbx), %r14
movq 0x48(%rbx), %r15
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
cmpq %r15, %r14
je 0x2e6c
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 0x53bc
movq %r14, %rdi
movq %r15, %rsi
callq 0x549a
movq 0x40(%rbx), %r14
movq 0x48(%rbx), %rax
jmp 0x2e6f
movq 0x58(%rbx), %rcx
movq 0x60(%rbx), %rdx
subq %rcx, %rdx
je 0x2e12
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %eax, %eax
movsd (%rcx,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x2e9f
incq %rax
cmpq %rax, %rdx
jne 0x2dfb
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rax, %rcx
je 0x2f03
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 0x42a0
movq %rbx, %rdi
movsd -0x28(%rbp), %xmm0
movq %r14, %rsi
callq 0x2d13
movq -0x48(%rbp), %rdi
jmp 0x2eec
movq %r14, %rax
subq %r14, %rax
movl 0x20(%rbx), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x20(%rbx)
sarq $0x3, %rax
imulq %r12, %rax
movslq 0x6306(%rip), %rdx      # 0x9190
decq %rdx
cmpq %rdx, %rax
jbe 0x2ef6
movl %ecx, 0x20(%rbx)
movq %rbx, %rdi
callq 0x251c
jmp 0x2ef6
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x2f10
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 0x42a0
movq %rbx, %rdi
movsd -0x28(%rbp), %xmm0
movq %r14, %rsi
callq 0x2d13
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x2ef6
callq 0x2180
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1(%rdx), %rsi
leaq 0x3167(%rip), %rdi      # 0x6075
jmp 0x2f1a
leaq 0x315e(%rip), %rdi      # 0x6075
movq %rax, %rsi
xorl %eax, %eax
callq 0x2250
movq %rax, %rbx
movq -0x68(%rbp), %rdi
jmp 0x2f31
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x2f47
jmp 0x2f4c
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0x2f4c
callq 0x2180
movq %rbx, %rdi
callq 0x22c0