// File: cmirnov[P]triangular-arbitrage/exchange.cpp
// Function: Exchange::arbitrage(int, int, long double, int, std::vector<int, std::allocator<int>>, long double)
void Exchange::arbitrage(int begin, int prev, long double tempPrice, int level, std::vector<int> stack, long double fees) {
	if (level == 0) {
		tempPrice *= (matrix[prev][begin]->get(0))->price;
		if (tempPrice - fees > 1) {
			std::cout << "there is a new arbitrage: ";
			for (int i = 0; i < stack.size(); ++i) {
				std::cout << converter->intToName(stack[i]) << " ";
			}
			std::cout << std::endl << "with a profit = " << tempPrice - fees - 1 << std::endl;
		}
		return;
	}
	if (prev == -1) {
		for (int i = 0; i < matrix.size(); ++i) {
			used[i] = true;
			arbitrage(i, i, 1, level - 1, {i}, buyFee[i]);
			used[i] = false;
		}
	} else {
		for (int i = 0; i < matrix.size(); ++i) {
			if (i != prev && matrix[prev][i] != NULL && !used[i]) {
				used[i] = true;
				stack.push_back(i);
				arbitrage(begin, i, tempPrice * (matrix[prev][i]->get(0))->price, level - 1, stack, fees + sellFee[prev] + buyFee[i]);
				stack.pop_back();
				used[i] = false;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %r8, -0x128(%rbp)
fldt 0x20(%rbp)
fldt 0x10(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
fstpt -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
fstpt -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x2b52
movq -0x120(%rbp), %rdi
addq $0x38, %rdi
movslq -0x10(%rbp), %rsi
callq 0x3290
movq %rax, %rdi
movslq -0xc(%rbp), %rsi
callq 0x34f0
movq (%rax), %rdi
xorl %esi, %esi
callq 0xa6d0
fldt 0x10(%rax)
fldt -0x20(%rbp)
fmulp %st, %st(1)
fstpt -0x20(%rbp)
fldt -0x20(%rbp)
fldt -0x40(%rbp)
fsubrp %st, %st(1)
fld1
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x2b4d
jmp 0x2a21
movq 0x135b0(%rip), %rdi     # 0x15fd8
leaq 0xb5dd(%rip), %rsi      # 0xe00c
callq 0x2160
movl $0x0, -0x44(%rbp)
movq -0x128(%rbp), %rdi
movslq -0x44(%rbp), %rax
movq %rax, -0x130(%rbp)
callq 0x3510
movq %rax, %rcx
movq -0x130(%rbp), %rax
cmpq %rcx, %rax
jae 0x2b01
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x148(%rbp)
movslq -0x44(%rbp), %rsi
callq 0x3530
movq -0x148(%rbp), %rsi
movl (%rax), %edx
leaq -0x68(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x9900
movq -0x140(%rbp), %rsi
movq 0x1352b(%rip), %rdi     # 0x15fd8
callq 0x2140
movq %rax, -0x138(%rbp)
jmp 0x2abb
movq -0x138(%rbp), %rdi
leaq 0xb55c(%rip), %rsi      # 0xe025
callq 0x2160
jmp 0x2ad0
leaq -0x68(%rbp), %rdi
callq 0x20e0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2a3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x20e0
jmp 0x2f98
movq 0x134d0(%rip), %rdi     # 0x15fd8
movq 0x134b9(%rip), %rsi     # 0x15fc8
callq 0x2190
movq %rax, %rdi
leaq 0xb509(%rip), %rsi      # 0xe027
callq 0x2160
movq %rax, %rdi
fldt -0x20(%rbp)
fldt -0x40(%rbp)
fsubrp %st, %st(1)
fld1
fchs
faddp %st, %st(1)
movq %rsp, %rax
fstpt (%rax)
callq 0x21b0
movq %rax, %rdi
movq 0x13480(%rip), %rsi     # 0x15fc8
callq 0x2190
jmp 0x2f8f
cmpl $-0x1, -0x10(%rbp)
jne 0x2d03
movl $0x0, -0x78(%rbp)
movq -0x120(%rbp), %rdi
movslq -0x78(%rbp), %rax
movq %rax, -0x150(%rbp)
addq $0x38, %rdi
callq 0x3550
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
jae 0x2cfe
movslq -0x78(%rbp), %rsi
leaq 0x135c4(%rip), %rdi     # 0x16160
callq 0x3580
movq %rax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x35e0
movl -0x78(%rbp), %eax
movl %eax, -0x164(%rbp)
movl %eax, %ecx
movl %ecx, -0x160(%rbp)
movl -0x24(%rbp), %ecx
decl %ecx
movl %ecx, -0x15c(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xb4(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq $0x1, -0xa8(%rbp)
leaq -0xb5(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3630
movq -0x158(%rbp), %rcx
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x3650
jmp 0x2c2e
movq -0x120(%rbp), %rdi
addq $0x20, %rdi
movslq -0x78(%rbp), %rsi
callq 0x33d0
movq -0x120(%rbp), %rdi
movl -0x160(%rbp), %esi
movl -0x164(%rbp), %edx
movl -0x15c(%rbp), %ecx
fldt (%rax)
movq %rsp, %rax
fstpt 0x10(%rax)
fld1
fstpt (%rax)
leaq -0xa0(%rbp), %r8
callq 0x2990
jmp 0x2c75
leaq -0xa0(%rbp), %rdi
callq 0x36d0
leaq -0xb5(%rbp), %rdi
callq 0x3730
movslq -0x78(%rbp), %rsi
leaq 0x134c8(%rip), %rdi     # 0x16160
callq 0x3580
movq %rax, -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
callq 0x35e0
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x2b63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2ced
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x36d0
leaq -0xb5(%rbp), %rdi
callq 0x3730
jmp 0x2f98
jmp 0x2f8f
movl $0x0, -0xcc(%rbp)
movq -0x120(%rbp), %rdi
movslq -0xcc(%rbp), %rax
movq %rax, -0x170(%rbp)
addq $0x38, %rdi
callq 0x3550
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0x2f8d
movl -0xcc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x10(%rbp), %ecx
movb %al, -0x171(%rbp)
je 0x2dba
movq -0x120(%rbp), %rdi
addq $0x38, %rdi
movslq -0x10(%rbp), %rsi
callq 0x3290
movq %rax, %rdi
movslq -0xcc(%rbp), %rsi
callq 0x34f0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x171(%rbp)
je 0x2dba
movslq -0xcc(%rbp), %rsi
leaq 0x133cd(%rip), %rdi     # 0x16160
callq 0x3580
movq %rax, -0xe0(%rbp)
movq %rdx, -0xd8(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3750
xorb $-0x1, %al
movb %al, -0x171(%rbp)
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x2dc9
jmp 0x2f77
movslq -0xcc(%rbp), %rsi
leaq 0x13389(%rip), %rdi     # 0x16160
callq 0x3580
movq %rax, -0xf0(%rbp)
movq %rdx, -0xe8(%rbp)
leaq -0xf0(%rbp), %rdi
movl $0x1, %esi
callq 0x35e0
movq -0x128(%rbp), %rdi
leaq -0xcc(%rbp), %rsi
callq 0x3780
movq -0x120(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x18c(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x188(%rbp)
fldt -0x20(%rbp)
fstpt -0x1bc(%rbp)
addq $0x38, %rdi
movslq -0x10(%rbp), %rsi
callq 0x3290
movq %rax, %rdi
movslq -0xcc(%rbp), %rsi
callq 0x34f0
movq (%rax), %rdi
xorl %esi, %esi
callq 0xa6d0
fldt -0x1bc(%rbp)
movq -0x128(%rbp), %rsi
fldt 0x10(%rax)
fmulp %st, %st(1)
fstpt -0x198(%rbp)
movl -0x24(%rbp), %eax
decl %eax
movl %eax, -0x184(%rbp)
leaq -0x108(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x37f0
movq -0x120(%rbp), %rdi
fldt -0x40(%rbp)
fstpt -0x1b0(%rbp)
addq $0x8, %rdi
movslq -0x10(%rbp), %rsi
callq 0x33d0
fldt -0x1b0(%rbp)
movq -0x120(%rbp), %rdi
fldt (%rax)
faddp %st, %st(1)
fstpt -0x1a4(%rbp)
addq $0x20, %rdi
movslq -0xcc(%rbp), %rsi
callq 0x33d0
fldt -0x1a4(%rbp)
fldt -0x198(%rbp)
movq -0x120(%rbp), %rdi
movl -0x18c(%rbp), %esi
movl -0x188(%rbp), %edx
movl -0x184(%rbp), %ecx
movq -0x180(%rbp), %r8
fldt (%rax)
faddp %st, %st(2)
movq %rsp, %rax
fxch %st(1)
fstpt 0x10(%rax)
fstpt (%rax)
callq 0x2990
jmp 0x2f14
leaq -0x108(%rbp), %rdi
callq 0x36d0
movq -0x128(%rbp), %rdi
callq 0x38e0
movslq -0xcc(%rbp), %rsi
leaq 0x13226(%rip), %rdi     # 0x16160
callq 0x3580
movq %rax, -0x118(%rbp)
movq %rdx, -0x110(%rbp)
leaq -0x118(%rbp), %rdi
xorl %esi, %esi
callq 0x35e0
jmp 0x2f77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x36d0
jmp 0x2f98
jmp 0x2f79
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x2d0d
jmp 0x2f8f
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2250
nopw %cs:(%rax,%rax)