// File: aydarbiktimirov[P]data-structures/src/include/persistent-segment-tree.h
// Function: void CPersistentSegmentTree<int, std::plus<int>>::BuildTree<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>>(unsigned long, unsigned long, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>&, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>>>)
void CPersistentSegmentTree<T, Operation>::BuildTree(size_t current, size_t current_depth_count, InputIterator &from, InputIterator to)
{ // построение поддерева, аналогично построению в эфемерном дереве отрезков
	values.resize(std::max(values.size(), current + 1));

	if (current_depth_count >= element_count)
	{
		if (values_first_index == (size_t)-1)
		{
			values_first_index = current;
		}

		if (from != to)
		{
			values[current] = CNode(*(from++));
		} else {
			values[current] = CNode(default_value);
		}
	} else {
		size_t left = 2 * current + 1;
		size_t right = 2 * current + 2;

		BuildTree(left, current_depth_count * 2, from, to);
		BuildTree(right, current_depth_count * 2, from, to);

		values[current] = CNode(Operation()(values[left].value, values[right].value), left, right);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %r8, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
movq %rdi, %rax
addq $0x30, %rax
movq %rax, -0xc0(%rbp)
addq $0x30, %rdi
callq 0x49b0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4970
movq -0xc0(%rbp), %rdi
movq (%rax), %rsi
callq 0x48e0
movq -0xb8(%rbp), %rcx
movq -0x20(%rbp), %rax
cmpq 0x20(%rcx), %rax
jb 0x416b
movq -0xb8(%rbp), %rax
cmpq $-0x1, 0x28(%rax)
jne 0x40af
movq -0xb8(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x49e0
testb $0x1, %al
jne 0x40c2
jmp 0x411d
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x4a20
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4a60
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
movq $-0x1, %rcx
movq %rcx, %rdx
callq 0x4a80
movq -0xb8(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x4ac0
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x4166
movq -0xb8(%rbp), %rsi
addq $0x60, %rsi
leaq -0x70(%rbp), %rdi
movq $-0x1, %rcx
movq %rcx, %rdx
callq 0x4a80
movq -0xb8(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x4ac0
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x427d
movq -0xb8(%rbp), %rdi
movq -0x18(%rbp), %rax
shlq %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
shlq %rax
addq $0x2, %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rsi
movq -0x20(%rbp), %rdx
shlq %rdx
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %r8
callq 0x4010
movq -0xb8(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x20(%rbp), %rdx
shlq %rdx
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %r8
callq 0x4010
movq -0xb8(%rbp), %rdi
addq $0x30, %rdi
movq -0x78(%rbp), %rsi
callq 0x4ac0
movq -0xb8(%rbp), %rdi
movq %rax, -0xc8(%rbp)
addq $0x30, %rdi
movq -0x80(%rbp), %rsi
callq 0x4ac0
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
leaq -0xad(%rbp), %rdi
callq 0x4ae0
movl %eax, -0xac(%rbp)
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x4a80
movq -0xb8(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x4ac0
movq -0xa8(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa0(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x10(%rax)
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)