// File: tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::findNodes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
vector<Node> MP2Node::findNodes(string key) {
	size_t pos = hashFunction(key);
	vector<Node> addr_vec;
	if (ring.size() >= 3) {
		// if pos <= min || pos > max, the leader is the min
		if (pos <= ring.at(0).getHashCode() || pos > ring.at(ring.size()-1).getHashCode()) {
			addr_vec.emplace_back(ring.at(0));
			addr_vec.emplace_back(ring.at(1));
			addr_vec.emplace_back(ring.at(2));
		}
		else {
			// go through the ring until pos <= node
			for (int i=1; i < (int)ring.size(); i++){
				Node addr = ring.at(i);
				if (pos <= addr.getHashCode()) {
					addr_vec.emplace_back(addr);
					addr_vec.emplace_back(ring.at((i+1)%ring.size()));
					addr_vec.emplace_back(ring.at((i+2)%ring.size()));
					break;
				}
			}
		}
	}
	return addr_vec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdx, -0xa8(%rbp)
movq %rsi, %rax
movq -0xa8(%rbp), %rsi
movq %rdi, -0x90(%rbp)
movq %rdi, %rcx
movq %rcx, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4160
movq -0x88(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1ec90
movq %rax, -0x98(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4200
movq -0x98(%rbp), %rax
movq -0x90(%rbp), %rdi
movq %rax, -0x20(%rbp)
movb $0x0, -0x41(%rbp)
callq 0x15010
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
callq 0x150e0
cmpq $0x3, %rax
jb 0x1f3f1
movq -0x88(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15100
movq %rax, -0xb0(%rbp)
jmp 0x1f0fa
movq -0xb0(%rbp), %rdi
callq 0x26310
movq %rax, -0xc0(%rbp)
jmp 0x1f10f
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1f18b
movq -0x88(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0xd8(%rbp)
addq $0x30, %rdi
movq %rdi, -0xd0(%rbp)
callq 0x150e0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x15100
movq %rax, -0xc8(%rbp)
jmp 0x1f15f
movq -0xc8(%rbp), %rdi
callq 0x26310
movq %rax, -0xe0(%rbp)
jmp 0x1f174
movq -0xd8(%rbp), %rax
movq -0xe0(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1f239
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15100
movq %rax, -0xe8(%rbp)
jmp 0x1f1a8
movq -0xe8(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x220a0
jmp 0x1f1bd
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
movl $0x1, %esi
callq 0x15100
movq %rax, -0xf0(%rbp)
jmp 0x1f1db
movq -0xf0(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x220a0
jmp 0x1f1f0
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
movl $0x2, %esi
callq 0x15100
movq %rax, -0xf8(%rbp)
jmp 0x1f20e
movq -0xf8(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x220a0
jmp 0x1f223
jmp 0x1f3ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1f41e
movl $0x1, -0x58(%rbp)
movq -0x88(%rbp), %rdi
movl -0x58(%rbp), %eax
movl %eax, -0xfc(%rbp)
addq $0x30, %rdi
callq 0x150e0
movq %rax, %rcx
movl -0xfc(%rbp), %eax
cmpl %ecx, %eax
jge 0x1f3ed
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
movslq -0x58(%rbp), %rsi
callq 0x15100
movq %rax, -0x108(%rbp)
jmp 0x1f287
movq -0x108(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x26240
jmp 0x1f299
movq -0x20(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x26310
movq %rax, -0x110(%rbp)
jmp 0x1f2b6
movq -0x118(%rbp), %rax
movq -0x110(%rbp), %rcx
cmpq %rcx, %rax
ja 0x1f3c2
movq -0x90(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x220a0
jmp 0x1f2df
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x130(%rbp)
movl -0x58(%rbp), %eax
incl %eax
cltq
movq %rax, -0x128(%rbp)
callq 0x150e0
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movq -0x128(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
callq 0x15100
movq %rax, -0x120(%rbp)
jmp 0x1f32b
movq -0x120(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x220a0
jmp 0x1f340
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x148(%rbp)
movl -0x58(%rbp), %eax
addl $0x2, %eax
cltq
movq %rax, -0x140(%rbp)
callq 0x150e0
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movq -0x140(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
callq 0x15100
movq %rax, -0x138(%rbp)
jmp 0x1f38d
movq -0x138(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x220a0
jmp 0x1f3a2
movl $0x2, -0x7c(%rbp)
jmp 0x1f3c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x26200
jmp 0x1f41e
movl $0x0, -0x7c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x26200
movl -0x7c(%rbp), %eax
testl %eax, %eax
je 0x1f3dd
jmp 0x1f3db
jmp 0x1f3ed
jmp 0x1f3df
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1f240
jmp 0x1f3ef
jmp 0x1f3f1
movb $0x1, -0x41(%rbp)
movl $0x1, -0x7c(%rbp)
testb $0x1, -0x41(%rbp)
jne 0x1f40e
movq -0x90(%rbp), %rdi
callq 0x15080
movq -0xa0(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x15080
movq -0x50(%rbp), %rdi
callq 0x45b0
nopw %cs:(%rax,%rax)