// File: /workspace/github_cpp_makefile_star2_O1/zhjw1998[P]Merkle-Tree/src/merkle_tree.cpp
// Function: MerkleTree::createMerkleTree(std::vector<Node*, std::allocator<Node*>>)
void MerkleTree::createMerkleTree(std::vector<Node*> blocks){
    std::vector<Node*> nodes;
    while (blocks.size() != 1) {
        for (unsigned int l = 0, n = 0; l < blocks.size(); l = l + 2, n++) {
            if (l != blocks.size() - 1) { // checks for adjacent block
                nodes.push_back(new Node(hash_sha256(blocks[l]->hash + blocks[l+1]->hash))); // combine and hash adjacent blocks
                nodes[n]->left = blocks[l]; // assign children
                nodes[n]->right = blocks[l+1];
            } else {
                nodes.push_back(new Node(blocks[l]->hash));
                nodes[n]->left = blocks[l];
                nodes[n]->right = nullptr;
            }
        }
        blocks = nodes;
        nodes.clear();
    }
    // printNodeHashes(blocks);
    this->root = blocks[0];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, 0x68(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
je 0x4f7b
movq %rsi, %r15
movq %rsi, 0x70(%rsp)
movq (%r15), %r14
movq 0x8(%r15), %rax
subq %r14, %rax
je 0x4f4c
sarq $0x3, %rax
xorl %ebx, %ebx
movl $0x2, %r12d
xorl %r13d, %r13d
decq %rax
cmpq %rbx, %rax
jne 0x4e58
movl $0x30, %edi
callq 0x2160
movq %rax, %rbp
movq (%r14,%rbx,8), %rax
leaq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x45d2
movq %r14, %rsi
movb $0x1, %r14b
movq %rbp, %rdi
callq 0x6bb4
movq %rbp, 0x18(%rsp)
xorl %r14d, %r14d
movq %rsp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6314
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4e38
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2170
movq (%r15), %rax
movq (%rax,%rbx,8), %rcx
movl %r13d, %eax
movq (%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq (%rax), %rdx
movq %rcx, 0x20(%rdx)
xorl %ecx, %ecx
jmp 0x4f24
movl $0x30, %edi
callq 0x2160
movq %rax, 0x20(%rsp)
movq (%r14,%rbx,8), %rsi
leal -0x1(%r12), %r15d
movq (%r14,%r15,8), %rdx
leaq 0x48(%rsp), %rdi
callq 0x6002
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x3a4e
movq %r14, %rsi
movb $0x1, %r14b
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x6bb4
movq %rbp, 0x18(%rsp)
xorl %r14d, %r14d
movq %rsp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6314
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x4ee2
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4efe
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x70(%rsp), %rbp
movq (%rbp), %rcx
movq (%rcx,%rbx,8), %rdx
movl %r13d, %eax
movq (%rsp), %rsi
leaq (%rsi,%rax,8), %rax
movq (%rax), %rsi
movq %rdx, 0x20(%rsi)
movq (%rcx,%r15,8), %rcx
movq %rbp, %r15
movq (%rax), %rax
movq %rcx, 0x28(%rax)
incl %r13d
movl %r12d, %ebx
movq (%r15), %r14
movq 0x8(%r15), %rax
subq %r14, %rax
sarq $0x3, %rax
addl $0x2, %r12d
cmpq %rbx, %rax
ja 0x4dbb
movq %r15, %rdi
movq %rsp, %rsi
callq 0x605c
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x4f67
movq %rax, 0x8(%rsp)
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0x4d9c
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq %rax, (%rcx)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4f9c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4fbd
movq %rax, %rbx
movb $0x1, %r14b
jmp 0x5044
jmp 0x4fbd
movq %rax, %rbx
jmp 0x5058
movq %rax, %rbx
movb $0x1, %r14b
jmp 0x5028
movq %rax, %rbx
movb $0x1, %r14b
jmp 0x4ff4
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4ff4
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2170
testb %r14b, %r14b
je 0x5058
movl $0x30, %esi
movq %rbp, %rdi
jmp 0x5053
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x5028
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2170
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x5044
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2170
testb %r14b, %r14b
je 0x5058
movl $0x30, %esi
movq 0x20(%rsp), %rdi
callq 0x2170
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x506e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2240