// File: havluj[P]spreadsheet/src/CEquation.cpp
// Function: CEquation::replaceOtherCells(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string CEquation::replaceOtherCells(std::string exp) {
    // erase all the spaces
    exp.erase(std::remove(exp.begin(), exp.end(), ' '), exp.end());
    m_expression = exp; 
    // replace = with a space
    exp.replace(exp.find("="), 1, " "); 
    // erase all the spaces
    exp.erase(std::remove(exp.begin(), exp.end(), ' '), exp.end());
    

    /* make everything upper case */
    exp = UpperCase(exp);

    /* PARSING CELL FUNCTION */
    std::string phraze = "CELL"; // substring we are looking for
    std::string subExp;
    size_t pos = exp.find(phraze, 0);
    while (pos != std::string::npos) {
	  size_t endingParentheses = exp.find(")", pos);
	  subExp = exp.substr(pos + 4, endingParentheses - pos + 1);
	  std::stringstream stream;
	  stream << subExp;
	  char ch;
	  stream >> ch;
	  if (ch != '(') {
		m_error = true;
		m_errorMsg = "ERR: wrong CELL format";
		return exp;
	  }
	  int row = 0, col = 0;
	  stream >> row;
	  stream >> ch;
	  if (ch != ',') {
		m_error = true;
		m_errorMsg = "ERR: wrong CELL format";
		return exp;
	  }
	  stream >> col;

	  stream >> ch;
	  if (ch != ')') {
		m_error = true;
		m_errorMsg = "ERR: wrong CELL format";
		return exp;
	  }

	  if (col == 0 || row == 0) {
		m_error = true;
		m_errorMsg = "ERR: wrong CELL format";
		return exp;
	  }

	  m_affectedBy.insert(std::make_pair(row, col));

	  //replace the cell
	  double val = 0;
	  CCell* cell = NULL;
	  try {
		cell = m_database->getCell(row, col);
		if (cell->getId() == m_id) {
		    m_error = true;
		    m_errorMsg = "ERR: trying to get value of itself in CELL function";
		    return exp;
		} else {
		    val = cell->getValue();
		}
	  } catch (std::logic_error e) {
		m_error = true;
		m_errorMsg = "ERR: trying to compute with string or empty cell";
		return exp;
	  }

	  exp.replace(pos, endingParentheses - pos + 1, std::to_string(val));

	  pos = exp.find(phraze, pos + 1);
    }


    /* PARSING SUM FUNCTION */
    phraze = "SUM"; // substring we are looking for
    pos = exp.find(phraze, 0);
    while (pos != std::string::npos) {
	  size_t endingParentheses = exp.find(")", pos);
	  subExp = exp.substr(pos + 3, endingParentheses - pos + 1);
	  std::stringstream stream;
	  stream << subExp;
	  char ch;
	  stream >> ch;
	  if (ch != '(') {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }
	  int rowBegin = 0, colBegin = 0, rowEnd = 0, colEnd = 0;
	  stream >> rowBegin;
	  stream >> ch;
	  if (ch != ',') {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }
	  stream >> colBegin;

	  stream >> ch;
	  if (ch != ':') {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }
	  stream >> rowEnd;
	  stream >> ch;
	  if (ch != ',') {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }
	  stream >> colEnd;

	  stream >> ch;
	  if (ch != ')') {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }

	  if (colBegin == 0 || rowBegin == 0 || rowEnd == 0 || colEnd == 0) {
		m_error = true;
		m_errorMsg = "ERR: wrong SUM format";
		return exp;
	  }

	  if (rowBegin > rowEnd) {
		int tmp = rowEnd;
		rowEnd = rowBegin;
		rowBegin = tmp;
	  }

	  if (colBegin > colEnd) {
		int tmp = colEnd;
		colEnd = colBegin;
		colBegin = tmp;
	  }

	  double val = 0;
	  for (int i = rowBegin; i <= rowEnd; i++) {
		for (int j = colBegin; j <= colEnd; j++) {
		    m_affectedBy.insert(std::make_pair(i, j));

		    //replace the cell
		    CCell* cell = NULL;
		    try {
			  cell = m_database->getCell(i, j);
			  if (cell->getId() == m_id) {
				m_error = true;
				m_errorMsg = "ERR: trying to get value of itself in SUM function";
			  } else {
				val += cell->getValue();
			  }
		    } catch (std::logic_error e) {
			  m_error = true;
			  m_errorMsg = "ERR: trying to compute with string or empty cell";
		    }
		}
	  }
	  if (m_error) {
		return exp;
	  }

	  exp.replace(pos, endingParentheses - pos + 1, std::to_string(val));

	  pos = exp.find(phraze, pos + 1);
    }


    /* PARSING SUM FUNCTION */
    phraze = "AVG"; // substring we are looking for
    pos = exp.find(phraze, 0);
    while (pos != std::string::npos) {
	  size_t endingParentheses = exp.find(")", pos);
	  subExp = exp.substr(pos + 3, endingParentheses - pos + 1);
	  std::stringstream stream;
	  stream << subExp;
	  char ch;
	  stream >> ch;
	  if (ch != '(') {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }
	  int rowBegin = 0, colBegin = 0, rowEnd = 0, colEnd = 0;
	  stream >> rowBegin;
	  stream >> ch;
	  if (ch != ',') {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }
	  stream >> colBegin;

	  stream >> ch;
	  if (ch != ':') {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }
	  stream >> rowEnd;
	  stream >> ch;
	  if (ch != ',') {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }
	  stream >> colEnd;

	  stream >> ch;
	  if (ch != ')') {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }

	  if (colBegin == 0 || rowBegin == 0 || rowEnd == 0 || colEnd == 0) {
		m_error = true;
		m_errorMsg = "ERR: wrong AVG format";
		return exp;
	  }

	  if (rowBegin > rowEnd) {
		int tmp = rowEnd;
		rowEnd = rowBegin;
		rowBegin = tmp;
	  }

	  if (colBegin > colEnd) {
		int tmp = colEnd;
		colEnd = colBegin;
		colBegin = tmp;
	  }

	  double val = 0;
	  for (int i = rowBegin; i <= rowEnd; i++) {
		for (int j = colBegin; j <= colEnd; j++) {
		    m_affectedBy.insert(std::make_pair(i, j));

		    //replace the cell
		    CCell* cell = NULL;
		    try {
			  cell = m_database->getCell(i, j);
			  if (cell->getId() == m_id) {
				m_error = true;
				m_errorMsg = "ERR: trying to get value of itself in AVG function";
			  } else {
				val += cell->getValue();
			  }
		    } catch (std::logic_error e) {
			  m_error = true;
			  m_errorMsg = "ERR: trying to compute with string or empty cell";
		    }
		}
	  }
	  if (m_error) {
		return exp;
	  }
	  int rowCnt = rowEnd - rowBegin + 1;
	  int colCnt = colEnd - colBegin + 1;

	  exp.replace(pos, endingParentheses - pos + 1, std::to_string(val / (rowCnt * colCnt)));

	  pos = exp.find(phraze, pos + 1);
    }

    return exp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x900, %rsp            # imm = 0x900
