// File: /workspace/github_cpp_makefile_star2_O1/havluj[P]spreadsheet/src/CTable.cpp
// Function: CTable::updateElement(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void CTable::updateElement(int row, int col, std::string value) {
    std::set<std::pair<int, int>> affectedBy;

    auto it = m_database.find(std::make_pair(row, col));
    if (it == m_database.end()) {
	  CCell* newCell;
	  if (value.length() > 0 && value.at(0) == '=') {
		newCell = new CEquation(this);
	  } else {
		newCell = new CText();
	  }
	  newCell->setId(m_idCounter++);
	  m_database.insert(std::make_pair(std::make_pair(row, col), newCell));
	  affectedBy = newCell->update(value);
    } else {
	  delete it->second;

	  CCell* newCell;
	  if (value.length() > 0 && value.at(0) == '=') {
		newCell = new CEquation(this);
	  } else {
		newCell = new CText();
	  }
	  newCell->setId(m_idCounter++);
	  m_database[std::make_pair(row, col)] = newCell;
	  affectedBy = newCell->update(value);
    }

    // create the affecting relationships
    if (affectedBy.size() > 0) {
	  for (auto i = affectedBy.begin(); i != affectedBy.end(); ++i) {
		auto relIt = m_relationships.find(*i);
		if (relIt == m_relationships.end()) {
		    /* create new entry */
		    std::set<std::pair<int, int>> tmp;
		    tmp.insert(std::make_pair(row, col));
		    m_relationships.insert(std::make_pair(std::make_pair(i->first, i->second), tmp));
		} else {
		    /* expand the set */
		    relIt->second.insert(std::make_pair(row, col));
		}
	  }
    }

    auto recalcIt = m_relationships.find(std::make_pair(row, col));
    if (recalcIt != m_relationships.end()) {
	  for (auto i = recalcIt->second.begin(); i != recalcIt->second.end(); ++i) {
		reCompute((*i).first, (*i).second);
	  }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rcx, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x38(%rdi), %r15
shlq $0x20, %rdx
movl %esi, %eax
orq %rdx, %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x8(%rsp)
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x61a6
leaq 0x40(%rbx), %rcx
cmpq %rcx, %rax
je 0x5971
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x5860
movq (%rdi), %rax
callq *0x8(%rax)
cmpq $0x0, 0x8(%r14)
je 0x5889
movq (%r14), %rax
cmpb $0x3d, (%rax)
jne 0x5889
movl $0xb8, %edi
callq 0x42c0
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6a14
jmp 0x589e
movl $0x30, %edi
callq 0x42c0
movq %rax, %r12
movq %rax, %rdi
callq 0x6988
movl 0x68(%rbx), %esi
leal 0x1(%rsi), %eax
movl %eax, 0x68(%rbx)
movq %r12, %rdi
callq 0x5310
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x5eaa
movq %r12, (%rax)
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x5370
movq (%r12), %rax
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
movq %r12, %rsi
callq *0x10(%rax)
leaq 0x10(%rsp), %rdi
callq 0x5fe0
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x594c
leaq 0x48(%rsp), %rcx
movl (%rcx), %edx
movl %edx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movups 0x10(%rcx), %xmm0
movups %xmm0, 0x28(%rsp)
leaq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rax)
movq 0x20(%rcx), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x40(%rsp), %rdi
callq 0x5320
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a8b
movq 0x88(%rsp), %rsi
jmp 0x5a83
cmpq $0x0, 0x8(%r14)
je 0x599a
movq (%r14), %rax
cmpb $0x3d, (%rax)
jne 0x599a
movl $0xb8, %edi
callq 0x42c0
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6a14
jmp 0x59af
movl $0x30, %edi
callq 0x42c0
movq %rax, %r12
movq %rax, %rdi
callq 0x6988
movl 0x68(%rbx), %esi
leal 0x1(%rsi), %eax
movl %eax, 0x68(%rbx)
movq %r12, %rdi
callq 0x5310
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
movq %r12, 0x8(%rsi)
movq %r15, %rdi
callq 0x620e
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x5370
movq (%r12), %rax
leaq 0x40(%rsp), %rdi
leaq 0x98(%rsp), %rdx
movq %r12, %rsi
callq *0x10(%rax)
leaq 0x10(%rsp), %rdi
callq 0x5fe0
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x5a64
leaq 0x48(%rsp), %rcx
movl (%rcx), %edx
movl %edx, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movups 0x10(%rcx), %xmm0
movups %xmm0, 0x28(%rsp)
leaq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rax)
movq 0x20(%rcx), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x40(%rsp), %rdi
callq 0x5320
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a8b
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpq $0x0, 0x38(%rsp)
je 0x5b81
movq 0x28(%rsp), %r15
leaq 0x18(%rsp), %rax
cmpq %rax, %r15
je 0x5b81
leaq 0x8(%rbx), %r12
leaq 0x10(%rbx), %r14
leaq 0xb8(%rsp), %r13
leaq 0x40(%rsp), %rbp
leaq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x6546
cmpq %r14, %rax
je 0x5aeb
addq $0x28, %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x65ae
jmp 0x5b68
movl $0x0, 0xc0(%rsp)
xorl %ecx, %ecx
movq %rcx, 0xc8(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
movq %rcx, 0xe0(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x65ae
movq 0x20(%r15), %rax
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x600e
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6702
leaq 0x48(%rsp), %rdi
callq 0x5320
movq %r13, %rdi
callq 0x5320
movq %r15, %rdi
callq 0x4350
movq %rax, %r15
leaq 0x18(%rsp), %rax
cmpq %rax, %r15
jne 0x5abf
leaq 0x8(%rbx), %rdi
leaq 0x40(%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
callq 0x6546
movq %rax, %r14
leaq 0x10(%rbx), %rax
cmpq %rax, %r14
je 0x5bd1
movq 0x40(%r14), %r15
addq $0x30, %r14
cmpq %r14, %r15
je 0x5bd1
movl 0x20(%r15), %esi
movl 0x24(%r15), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r15, %rdi
callq 0x4350
movq %rax, %r15
cmpq %r14, %rax
jne 0x5bb0
leaq 0x10(%rsp), %rdi
callq 0x5320
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5bef
movq %rax, %rbx
movl $0xb8, %esi
jmp 0x5c21
jmp 0x5c19
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c7b
movq 0xa8(%rsp), %rsi
jmp 0x5c3b
jmp 0x5c78
jmp 0x5c78
movq %rax, %rbx
movl $0x30, %esi
movq %r12, %rdi
jmp 0x5c3e
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c7b
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x5c7b
jmp 0x5c78
jmp 0x5c78
jmp 0x5c78
jmp 0x5c78
jmp 0x5c78
jmp 0x5c78
jmp 0x5c62
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5320
jmp 0x5c65
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x5320
jmp 0x5c7b
jmp 0x5c78
jmp 0x5c78
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5320
movq %rbx, %rdi
callq 0x45a0
nop