// File: /workspace/github_cpp_makefile_star2_O1/aydarbiktimirov[P]data-structures/src/include/persistent-segment-tree.h
// Function: CPersistentSegmentTree<int, std::plus<int>>::AddBranch(unsigned long, int const&, unsigned long, unsigned long, unsigned long, unsigned long)
void CPersistentSegmentTree<T, Operation>::AddBranch(size_t changed_position, const T &changed_value, size_t previous, size_t current_depth_count, size_t left_bound, size_t right_bound)
{ // добавление новой ветки рекурсивно сверху вниз
	size_t new_node = values.size();
	values.push_back(CNode());

	if (current_depth_count >= element_count)
	{ // добрались до листа
		values[new_node] = CNode(changed_value);
	} else {
		size_t middle_bound = (left_bound + right_bound) / 2; // добавляем поддеревья в зависимости от того, которое из поддеревьев изменилось
		if (changed_position <= middle_bound)
		{
			values[new_node].left = values.size();
			values[new_node].right = values[previous].right;
			AddBranch(changed_position, changed_value, values[previous].left, 2 * current_depth_count, left_bound, middle_bound);
		} else {
			values[new_node].left = values[previous].left;
			values[new_node].right = values.size();
			AddBranch(changed_position, changed_value, values[previous].right, 2 * current_depth_count, middle_bound + 1, right_bound);
		}

		values[new_node].value = Operation()(values[values[new_node].left].value, values[values[new_node].right].value); // вычисление значения для новой вершины
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, %r14
movq %rdx, %rbp
movq %rsi, %r11
movq %rdi, %r13
leaq 0x30(%rdi), %rbx
movq 0x38(%rdi), %rsi
movq %rsi, %r15
subq 0x30(%rdi), %r15
movl $0x0, 0x20(%rsp)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x28(%rsp)
cmpq 0x40(%rdi), %rsi
je 0x3320
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsi)
movdqu 0x20(%rsp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x18, 0x38(%r13)
jmp 0x3347
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %rcx, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq %r11, %rbx
callq 0x355e
movq %rbx, %r11
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %rcx
cmpq %r14, 0x20(%r13)
jbe 0x33ab
movq 0x70(%rsp), %rax
leaq (%rax,%r12), %r9
shrq %r9
addq %r14, %r14
cmpq %r11, %r9
jae 0x33c2
movq 0x30(%r13), %r10
leaq (%rcx,%rcx,2), %rdx
movq 0x8(%r10,%rdx,8), %rsi
movq %rsi, 0x8(%r10,%r15)
movq 0x38(%r13), %rsi
subq %r10, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdi
movq %rdi, 0x10(%r10,%r15)
movq 0x10(%r10,%rdx,8), %rcx
incq %r9
movq %rax, (%rsp)
movq %r13, %rdi
movq %r11, %rsi
movq %rbp, %rdx
movq %r14, %r8
jmp 0x340a
movl (%rbp), %eax
movq (%rbx), %rcx
movl %eax, (%rcx,%r15)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x8(%rcx,%r15)
jmp 0x342e
movq 0x30(%r13), %rax
movq 0x38(%r13), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
movq %rdx, 0x8(%rax,%r15)
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rax,%r15)
movq 0x8(%rax,%rcx,8), %rcx
movq %r9, (%rsp)
movq %r13, %rdi
movq %r11, %rsi
movq %rbp, %rdx
movq %r14, %r8
movq %r12, %r9
callq 0x32c2
movq (%rbx), %rax
movq 0x8(%rax,%r15), %rcx
movq 0x10(%rax,%r15), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
movl (%rax,%rdx,8), %edx
addl (%rax,%rcx,8), %edx
movl %edx, (%rax,%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop