// File: /workspace/github_cpp_makefile_star2_O3/tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::updateTransactionMap()
void MP2Node::updateTransactionMap() {
    if (txMap.empty()) { // nothing to check here
        return;
    }
    // Go through each entry in the transaction map
    for (auto it = txMap.begin(); it != txMap.end();) {
        int txId = it->first;
        Transaction *transaction = &it->second;

        // if this transaction has enough successful replies, log success
        if (transaction->successCount >= QUORUM) { // operation successful! log success as coordinator
            switch (transaction->type) {
                case READ:
                    log->logReadSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case UPDATE:
                    log->logUpdateSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case CREATE:
                    log->logCreateSuccess(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case DELETE:
                    log->logDeleteSuccess(&memberNode->addr, true, txId, transaction->key);
                    break;
                default:
                    break;
            }
            txMap.erase(it++);
            continue;
        }
        // This transaction DOES NOT have enough success replies...
        // So we check if it has reached maximum replies, or it has timed out
        if (transaction->totalCount == TOTAL || par->getcurrtime() - transaction->timestamp > OPERATION_TIMEOUT) { // operation failed :( log failure as coordinator
            switch (transaction->type) {
                case READ:
                    log->logReadFail(&memberNode->addr, true, txId, transaction->key);
                    break;
                case UPDATE:
                    log->logUpdateFail(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case CREATE:
                    log->logCreateFail(&memberNode->addr, true, txId, transaction->key, transaction->value);
                    break;
                case DELETE:
                    log->logDeleteFail(&memberNode->addr, true, txId, transaction->key);
                    break;
                default:
                    break;
            }
            txMap.erase(it++);
            continue;
        }
        // otherwise, we don't do anything
        // since if transaction doesn't exist in the map, it's already resolved
        it++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, (%rsp)
cmpq $0x0, 0xe8(%rdi)
je 0xf33b
movq (%rsp), %rax
movq 0xd8(%rax), %r15
addq $0xc8, %rax
movq %rax, 0x100(%rsp)
cmpq %rax, %r15
je 0xf33b
movq (%rsp), %rax
addq $0xc0, %rax
movq %rax, 0x78(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %r14
leaq 0x58(%rsp), %rbp
leaq 0x38(%rsp), %r13
movl 0x20(%r15), %ebx
cmpl $0x2, 0x28(%r15)
jl 0xee46
movl 0x38(%r15), %eax
cmpq $0x3, %rax
ja 0xf0b3
leaq 0x8ecb(%rip), %rcx      # 0x17c34
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %ebx, %r13d
movq (%rsp), %rax
movq 0x50(%rax), %rbp
movq 0x68(%rax), %r12
leaq 0x138(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %r14
movq %r14, %rdi
callq 0x5a4e
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
callq 0x5a4e
addq $0x8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %r13d, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xbf68
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x18(%rsp), %r12
je 0xee1e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
leaq 0x58(%rsp), %rbp
leaq 0x38(%rsp), %rcx
movq %r12, %r14
jmp 0xf2b5
cmpl $0x3, 0x2c(%r15)
je 0xee67
movq (%rsp), %rax
movq 0x58(%rax), %rdi
callq 0xc87e
subl 0x34(%r15), %eax
cmpl $0x15, %eax
jl 0xef5b
movl 0x38(%r15), %eax
cmpq $0x3, %rax
ja 0xf0b3
leaq 0x8da8(%rip), %rcx      # 0x17c24
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
leaq 0x80(%rsp), %r13
movq 0x50(%rax), %rbp
movq 0x68(%rax), %r12
leaq 0x118(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
leaq 0x108(%rsp), %r14
movq %r14, %rdi
callq 0x5a4e
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5a4e
addq $0x8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movq %r14, %r8
movq %r13, %r9
callq 0xc322
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
leaq 0x38(%rsp), %rbx
leaq 0x58(%rsp), %rbp
je 0xef32
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
leaq 0x18(%rsp), %r14
movq %rbx, %r13
jne 0xf0a8
jmp 0xf0b3
movq %r15, %rdi
callq 0x31d0
movq %rax, %r12
jmp 0xf0cb
movl %ebx, %r14d
leaq 0x148(%rsp), %r13
movq (%rsp), %rax
movq 0x50(%rax), %rbp
movq 0x68(%rax), %r12
leaq 0x158(%rsp), %rax
movq %rax, 0x148(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5a4e
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
callq 0x5a4e
addq $0x8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %r14d, %ecx
movq %r13, %r8
movq %rbx, %r9
callq 0xc14c
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xf012
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
leaq 0x58(%rsp), %rbp
jmp 0xf09c
movq %rbp, %r13
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %r12
leaq 0x1b8(%rsp), %r14
movq %r14, 0x1a8(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
movl %ebx, %ebp
leaq 0x1a8(%rsp), %rbx
movq %rbx, %rdi
callq 0x5a4e
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebp, %ecx
movq %rbx, %r8
callq 0xc23e
movq 0x1a8(%rsp), %rdi
movq %r14, %rax
cmpq %r14, %rdi
movq %r13, %rbp
leaq 0x38(%rsp), %r13
leaq 0x18(%rsp), %r14
je 0xf0b3
movq (%rax), %rsi
incq %rsi
callq 0x32c0
movq %r15, %rdi
callq 0x31d0
movq %rax, %r12
movq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x1320c
movq %r12, %r15
cmpq 0x100(%rsp), %r12
jne 0xed45
jmp 0xf33b
movq (%rsp), %rax
movq %r14, %r13
movq %rbp, %r14
movq 0x50(%rax), %rbp
movq 0x68(%rax), %r12
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5a4e
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x5a4e
addq $0x8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movq %r13, %rbx
movq %r13, %r8
movq %r14, %rbp
movq %r14, %r9
callq 0xc05a
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
leaq 0x38(%rsp), %r13
je 0xf170
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
movq %rbx, %r14
jne 0xf0a8
jmp 0xf0b3
movq %r13, %r14
movq (%rsp), %rax
movq 0x50(%rax), %rbp
movq 0x68(%rax), %r12
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5a4e
leaq 0xb0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x60(%r15), %rsi
movq 0x68(%r15), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0x5a4e
addq $0x8, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movq %r14, %r12
movq %r14, %r8
movq %r13, %r9
callq 0xc4f8
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x18(%rsp), %r14
je 0xf22e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
movq %r12, %r13
jmp 0xf32b
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %r12
leaq 0x178(%rsp), %r14
movq %r14, 0x168(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
leaq 0x168(%rsp), %r13
movq %r13, %rdi
callq 0x5a4e
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movq %r13, %r8
callq 0xc5ea
movq 0x168(%rsp), %rdi
movq %r14, %rax
cmpq %r14, %rdi
leaq 0x18(%rsp), %r14
leaq 0x38(%rsp), %rcx
movq %rcx, %r13
jne 0xf0a8
jmp 0xf0b3
movq (%rsp), %rax
movq 0x50(%rax), %r12
movq 0x68(%rax), %rbp
addq $0x8, %r12
leaq 0x198(%rsp), %r14
movq %r14, 0x188(%rsp)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
leaq 0x188(%rsp), %r13
movq %r13, %rdi
callq 0x5a4e
movq %rbp, %rdi
movq %r12, %rsi
movl $0x1, %edx
movl %ebx, %ecx
movq %r13, %r8
callq 0xc414
movq 0x188(%rsp), %rdi
movq %r14, %rax
cmpq %r14, %rdi
leaq 0x38(%rsp), %r13
leaq 0x18(%rsp), %r14
leaq 0x58(%rsp), %rbp
jne 0xf0a8
jmp 0xf0b3
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xf37a
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0xf37a
movq %rax, %rbx
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
jmp 0xf497
movq %rax, %rbx
movq 0x188(%rsp), %rdi
jmp 0xf4c4
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xf3cc
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0xf3cc
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
jmp 0xf497
movq %rax, %rbx
movq 0x168(%rsp), %rdi
jmp 0xf4c4
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xf418
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0xf418
movq %rax, %rbx
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
jmp 0xf497
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xf44e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0xf44e
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
jmp 0xf49c
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xf487
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0xf487
movq %rax, %rbx
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, %rdi
je 0xf4b1
movq 0x8(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x34b0
movq %rax, %rbx
movq 0x1a8(%rsp), %rdi
movq %r14, 0x8(%rsp)
cmpq %r14, %rdi
jne 0xf4a1
jmp 0xf4b1