// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %r8, %r14
movl %edx, %r13d
movq %rdi, %rbx
fldt 0x20(%rbp)
fldt 0x10(%rbp)
movl %ecx, -0x2c(%rbp)
testl %ecx, %ecx
je 0x2c06
cmpl $-0x1, %r13d
je 0x2d64
movl %esi, -0x64(%rbp)
movl $0x0, -0x60(%rbp)
movq 0x38(%rbx), %rax
cmpq %rax, 0x40(%rbx)
je 0x2bfd
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
movslq %r13d, %rdx
decl -0x2c(%rbp)
xorl %ecx, %ecx
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
leaq (%rdx,%rdx,2), %r9
leaq 0x3f(%r8), %r10
shlq $0x4, %rdx
movq %rdx, -0x90(%rbp)
movq %r9, -0x78(%rbp)
movq %r10, -0x88(%rbp)
fxch %st(1)
fstpt -0x38(%rbp)
fstpt -0x70(%rbp)
fldz
fldz
fstp %st(1)
fstp %st(0)
cmpl %r13d, %ecx
je 0x2bd3
movq (%rax,%r9,8), %rax
cmpq $0x0, (%rax,%rcx,8)
je 0x2bd3
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x66b8(%rip), %rax      # 0x9130
movq %rcx, %rsi
andq %r10, %rsi
xorl %edx, %edx
cmpq %r8, %rsi
setbe %dl
movl $0x1, %esi
shlq %cl, %rsi
movq -0x8(%rax,%rdx,8), %rdi
btq %rcx, %rdi
jb 0x2bd3
leaq -0x8(,%rdx,8), %rdx
orq %rsi, %rdi
movq %rdi, (%rax,%rdx)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x2ac2
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x2ad2
movq %r14, %rdi
leaq -0x60(%rbp), %rdx
callq 0x39e0
movq -0x78(%rbp), %r9
movslq -0x60(%rbp), %r12
movq 0x38(%rbx), %rax
movq (%rax,%r9,8), %rax
movq (%rax,%r12,8), %rdi
xorl %esi, %esi
callq 0x4732
fldt 0x10(%rax)
fldt -0x70(%rbp)
fmulp %st, %st(1)
fstpt -0xcc(%rbp)
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x31a0
movq 0x8(%rbx), %rax
movq 0x20(%rbx), %rcx
movq -0x90(%rbp), %rdx
fldt (%rax,%rdx)
fldt -0x38(%rbp)
faddp %st, %st(1)
movslq -0x60(%rbp), %rax
shlq $0x4, %rax
fldt (%rcx,%rax)
faddp %st, %st(1)
fstpt 0x10(%rsp)
fldt -0xcc(%rbp)
fstpt (%rsp)
movq %rbx, %rdi
movl -0x64(%rbp), %esi
movl %r12d, %edx
movl -0x2c(%rbp), %ecx
movq %r15, %r8
callq 0x29ac
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x2b69
movq -0x98(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
addq $-0x4, 0x8(%r14)
movslq -0x60(%rbp), %rcx
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x65a4(%rip), %rax      # 0x9130
movq %rcx, %rdx
movq -0x88(%rbp), %r10
andq %r10, %rdx
xorl %esi, %esi
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
cmpq %r8, %rdx
setbe %sil
movq $-0x2, %rdx
rolq %cl, %rdx
andq %rdx, -0x8(%rax,%rsi,8)
fldt -0x38(%rbp)
fstp %st(0)
fldt -0x70(%rbp)
fstp %st(0)
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
movq -0x78(%rbp), %r9
movslq -0x60(%rbp), %rcx
incq %rcx
movl %ecx, -0x60(%rbp)
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r11, %rdx
cmpq %rcx, %rdx
fldz
fldz
ja 0x2a42
fstp %st(1)
fstp %st(0)
jmp 0x2d5d
movslq %r13d, %rax
movq 0x38(%rbx), %rcx
leaq (%rax,%rax,2), %rax
movslq %esi, %rdx
movq (%rcx,%rax,8), %rax
movq (%rax,%rdx,8), %rdi
xorl %esi, %esi
fxch %st(1)
fstpt -0x38(%rbp)
fstpt -0x70(%rbp)
callq 0x4732
fldt 0x10(%rax)
fldt -0x70(%rbp)
fmulp %st, %st(1)
fldt -0x38(%rbp)
fsubrp %st, %st(1)
fld1
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
jbe 0x2e57
fstpt -0x38(%rbp)
movq 0x6388(%rip), %rdi      # 0x8fd8
leaq 0x33b5(%rip), %rsi      # 0x600c
movl $0x1a, %edx
callq 0x2170
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x2cda
xorl %r12d, %r12d
movq 0x6364(%rip), %r13      # 0x8fd8
leaq 0x33aa(%rip), %r15      # 0x6025
movq (%rbx), %rsi
movl (%rax,%r12,4), %edx
leaq -0x60(%rbp), %rdi
callq 0x4150
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq %r13, %rdi
callq 0x2170
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2170
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x2cc4
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2150
incq %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
ja 0x2c7b
movq 0x62f7(%rip), %rbx      # 0x8fd8
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
movq %rax, %rbx
leaq 0x3315(%rip), %rsi      # 0x6027
movl $0x10, %edx
movq %rax, %rdi
callq 0x2170
fld1
fchs
fldt -0x38(%rbp)
faddp %st, %st(1)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x2080
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20c0
fldz
jmp 0x2e57
fstp %st(1)
fstp %st(0)
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
fldz
je 0x2e57
fstp %st(0)
decl -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
leaq -0xc0(%rbp), %r13
xorl %r15d, %r15d
movq %rbx, -0x80(%rbp)
fldz
fstp %st(0)
movq 0x6392(%rip), %rax      # 0x9130
movq %r15, %r12
shrq $0x6, %r12
movl $0x1, %r14d
movl %r15d, %ecx
shlq %cl, %r14
orq %r14, (%rax,%r12,8)
movl %r15d, -0x60(%rbp)
movl $0x1, %edx
movq %r13, %rbx
movq %r13, %rdi
leaq -0x60(%rbp), %rsi
leaq -0x39(%rbp), %rcx
callq 0x315a
movq -0x80(%rbp), %rdi
movq 0x20(%rdi), %rax
movq -0x38(%rbp), %rcx
fldt (%rax,%rcx)
fstpt 0x10(%rsp)
fld1
fstpt (%rsp)
movl %r15d, %esi
movl %r15d, %edx
movl -0x2c(%rbp), %ecx
movq %rbx, %r13
movq %rbx, %r8
callq 0x29ac
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x2e18
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
callq 0x2150
movq 0x6311(%rip), %rax      # 0x9130
notq %r14
andq %r14, (%rax,%r12,8)
incq %r15
movq -0x80(%rbp), %rbx
movq 0x40(%rbx), %rax
subq 0x38(%rbx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x10, -0x38(%rbp)
cmpq %r15, %rax
fldz
ja 0x2d95
fstp %st(0)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x2ebf
movq -0x98(%rbp), %rsi
jmp 0x2e9e
movq %rax, %rbx
jmp 0x2ebf
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x2ebf
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
jmp 0x2eba
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x2ebf
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x21f0
nop