// File: /workspace/github_cpp_makefile_star2_O3/cjc12[P]ezSTL/src/../include/algorithm.h
// Function: void ezSTL::__heap_sort<unsigned int*, ezSTL::less<unsigned int>>(unsigned int*, unsigned int*, ezSTL::less<unsigned int>)
inline void __heap_sort(Iterator First, Iterator Last, Compare cmp) {
		Iterator now, left, right;
		// make heap
		for (Iterator ite = (Last - First - 1) / 2 + First; ite >= First; --ite) {
			now = ite;
			left = First + (now - First) * 2 + 1;
			right = First + (now - First) * 2 + 2;
			// if has both left and right children
			while (right < Last) {
				// exchange father and left
				if (!cmp(*left, *right) && cmp(*now, *left)) {
					swap(*left, *now);
					now = left;
					left = First + (now - First) * 2 + 1;
					right = First + (now - First) * 2 + 2;
				}
				// exchange father and right
				else if (!cmp(*right, *left) && cmp(*now, *right)) {
					swap(*right, *now);
					now = right;
					left = First + (now - First) * 2 + 1;
					right = First + (now - First) * 2 + 2;
				}
				else break;
			}
			// if only has left child
			if (right == Last && cmp(*now, *left))
				swap(*left, *now);
		}
		// heap sort
		for (Iterator ite = Last - 1; ite >= First; --ite) {
			swap(*First, *ite);
			now = First;
			left = First + 1;
			right = First + 2;
			// if has both left and right children
			while (right < ite) {
				// exchange father and left
				if (!cmp(*left, *right) && cmp(*now, *left)) {
					swap(*left, *now);
					now = left;
					left = First + (now - First) * 2 + 1;
					right = First + (now - First) * 2 + 2;
				}
				// exchange father and right
				else if (!cmp(*right, *left) && cmp(*now, *right)) {
					swap(*right, *now);
					now = right;
					left = First + (now - First) * 2 + 1;
					right = First + (now - First) * 2 + 2;
				}
				else break;
			}
			// if only has left child
			if (right == ite && cmp(*now, *left))
				swap(*left, *now);
		}
	}

// Assembly:
pushq %rbx
movq %rsi, %rax
subq %rdi, %rax
sarq $0x2, %rax
js 0xc66c
leaq -0x1(%rax), %rcx
shrq $0x3f, %rcx
addq %rcx, %rax
decq %rax
andq $-0x2, %rax
leaq (%rdi,%rax,2), %rax
movq %rax, %rcx
subq %rdi, %rcx
leaq (%rdi,%rcx,2), %rdx
addq $0x8, %rdx
leaq (%rdi,%rcx,2), %rcx
addq $0x4, %rcx
movq %rax, %r8
movq %rax, %r9
cmpq %rsi, %rdx
jae 0xc64a
movl (%rcx), %r10d
movl (%rdx), %r9d
cmpl %r9d, %r10d
jb 0xc613
movl (%r8), %r11d
cmpl %r10d, %r11d
jae 0xc613
movl %r11d, (%rcx)
jmp 0xc629
cmpl %r10d, %r9d
jb 0xc647
movl (%r8), %r10d
cmpl %r9d, %r10d
jae 0xc647
movl %r10d, (%rdx)
movl %r9d, %r10d
movq %rdx, %rcx
movq %rcx, %r9
movl %r10d, (%r8)
subq %rdi, %rcx
leaq (%rdi,%rcx,2), %rdx
addq $0x8, %rdx
leaq (%rdi,%rcx,2), %rcx
addq $0x4, %rcx
movq %r9, %r8
jmp 0xc5f6
movq %r8, %r9
cmpq %rsi, %rdx
jne 0xc65f
movl (%r9), %edx
movl (%rcx), %r8d
cmpl %r8d, %edx
jae 0xc65f
movl %edx, (%rcx)
movl %r8d, (%r9)
addq $-0x4, %rax
cmpq %rdi, %rax
jae 0xc5da
addq $-0x4, %rsi
cmpq %rdi, %rsi
jb 0xc718
leaq 0x8(%rdi), %rax
leaq 0x4(%rdi), %rcx
movl (%rdi), %edx
movl (%rsi), %r8d
movl %r8d, (%rdi)
movl %edx, (%rsi)
movq %rdi, %r9
movq %rax, %r8
movq %rcx, %rdx
cmpq %rsi, %rax
jae 0xc6f5
movq %rcx, %rdx
movq %rax, %r8
movq %rdi, %r10
movl (%rdx), %r11d
movl (%r8), %r9d
cmpl %r9d, %r11d
jb 0xc6b9
movl (%r10), %ebx
cmpl %r11d, %ebx
jae 0xc6b9
movl %ebx, (%rdx)
jmp 0xc6cf
cmpl %r11d, %r9d
jb 0xc6f2
movl (%r10), %r11d
cmpl %r9d, %r11d
jae 0xc6f2
movl %r11d, (%r8)
movl %r9d, %r11d
movq %r8, %rdx
movq %rdx, %r9
movl %r11d, (%r10)
subq %rdi, %rdx
leaq (%rdi,%rdx,2), %r8
addq $0x8, %r8
leaq (%rdi,%rdx,2), %rdx
addq $0x4, %rdx
movq %r9, %r10
cmpq %rsi, %r8
jb 0xc6a2
jmp 0xc6f5
movq %r10, %r9
cmpq %rsi, %r8
jne 0xc70b
movl (%r9), %r8d
movl (%rdx), %r10d
cmpl %r10d, %r8d
jae 0xc70b
movl %r8d, (%rdx)
movl %r10d, (%r9)
addq $-0x4, %rsi
cmpq %rdi, %rsi
jae 0xc681
popq %rbx
retq