// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, %r15
movl %edx, %r13d
movq %rdi, %rbx
fldt 0x20(%rbp)
fldt 0x10(%rbp)
movl %ecx, -0x34(%rbp)
testl %ecx, %ecx
je 0x28d6
cmpl $-0x1, %r13d
je 0x2987
movl %esi, -0x50(%rbp)
movslq %r13d, %rax
decl -0x34(%rbp)
xorl %ecx, %ecx
pushq $0x18
popq %r14
imulq $0x18, %rax, %rdx
movq %rdx, -0x58(%rbp)
leaq 0x59b0(%rip), %rdi      # 0x8130
shlq $0x4, %rax
movq %rax, -0x80(%rbp)
fxch %st(1)
fstpt -0x4c(%rbp)
fstpt -0x40(%rbp)
movl %ecx, -0x78(%rbp)
movslq %ecx, %rsi
movq 0x38(%rbx), %r8
movq 0x40(%rbx), %rax
subq %r8, %rax
cqto
idivq %r14
cmpq %rsi, %rax
jbe 0x2a65
movl %r13d, %r9d
cmpl %r13d, %ecx
je 0x28cb
movq -0x58(%rbp), %rax
movq (%r8,%rax), %rax
cmpq $0x0, (%rax,%rsi,8)
movl %ecx, %r9d
je 0x28cb
callq 0x2c6a
movl -0x78(%rbp), %r9d
testq %rdx, (%rax)
je 0x27f5
fldt -0x4c(%rbp)
fstp %st(0)
fldt -0x40(%rbp)
fstp %st(0)
leaq 0x5940(%rip), %rdi      # 0x8130
jmp 0x28cb
movslq %r9d, %rsi
leaq 0x5931(%rip), %rdi      # 0x8130
callq 0x2c6a
orq %rdx, (%rax)
movq %r15, %rdi
leaq -0x78(%rbp), %rsi
callq 0x2ce4
movslq -0x78(%rbp), %r12
movq 0x38(%rbx), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
callq 0x43f2
fldt 0x10(%rax)
fldt -0x40(%rbp)
fmulp %st, %st(1)
fstpt -0x8c(%rbp)
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
callq 0x2d0a
movq 0x8(%rbx), %rax
movq 0x20(%rbx), %rcx
movq -0x80(%rbp), %rdx
fldt (%rax,%rdx)
fldt -0x4c(%rbp)
faddp %st, %st(1)
movslq -0x78(%rbp), %rax
shlq $0x4, %rax
fldt (%rcx,%rax)
faddp %st, %st(1)
fstpt 0x10(%rsp)
fldt -0x8c(%rbp)
fstpt (%rsp)
movq %rbx, %rdi
movl -0x50(%rbp), %esi
movl %r12d, %edx
leaq -0xa8(%rbp), %r12
movl -0x34(%rbp), %ecx
movq %r12, %r8
callq 0x272a
movq %r12, %rdi
callq 0x3724
addq $-0x4, 0x8(%r15)
movslq -0x78(%rbp), %rsi
leaq 0x5884(%rip), %r12      # 0x8130
movq %r12, %rdi
callq 0x2c6a
notq %rdx
andq %rdx, (%rax)
movl -0x78(%rbp), %r9d
fldt -0x4c(%rbp)
fstp %st(0)
fldt -0x40(%rbp)
fstp %st(0)
movq %r12, %rdi
incl %r9d
movl %r9d, %ecx
jmp 0x2790
movslq %r13d, %rax
movq 0x38(%rbx), %rcx
imulq $0x18, %rax, %rax
movslq %esi, %rdx
movq (%rcx,%rax), %rax
movq (%rax,%rdx,8), %rdi
xorl %esi, %esi
fxch %st(1)
fstpt -0x4c(%rbp)
fstpt -0x40(%rbp)
callq 0x43f2
fldt 0x10(%rax)
fldt -0x40(%rbp)
fmulp %st, %st(1)
fldt -0x4c(%rbp)
fsubrp %st, %st(1)
fld1
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
jbe 0x2a67
fstpt -0x34(%rbp)
movq 0x56b8(%rip), %rdi      # 0x7fd8
leaq 0x26e5(%rip), %rsi      # 0x500c
callq 0x2140
xorl %r14d, %r14d
leaq -0x78(%rbp), %r12
leaq 0x26eb(%rip), %r13      # 0x5025
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r14, %rcx
jbe 0x2a2e
movq (%rbx), %rsi
movl (%rax,%r14,4), %edx
movq %r12, %rdi
callq 0x3f22
movq 0x5671(%rip), %rdi      # 0x7fd8
movq %r12, %rsi
callq 0x2120
movq %rax, %rdi
movq %r13, %rsi
callq 0x2140
movq %r12, %rdi
callq 0x2080
incq %r14
jmp 0x293a
fstp %st(1)
fstp %st(0)
decl -0x34(%rbp)
xorl %r14d, %r14d
leaq 0x5798(%rip), %r15      # 0x8130
leaq -0xc0(%rbp), %r12
xorl %r13d, %r13d
movq 0x40(%rbx), %rax
subq 0x38(%rbx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %r13, %rax
fldz
jbe 0x2a67
fstp %st(0)
movq %r15, %rdi
movq %r13, %rsi
callq 0x2c6a
orq %rdx, (%rax)
movl %r13d, -0x78(%rbp)
movq %r12, %rdi
leaq -0x78(%rbp), %rsi
pushq $0x1
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x2cae
movq 0x20(%rbx), %rax
fldt (%rax,%r14)
fstpt 0x10(%rsp)
fld1
fstpt (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movl %r13d, %edx
movl -0x34(%rbp), %ecx
movq %r12, %r8
callq 0x272a
movq %r12, %rdi
callq 0x3724
movq %r15, %rdi
movq %r13, %rsi
callq 0x2c6a
notq %rdx
andq %rdx, (%rax)
incq %r13
addq $0x10, %r14
jmp 0x29a2
movq 0x55a3(%rip), %rdi      # 0x7fd8
callq 0x2090
leaq 0x25e6(%rip), %rsi      # 0x5027
movq %rax, %rdi
callq 0x2140
fld1
fchs
fldt -0x34(%rbp)
faddp %st, %st(1)
fstpt (%rsp)
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
callq 0x2090
fldz
fstp %st(0)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x2a96
movq %rax, %rbx
jmp 0x2aa9
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x3724
jmp 0x2aa9
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2200
nop