movq %rdx, -0x7c8(%rbp)
movq %rdi, %rax
movq -0x7c8(%rbp), %rdi
movq %rax, -0x7e0(%rbp)
movq %rax, %rcx
movq %rcx, -0x7d8(%rbp)
movq %rax, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x7d0(%rbp)
callq 0x53c0
movq -0x7c8(%rbp), %rdi
movq %rax, -0x30(%rbp)
callq 0x5260
movq %rax, -0x38(%rbp)
movb $0x20, -0x39(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x39(%rbp), %rdx
callq 0xf1d0
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xf220
movq -0x7c8(%rbp), %rdi
callq 0x5260
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xf220
movq -0x7c8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x50b0
movq -0x7d0(%rbp), %rdi
movq -0x7c8(%rbp), %rsi
movq %rax, -0x58(%rbp)
addq $0x8, %rdi
callq 0x5040
movq -0x7c8(%rbp), %rdi
leaq 0xeabf(%rip), %rsi      # 0x1c4bc
xorl %eax, %eax
movl %eax, %edx
callq 0x5830
movq -0x7c8(%rbp), %rdi
movq %rax, %rsi
leaq 0xee1c(%rip), %rcx      # 0x1c833
movl $0x1, %edx
callq 0x5280
movq -0x7c8(%rbp), %rdi
callq 0x53c0
movq -0x7c8(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x5260
movq %rax, -0x78(%rbp)
movb $0x20, -0x79(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
leaq -0x79(%rbp), %rdx
callq 0xf1d0
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xf220
movq -0x7c8(%rbp), %rdi
callq 0x5260
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xf220
movq -0x7c8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x50b0
movq -0x7c8(%rbp), %rsi
movq %rax, -0x98(%rbp)
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x7c0(%rbp)
callq 0x51b0
movq -0x7c0(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x148f0
jmp 0xdada
movq -0x7c8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movq %rsi, -0x7f0(%rbp)
callq 0x5510
movq -0x7f0(%rbp), %rdi
callq 0x52a0
leaq -0xd8(%rbp), %rdi
callq 0x52a0
leaq -0x109(%rbp), %rdi
movq %rdi, -0x7e8(%rbp)
callq 0x5740
movq -0x7e8(%rbp), %rdx
leaq 0xe991(%rip), %rsi      # 0x1c4be
leaq -0x108(%rbp), %rdi
callq 0x7360
jmp 0xdb3b
leaq -0x109(%rbp), %rdi
callq 0x54a0
leaq -0x130(%rbp), %rdi
callq 0x55b0
movq -0x7c8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5850
movq %rax, -0x138(%rbp)
cmpq $-0x1, -0x138(%rbp)
je 0xe151
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0xed42(%rip), %rsi      # 0x1c8d6
callq 0x5830
movq -0x7c8(%rbp), %rsi
movq %rax, -0x140(%rbp)
movq -0x138(%rbp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq -0x140(%rbp), %rcx
subq %rax, %rcx
incq %rcx
leaq -0x160(%rbp), %rdi
callq 0x5450
jmp 0xdbd0
leaq -0x130(%rbp), %rdi
leaq -0x160(%rbp), %rsi
movq %rsi, -0x7f8(%rbp)
callq 0x5510
movq -0x7f8(%rbp), %rdi
callq 0x52a0
leaq -0x2e8(%rbp), %rdi
callq 0x52f0
jmp 0xdc04
leaq -0x2d8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x53f0
jmp 0xdc19
leaq -0x2e8(%rbp), %rdi
leaq -0x2e9(%rbp), %rsi
callq 0x5580
jmp 0xdc2e
movsbl -0x2e9(%rbp), %eax
cmpl $0x28, %eax
je 0xdcf1
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe86f(%rip), %rsi      # 0x1c4c3
callq 0x55a0
jmp 0xdc5b
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe101
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x52a0
jmp 0xf0fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x109(%rbp), %rdi
callq 0x54a0
jmp 0xf0fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xf0e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xe140
movl $0x0, -0x2f4(%rbp)
movl $0x0, -0x2f8(%rbp)
leaq -0x2e8(%rbp), %rdi
leaq -0x2f4(%rbp), %rsi
callq 0x5290
jmp 0xdd1a
leaq -0x2e8(%rbp), %rdi
leaq -0x2e9(%rbp), %rsi
callq 0x5580
jmp 0xdd2f
movsbl -0x2e9(%rbp), %eax
cmpl $0x2c, %eax
je 0xdd7a
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe772(%rip), %rsi      # 0x1c4c3
callq 0x55a0
jmp 0xdd58
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe101
leaq -0x2e8(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x5290
jmp 0xdd8f
leaq -0x2e8(%rbp), %rdi
leaq -0x2e9(%rbp), %rsi
callq 0x5580
jmp 0xdda4
movsbl -0x2e9(%rbp), %eax
cmpl $0x29, %eax
je 0xddef
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe6fd(%rip), %rsi      # 0x1c4c3
callq 0x55a0
jmp 0xddcd
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe101
cmpl $0x0, -0x2f8(%rbp)
je 0xde01
cmpl $0x0, -0x2f4(%rbp)
jne 0xde40
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe6ac(%rip), %rsi      # 0x1c4c3
callq 0x55a0
jmp 0xde1e
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe101
movq -0x7d0(%rbp), %rax
addq $0x88, %rax
movq %rax, -0x808(%rbp)
leaq -0x2f4(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x9200
movq %rax, -0x800(%rbp)
jmp 0xde70
movq -0x808(%rbp), %rdi
movq -0x800(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x300(%rbp), %rsi
callq 0x9550
movb %dl, -0x811(%rbp)
movq %rax, -0x810(%rbp)
jmp 0xdea0
movq -0x7d0(%rbp), %rax
movb -0x811(%rbp), %cl
movq -0x810(%rbp), %rdx
movq %rdx, -0x310(%rbp)
movb %cl, -0x308(%rbp)
movq $0x0, -0x318(%rbp)
movq $0x0, -0x320(%rbp)
movq 0x38(%rax), %rdi
movl -0x2f4(%rbp), %esi
movl -0x2f8(%rbp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq %rax, -0x820(%rbp)
jmp 0xdef9
movq -0x820(%rbp), %rax
movq %rax, -0x320(%rbp)
movq -0x320(%rbp), %rdi
callq 0x7920
movl %eax, -0x824(%rbp)
jmp 0xdf1b
movl -0x824(%rbp), %eax
movq -0x7d0(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0xe010
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe593(%rip), %rsi      # 0x1c4da
callq 0x55a0
jmp 0xdf4e
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe101
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe140
movq -0xe0(%rbp), %rdi
movq %rdi, -0x830(%rbp)
callq 0x5540
movq %rax, %rsi
leaq -0x330(%rbp), %rdi
callq 0x57a0
movq -0x830(%rbp), %rdi
callq 0x5180
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe535(%rip), %rsi      # 0x1c50e
callq 0x55a0
jmp 0xdfe0
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xe061
movq -0x320(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movsd %xmm0, -0x838(%rbp)
jmp 0xe02a
movsd -0x838(%rbp), %xmm0
movsd %xmm0, -0x318(%rbp)
jmp 0xe06b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xe066
jmp 0xe101
jmp 0xe140
movq -0x138(%rbp), %rcx
movq %rcx, -0x848(%rbp)
movq -0x140(%rbp), %rax
subq %rcx, %rax
incq %rax
movq %rax, -0x840(%rbp)
movsd -0x318(%rbp), %xmm0
leaq -0x350(%rbp), %rdi
callq 0xf260
jmp 0xe0a3
movq -0x840(%rbp), %rdx
movq -0x848(%rbp), %rsi
movq -0x7c8(%rbp), %rdi
leaq -0x350(%rbp), %rcx
callq 0x5140
jmp 0xe0c6
leaq -0x350(%rbp), %rdi
callq 0x52a0
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
addq $0x1, %rdx
leaq -0x108(%rbp), %rsi
callq 0x5850
movq %rax, -0x138(%rbp)
movl $0x0, -0x2f0(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x5320
movl -0x2f0(%rbp), %eax
testl %eax, %eax
jne 0xf0ba
jmp 0xe11d
jmp 0xdb71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x52a0
leaq -0x2e8(%rbp), %rdi
callq 0x5320
jmp 0xf0e2
leaq 0xe3e7(%rip), %rsi      # 0x1c53f
leaq -0x108(%rbp), %rdi
callq 0x55a0
jmp 0xe166
movq -0x7c8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5850
movq %rax, -0x138(%rbp)
cmpq $-0x1, -0x138(%rbp)
je 0xe8d9
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0xe72f(%rip), %rsi      # 0x1c8d6
callq 0x5830
movq -0x7c8(%rbp), %rsi
movq %rax, -0x358(%rbp)
movq -0x138(%rbp), %rax
movq %rax, %rdx
addq $0x3, %rdx
movq -0x358(%rbp), %rcx
subq %rax, %rcx
incq %rcx
leaq -0x378(%rbp), %rdi
callq 0x5450
jmp 0xe1e3
leaq -0x130(%rbp), %rdi
leaq -0x378(%rbp), %rsi
movq %rsi, -0x850(%rbp)
callq 0x5510
movq -0x850(%rbp), %rdi
callq 0x52a0
leaq -0x500(%rbp), %rdi
callq 0x52f0
jmp 0xe217
leaq -0x4f0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x53f0
jmp 0xe22c
leaq -0x500(%rbp), %rdi
leaq -0x501(%rbp), %rsi
callq 0x5580
jmp 0xe241
movsbl -0x501(%rbp), %eax
cmpl $0x28, %eax
je 0xe2a3
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe2e0(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe26a
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xe8c8
movl $0x0, -0x508(%rbp)
movl $0x0, -0x50c(%rbp)
movl $0x0, -0x510(%rbp)
movl $0x0, -0x514(%rbp)
leaq -0x500(%rbp), %rdi
leaq -0x508(%rbp), %rsi
callq 0x5290
jmp 0xe2e0
leaq -0x500(%rbp), %rdi
leaq -0x501(%rbp), %rsi
callq 0x5580
jmp 0xe2f5
movsbl -0x501(%rbp), %eax
cmpl $0x2c, %eax
je 0xe340
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe22c(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe31e
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
leaq -0x500(%rbp), %rdi
leaq -0x50c(%rbp), %rsi
callq 0x5290
jmp 0xe355
leaq -0x500(%rbp), %rdi
leaq -0x501(%rbp), %rsi
callq 0x5580
jmp 0xe36a
movsbl -0x501(%rbp), %eax
cmpl $0x3a, %eax
je 0xe3b5
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe1b7(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe393
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
leaq -0x500(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0x5290
jmp 0xe3ca
leaq -0x500(%rbp), %rdi
leaq -0x501(%rbp), %rsi
callq 0x5580
jmp 0xe3df
movsbl -0x501(%rbp), %eax
cmpl $0x2c, %eax
je 0xe42a
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe142(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe408
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
leaq -0x500(%rbp), %rdi
leaq -0x514(%rbp), %rsi
callq 0x5290
jmp 0xe43f
leaq -0x500(%rbp), %rdi
leaq -0x501(%rbp), %rsi
callq 0x5580
jmp 0xe454
movsbl -0x501(%rbp), %eax
cmpl $0x29, %eax
je 0xe49f
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe0cd(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe47d
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
cmpl $0x0, -0x50c(%rbp)
je 0xe4c3
cmpl $0x0, -0x508(%rbp)
je 0xe4c3
cmpl $0x0, -0x510(%rbp)
je 0xe4c3
cmpl $0x0, -0x514(%rbp)
jne 0xe502
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xe06a(%rip), %rsi      # 0x1c543
callq 0x55a0
jmp 0xe4e0
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
movl -0x508(%rbp), %eax
cmpl -0x510(%rbp), %eax
jle 0xe534
movl -0x510(%rbp), %eax
movl %eax, -0x518(%rbp)
movl -0x508(%rbp), %eax
movl %eax, -0x510(%rbp)
movl -0x518(%rbp), %eax
movl %eax, -0x508(%rbp)
movl -0x50c(%rbp), %eax
cmpl -0x514(%rbp), %eax
jle 0xe566
movl -0x514(%rbp), %eax
movl %eax, -0x51c(%rbp)
movl -0x50c(%rbp), %eax
movl %eax, -0x514(%rbp)
movl -0x51c(%rbp), %eax
movl %eax, -0x50c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x528(%rbp)
movl -0x508(%rbp), %eax
movl %eax, -0x52c(%rbp)
movl -0x52c(%rbp), %eax
cmpl -0x510(%rbp), %eax
jg 0xe7c4
movl -0x50c(%rbp), %eax
movl %eax, -0x530(%rbp)
movl -0x530(%rbp), %eax
cmpl -0x514(%rbp), %eax
jg 0xe7ae
movq -0x7d0(%rbp), %rax
addq $0x88, %rax
movq %rax, -0x860(%rbp)
leaq -0x52c(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0x9200
movq %rax, -0x858(%rbp)
jmp 0xe5dd
movq -0x860(%rbp), %rdi
movq -0x858(%rbp), %rax
movq %rax, -0x538(%rbp)
leaq -0x538(%rbp), %rsi
callq 0x9550
movb %dl, -0x869(%rbp)
movq %rax, -0x868(%rbp)
jmp 0xe60d
movq -0x7d0(%rbp), %rax
movb -0x869(%rbp), %cl
movq -0x868(%rbp), %rdx
movq %rdx, -0x548(%rbp)
movb %cl, -0x540(%rbp)
movq $0x0, -0x550(%rbp)
movq 0x38(%rax), %rdi
movl -0x52c(%rbp), %esi
movl -0x530(%rbp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq %rax, -0x878(%rbp)
jmp 0xe65b
movq -0x878(%rbp), %rax
movq %rax, -0x550(%rbp)
movq -0x550(%rbp), %rdi
callq 0x7920
movl %eax, -0x87c(%rbp)
jmp 0xe67d
movl -0x87c(%rbp), %eax
movq -0x7d0(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0xe750
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xdeb0(%rip), %rsi      # 0x1c559
callq 0x55a0
jmp 0xe6b0
jmp 0xe782
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe8c8
movq -0xe0(%rbp), %rdi
movq %rdi, -0x888(%rbp)
callq 0x5540
movq %rax, %rsi
leaq -0x560(%rbp), %rdi
callq 0x57a0
movq -0x888(%rbp), %rdi
callq 0x5180
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xddf0(%rip), %rsi      # 0x1c50e
callq 0x55a0
jmp 0xe725
leaq -0x560(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xe738
jmp 0xe73a
jmp 0xe73c
movl -0x530(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x530(%rbp)
jmp 0xe59b
movq -0x550(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movsd %xmm0, -0x890(%rbp)
jmp 0xe76a
movsd -0x890(%rbp), %xmm0
addsd -0x528(%rbp), %xmm0
movsd %xmm0, -0x528(%rbp)
jmp 0xe73a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x560(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xe7a9
jmp 0xe8c8
jmp 0xe7b0
movl -0x52c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x52c(%rbp)
jmp 0xe57d
movq -0x7d0(%rbp), %rax
testb $0x1, 0x58(%rax)
je 0xe7f3
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xe889
movq -0x138(%rbp), %rcx
movq %rcx, -0x8a0(%rbp)
movq -0x358(%rbp), %rax
subq %rcx, %rax
incq %rax
movq %rax, -0x898(%rbp)
movsd -0x528(%rbp), %xmm0
leaq -0x580(%rbp), %rdi
callq 0xf260
jmp 0xe82b
movq -0x898(%rbp), %rdx
movq -0x8a0(%rbp), %rsi
movq -0x7c8(%rbp), %rdi
leaq -0x580(%rbp), %rcx
callq 0x5140
jmp 0xe84e
leaq -0x580(%rbp), %rdi
callq 0x52a0
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
addq $0x1, %rdx
leaq -0x108(%rbp), %rsi
callq 0x5850
movq %rax, -0x138(%rbp)
movl $0x0, -0x2f0(%rbp)
leaq -0x500(%rbp), %rdi
callq 0x5320
movl -0x2f0(%rbp), %eax
testl %eax, %eax
jne 0xf0ba
jmp 0xe8a5
jmp 0xe184
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x580(%rbp), %rdi
callq 0x52a0
leaq -0x500(%rbp), %rdi
callq 0x5320
jmp 0xf0e2
leaq 0xdcac(%rip), %rsi      # 0x1c58c
leaq -0x108(%rbp), %rdi
callq 0x55a0
jmp 0xe8ee
movq -0x7c8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5850
movq %rax, -0x138(%rbp)
cmpq $-0x1, -0x138(%rbp)
je 0xf09d
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0xdfa7(%rip), %rsi      # 0x1c8d6
callq 0x5830
movq -0x7c8(%rbp), %rsi
movq %rax, -0x588(%rbp)
movq -0x138(%rbp), %rax
movq %rax, %rdx
addq $0x3, %rdx
movq -0x588(%rbp), %rcx
subq %rax, %rcx
incq %rcx
leaq -0x5a8(%rbp), %rdi
callq 0x5450
jmp 0xe96b
leaq -0x130(%rbp), %rdi
leaq -0x5a8(%rbp), %rsi
movq %rsi, -0x8a8(%rbp)
callq 0x5510
movq -0x8a8(%rbp), %rdi
callq 0x52a0
leaq -0x730(%rbp), %rdi
callq 0x52f0
jmp 0xe99f
leaq -0x720(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x53f0
jmp 0xe9b4
leaq -0x730(%rbp), %rdi
leaq -0x731(%rbp), %rsi
callq 0x5580
jmp 0xe9c9
movsbl -0x731(%rbp), %eax
cmpl $0x28, %eax
je 0xea2b
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xdba5(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xe9f2
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xf08f
movl $0x0, -0x738(%rbp)
movl $0x0, -0x73c(%rbp)
movl $0x0, -0x740(%rbp)
movl $0x0, -0x744(%rbp)
leaq -0x730(%rbp), %rdi
leaq -0x738(%rbp), %rsi
callq 0x5290
jmp 0xea68
leaq -0x730(%rbp), %rdi
leaq -0x731(%rbp), %rsi
callq 0x5580
jmp 0xea7d
movsbl -0x731(%rbp), %eax
cmpl $0x2c, %eax
je 0xeac8
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xdaf1(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xeaa6
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
leaq -0x730(%rbp), %rdi
leaq -0x73c(%rbp), %rsi
callq 0x5290
jmp 0xeadd
leaq -0x730(%rbp), %rdi
leaq -0x731(%rbp), %rsi
callq 0x5580
jmp 0xeaf2
movsbl -0x731(%rbp), %eax
cmpl $0x3a, %eax
je 0xeb3d
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xda7c(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xeb1b
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
leaq -0x730(%rbp), %rdi
leaq -0x740(%rbp), %rsi
callq 0x5290
jmp 0xeb52
leaq -0x730(%rbp), %rdi
leaq -0x731(%rbp), %rsi
callq 0x5580
jmp 0xeb67
movsbl -0x731(%rbp), %eax
cmpl $0x2c, %eax
je 0xebb2
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xda07(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xeb90
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
leaq -0x730(%rbp), %rdi
leaq -0x744(%rbp), %rsi
callq 0x5290
jmp 0xebc7
leaq -0x730(%rbp), %rdi
leaq -0x731(%rbp), %rsi
callq 0x5580
jmp 0xebdc
movsbl -0x731(%rbp), %eax
cmpl $0x29, %eax
je 0xec27
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xd992(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xec05
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
cmpl $0x0, -0x73c(%rbp)
je 0xec4b
cmpl $0x0, -0x738(%rbp)
je 0xec4b
cmpl $0x0, -0x740(%rbp)
je 0xec4b
cmpl $0x0, -0x744(%rbp)
jne 0xec8a
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xd92f(%rip), %rsi      # 0x1c590
callq 0x55a0
jmp 0xec68
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
movl -0x738(%rbp), %eax
cmpl -0x740(%rbp), %eax
jle 0xecbc
movl -0x740(%rbp), %eax
movl %eax, -0x748(%rbp)
movl -0x738(%rbp), %eax
movl %eax, -0x740(%rbp)
movl -0x748(%rbp), %eax
movl %eax, -0x738(%rbp)
movl -0x73c(%rbp), %eax
cmpl -0x744(%rbp), %eax
jle 0xecee
movl -0x744(%rbp), %eax
movl %eax, -0x74c(%rbp)
movl -0x73c(%rbp), %eax
movl %eax, -0x744(%rbp)
movl -0x74c(%rbp), %eax
movl %eax, -0x73c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x758(%rbp)
movl -0x738(%rbp), %eax
movl %eax, -0x75c(%rbp)
movl -0x75c(%rbp), %eax
cmpl -0x740(%rbp), %eax
jg 0xef4c
movl -0x73c(%rbp), %eax
movl %eax, -0x760(%rbp)
movl -0x760(%rbp), %eax
cmpl -0x744(%rbp), %eax
jg 0xef36
movq -0x7d0(%rbp), %rax
addq $0x88, %rax
movq %rax, -0x8b8(%rbp)
leaq -0x75c(%rbp), %rdi
leaq -0x760(%rbp), %rsi
callq 0x9200
movq %rax, -0x8b0(%rbp)
jmp 0xed65
movq -0x8b8(%rbp), %rdi
movq -0x8b0(%rbp), %rax
movq %rax, -0x768(%rbp)
leaq -0x768(%rbp), %rsi
callq 0x9550
movb %dl, -0x8c1(%rbp)
movq %rax, -0x8c0(%rbp)
jmp 0xed95
movq -0x7d0(%rbp), %rax
movb -0x8c1(%rbp), %cl
movq -0x8c0(%rbp), %rdx
movq %rdx, -0x778(%rbp)
movb %cl, -0x770(%rbp)
movq $0x0, -0x780(%rbp)
movq 0x38(%rax), %rdi
movl -0x75c(%rbp), %esi
movl -0x760(%rbp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq %rax, -0x8d0(%rbp)
jmp 0xede3
movq -0x8d0(%rbp), %rax
movq %rax, -0x780(%rbp)
movq -0x780(%rbp), %rdi
callq 0x7920
movl %eax, -0x8d4(%rbp)
jmp 0xee05
movl -0x8d4(%rbp), %eax
movq -0x7d0(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0xeed8
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xd775(%rip), %rsi      # 0x1c5a6
callq 0x55a0
jmp 0xee38
jmp 0xef0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xf08f
movq -0xe0(%rbp), %rdi
movq %rdi, -0x8e0(%rbp)
callq 0x5540
movq %rax, %rsi
leaq -0x790(%rbp), %rdi
callq 0x57a0
movq -0x8e0(%rbp), %rdi
callq 0x5180
movq -0x7d0(%rbp), %rdi
movb $0x1, 0x58(%rdi)
addq $0x60, %rdi
leaq 0xd668(%rip), %rsi      # 0x1c50e
callq 0x55a0
jmp 0xeead
leaq -0x790(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xeec0
jmp 0xeec2
jmp 0xeec4
movl -0x760(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x760(%rbp)
jmp 0xed23
movq -0x780(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movsd %xmm0, -0x8e8(%rbp)
jmp 0xeef2
movsd -0x8e8(%rbp), %xmm0
addsd -0x758(%rbp), %xmm0
movsd %xmm0, -0x758(%rbp)
jmp 0xeec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x790(%rbp), %rdi
callq 0x5878
callq 0x5690
jmp 0xef31
jmp 0xf08f
jmp 0xef38
movl -0x75c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x75c(%rbp)
jmp 0xed05
movq -0x7d0(%rbp), %rax
testb $0x1, 0x58(%rax)
je 0xef7b
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
jmp 0xf054
movl -0x740(%rbp), %eax
movl -0x738(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0x794(%rbp)
movl -0x744(%rbp), %eax
movl -0x73c(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0x798(%rbp)
movq -0x138(%rbp), %rcx
movq %rcx, -0x8f8(%rbp)
movq -0x588(%rbp), %rax
subq %rcx, %rax
incq %rax
movq %rax, -0x8f0(%rbp)
movsd -0x758(%rbp), %xmm0
movl -0x794(%rbp), %eax
movl -0x798(%rbp), %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
leaq -0x7b8(%rbp), %rdi
callq 0xf260
jmp 0xeff6
movq -0x8f0(%rbp), %rdx
movq -0x8f8(%rbp), %rsi
movq -0x7c8(%rbp), %rdi
leaq -0x7b8(%rbp), %rcx
callq 0x5140
jmp 0xf019
leaq -0x7b8(%rbp), %rdi
callq 0x52a0
movq -0x7c8(%rbp), %rdi
movq -0x138(%rbp), %rdx
addq $0x1, %rdx
leaq -0x108(%rbp), %rsi
callq 0x5850
movq %rax, -0x138(%rbp)
movl $0x0, -0x2f0(%rbp)
leaq -0x730(%rbp), %rdi
callq 0x5320
movl -0x2f0(%rbp), %eax
testl %eax, %eax
jne 0xf0ba
jmp 0xf06c
jmp 0xe90c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x7b8(%rbp), %rdi
callq 0x52a0
leaq -0x730(%rbp), %rdi
callq 0x5320
jmp 0xf0e2
movq -0x7c8(%rbp), %rsi
movq -0x7e0(%rbp), %rdi
callq 0x5270
movl $0x1, -0x2f0(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x52a0
leaq -0x108(%rbp), %rdi
callq 0x52a0
movq -0x7d8(%rbp), %rax
addq $0x900, %rsp            # imm = 0x900
popq %rbp
retq
leaq -0x130(%rbp), %rdi
callq 0x52a0
leaq -0x108(%rbp), %rdi
callq 0x52a0
movq -0xe0(%rbp), %rdi
callq 0x5730
movq %rax, %rdi
callq 0x7670
nop