// File: zhjw1998[P]Merkle-Tree/src/merkle_tree.cpp
// Function: MerkleTree::MerkleTree(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
MerkleTree::MerkleTree(const std::vector<std::string>& leaves) {
    std::vector<Node*> blocks;
    for(auto leaf : leaves){
        blocks.push_back(new Node(leaf));
        blocks.back()->left = nullptr;
        blocks.back()->right = nullptr;
    }
    clock_t start, finish;
    double duration1, duration2;
    start = clock();
    
    createMerkleTree(blocks); // this->root
    finish = clock();
    duration1 = (double)(finish - start) / CLOCKS_PER_SEC;
    std::cout << std::setw(24) << duration1;
    // printMerkleTree();
    // std::cout << "tree created" << std::endl;

    start = clock();
    BuildTrieTree(leaves); // this->trieroot
    finish = clock();
    duration2 = (double)(finish - start) / CLOCKS_PER_SEC;
    std::cout << std::setw(24) << duration2;
    std::cout << std::setw(24) << duration2 / duration1;
    // LevelOrderTraverse();
    // std::cout << "trie tree created" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xa400
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa420
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa450
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa480
testb $0x1, %al
jne 0x87ff
jmp 0x8934
leaq -0x38(%rbp), %rdi
callq 0xa4c0
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x2090
jmp 0x8816
movl $0x30, %edi
callq 0x21c0
movq %rax, -0xf8(%rbp)
jmp 0x8829
movb $0x1, -0x99(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2090
jmp 0x8842
movq -0xf8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xf1c0
jmp 0x8857
movq -0xf8(%rbp), %rax
movb $0x0, -0x99(%rbp)
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xa4e0
jmp 0x8878
leaq -0x98(%rbp), %rdi
callq 0x20f0
leaq -0x28(%rbp), %rdi
callq 0xa510
movq (%rax), %rax
movq $0x0, 0x20(%rax)
leaq -0x28(%rbp), %rdi
callq 0xa510
movq (%rax), %rax
movq $0x0, 0x28(%rax)
leaq -0x60(%rbp), %rdi
callq 0x20f0
leaq -0x38(%rbp), %rdi
callq 0xa550
jmp 0x87e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8b20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x8908
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x20f0
testb $0x1, -0x99(%rbp)
jne 0x8913
jmp 0x8924
movq -0xf8(%rbp), %rdi
movl $0x30, %esi
callq 0x21e0
jmp 0x8926
leaq -0x60(%rbp), %rdi
callq 0x20f0
jmp 0x8b20
callq 0x2110
movq %rax, -0xa8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xa570
jmp 0x8952
movq -0xf0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x8b40
jmp 0x8967
leaq -0xd8(%rbp), %rdi
callq 0xa660
callq 0x2110
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq -0xa8(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x766b(%rip), %xmm1     # 0x10008
divsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movl $0x18, %edi
callq 0x3ca0
movl %eax, -0xfc(%rbp)
jmp 0x89bb
movl -0xfc(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0xdc(%rbp), %esi
movq 0xf604(%rip), %rdi      # 0x17fd8
callq 0x2270
movq %rax, -0x108(%rbp)
jmp 0x89e2
movq -0x108(%rbp), %rdi
movsd -0xb8(%rbp), %xmm0
callq 0x2380
jmp 0x89f8
callq 0x2110
movq -0xf0(%rbp), %rdi
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rsi
callq 0x8f20
jmp 0x8a16
callq 0x2110
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq -0xa8(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x75c8(%rip), %xmm1     # 0x10008
divsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movl $0x18, %edi
callq 0x3ca0
movl %eax, -0x10c(%rbp)
jmp 0x8a5e
movl -0x10c(%rbp), %eax
movl %eax, -0xe0(%rbp)
movl -0xe0(%rbp), %esi
movq 0xf561(%rip), %rdi      # 0x17fd8
callq 0x2270
movq %rax, -0x118(%rbp)
jmp 0x8a85
movq -0x118(%rbp), %rdi
movsd -0xc0(%rbp), %xmm0
callq 0x2380
jmp 0x8a9b
movl $0x18, %edi
callq 0x3ca0
movl %eax, -0x11c(%rbp)
jmp 0x8aad
movl -0x11c(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %esi
movq 0xf512(%rip), %rdi      # 0x17fd8
callq 0x2270
movq %rax, -0x128(%rbp)
jmp 0x8ad4
movq -0x128(%rbp), %rdi
movsd -0xc0(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x2380
jmp 0x8af6
leaq -0x28(%rbp), %rdi
callq 0xa660
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xa660
leaq -0x28(%rbp), %rdi
callq 0xa660
movq -0x68(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)