// File: Ripser[P]ripser/ripser.cpp
// Function: ripser<sparse_distance_matrix>::compute_pairs(std::vector<std::pair<float, long>, std::allocator<std::pair<float, long>>> const&, std::unordered_map<long, unsigned long, ripser<sparse_distance_matrix>::entry_hash, ripser<sparse_distance_matrix>::equal_index, std::allocator<std::pair<long const, unsigned long>>>&, long)
void compute_pairs(const std::vector<diameter_index_t>& columns_to_reduce,
	                   entry_hash_map& pivot_column_index, const index_t dim) {

#ifdef PRINT_PERSISTENCE_PAIRS
		std::cout << "persistence intervals in dim " << dim << ":" << std::endl;
#endif

		compressed_sparse_matrix<diameter_entry_t> reduction_matrix;
		
#ifdef INDICATE_PROGRESS
		std::chrono::steady_clock::time_point next = std::chrono::steady_clock::now() + time_step;
#endif
		for (size_t index_column_to_reduce = 0; index_column_to_reduce < columns_to_reduce.size();
		     ++index_column_to_reduce) {

			diameter_entry_t column_to_reduce(columns_to_reduce[index_column_to_reduce], 1);
			value_t diameter = get_diameter(column_to_reduce);

			reduction_matrix.append_column();

			std::priority_queue<diameter_entry_t, std::vector<diameter_entry_t>,
			                    greater_diameter_or_smaller_index_comp<diameter_entry_t>>
			    working_reduction_column, working_coboundary;

			diameter_entry_t e, pivot = init_coboundary_and_get_pivot(
			                        column_to_reduce, working_coboundary, dim, pivot_column_index);

			while (true) {
#ifdef INDICATE_PROGRESS
				if (std::chrono::steady_clock::now() > next) {
					std::cerr << clear_line << "reducing column " << index_column_to_reduce + 1
					          << "/" << columns_to_reduce.size() << " (diameter " << diameter << ")"
					          << std::flush;
					next = std::chrono::steady_clock::now() + time_step;
				}
#endif
				if (get_index(pivot) != -1) {
					auto pair = pivot_column_index.find(get_entry(pivot));
					if (pair != pivot_column_index.end()) {
						entry_t other_pivot = pair->first;
						index_t index_column_to_add = pair->second;
						coefficient_t factor =
						    modulus - get_coefficient(pivot) *
						                  multiplicative_inverse[get_coefficient(other_pivot)] %
						                  modulus;

						add_coboundary(reduction_matrix, columns_to_reduce, index_column_to_add,
						               factor, dim, working_reduction_column, working_coboundary);

						pivot = get_pivot(working_coboundary);
					} else if (get_index(e = get_zero_apparent_facet(pivot, dim + 1)) != -1) {
						set_coefficient(e, modulus - get_coefficient(e));

						add_simplex_coboundary(e, dim, working_reduction_column, working_coboundary);

						pivot = get_pivot(working_coboundary);
					} else {
#ifdef PRINT_PERSISTENCE_PAIRS
						value_t death = get_diameter(pivot);
						if (death > diameter * ratio) {
#ifdef INDICATE_PROGRESS
							std::cerr << clear_line << std::flush;
#endif
							std::cout << " [" << diameter << "," << death << ")" << std::endl;
						}
#endif
						pivot_column_index.insert({get_entry(pivot), index_column_to_reduce});

						while (true) {
							diameter_entry_t e = pop_pivot(working_reduction_column);
							if (get_index(e) == -1) break;
							assert(get_coefficient(e) > 0);
							reduction_matrix.push_back(e);
						}
						break;
					}
				} else {
#ifdef PRINT_PERSISTENCE_PAIRS
#ifdef INDICATE_PROGRESS
					std::cerr << clear_line << std::flush;
#endif
					std::cout << " [" << diameter << ", )" << std::endl;
#endif
					break;
				}
			}
		}
#ifdef INDICATE_PROGRESS
		std::cerr << clear_line << std::flush;
#endif
	}

// Assembly:
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rdi, 0x2b0(%rsp)
movq %rsi, 0x2a8(%rsp)
movq %rdx, 0x2a0(%rsp)
movq %rcx, 0x298(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x1d92a(%rip), %rdi     # 0x2efb8
leaq 0x10faf(%rip), %rsi     # 0x22644
callq 0x2230
movq %rax, %rdi
movq 0x298(%rsp), %rsi
callq 0x23d0
movq %rax, %rdi
leaq 0x10f82(%rip), %rsi     # 0x22636
callq 0x2230
movq %rax, %rdi
movq 0x1d8cd(%rip), %rsi     # 0x2ef90
callq 0x2250
leaq 0x268(%rsp), %rdi
callq 0x18f00
movq $0x0, 0x260(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0x2a8(%rsp), %rdi
callq 0xb370
movq %rax, %rcx
movq 0xf0(%rsp), %rax
cmpq %rcx, %rax
jae 0x11e7b
movq 0x2a8(%rsp), %rdi
movq 0x260(%rsp), %rsi
callq 0x18f30
movq %rax, %rsi
leaq 0x250(%rsp), %rdi
movl $0x1, %edx
callq 0x18f50
jmp 0x1173e
leaq 0x250(%rsp), %rdi
callq 0x2ab0
movss (%rax), %xmm0
movss %xmm0, 0x240(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x18fc0
jmp 0x11767
leaq 0x220(%rsp), %rdi
callq 0x19000
jmp 0x11776
leaq 0x200(%rsp), %rdi
callq 0x19000
jmp 0x11785
leaq 0x1f0(%rsp), %rdi
callq 0x161c0
jmp 0x11794
movq 0xf8(%rsp), %rdi
movups 0x250(%rsp), %xmm0
movaps %xmm0, 0x1d0(%rsp)
movq 0x2a0(%rsp), %r8
movss 0x1d0(%rsp), %xmm0
movq 0x1d8(%rsp), %rsi
leaq 0x200(%rsp), %rdx
leaq 0x298(%rsp), %rcx
callq 0x19030
movq %rax, 0xe0(%rsp)
movss %xmm0, 0xec(%rsp)
jmp 0x117ed
movq 0xe0(%rsp), %rax
movss 0xec(%rsp), %xmm0
movss %xmm0, 0x1e0(%rsp)
movq %rax, 0x1e8(%rsp)
jmp 0x11811
leaq 0x1e0(%rsp), %rdi
callq 0x2a70
cmpq $-0x1, %rax
je 0x11dd3
movq 0x2a0(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x2a60
movq 0xd0(%rsp), %rdi
movq %rax, %rsi
callq 0x193a0
movq %rax, 0xd8(%rsp)
jmp 0x1185f
movq 0xd8(%rsp), %rax
movq %rax, 0x1c8(%rsp)
movq 0x2a0(%rsp), %rdi
callq 0x193f0
movq %rax, 0x1c0(%rsp)
leaq 0x1c8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x193d0
testb $0x1, %al
jne 0x118a2
jmp 0x11a81
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x19420
movq 0xb8(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x1b8(%rsp)
callq 0x19420
movq %rax, %rcx
movq 0xf8(%rsp), %rax
movq 0x8(%rcx), %rcx
movq %rcx, 0x1b0(%rsp)
movl 0x38(%rax), %eax
movl %eax, 0xcc(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x2a90
movw %ax, %cx
movq 0xf8(%rsp), %rax
movzwl %cx, %ecx
movl %ecx, 0xc8(%rsp)
addq $0x58, %rax
movq %rax, 0xc0(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x29c0
movq 0xc0(%rsp), %rdi
movq %rax, %rsi
callq 0x19440
movq 0xf8(%rsp), %rdi
movq %rax, %rcx
movl 0xc8(%rsp), %eax
movzwl (%rcx), %ecx
imull %ecx, %eax
movzwl 0x38(%rdi), %ecx
cltd
idivl %ecx
movl 0xcc(%rsp), %eax
subl %edx, %eax
movw %ax, 0x1ae(%rsp)
movq 0x2a8(%rsp), %rdx
movq 0x1b0(%rsp), %rcx
movzwl 0x1ae(%rsp), %r8d
movq 0x298(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movq %rsp, %rax
leaq 0x200(%rsp), %rsi
movq %rsi, 0x8(%rax)
leaq 0x220(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x268(%rsp), %rsi
leaq 0x1a0(%rsp), %r9
callq 0x19460
jmp 0x119c5
movq 0xf8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x19650
movq %rax, 0xa8(%rsp)
movss %xmm0, 0xb4(%rsp)
jmp 0x119ed
movq 0xa8(%rsp), %rax
movss 0xb4(%rsp), %xmm0
movss %xmm0, 0x190(%rsp)
movq %rax, 0x198(%rsp)
leaq 0x1e0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x196b0
jmp 0x11dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x11e90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0x11e6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x248(%rsp)
movl %eax, 0x244(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x19b10
jmp 0x11e6c
movq 0xf8(%rsp), %rdi
movups 0x1e0(%rsp), %xmm0
movaps %xmm0, 0x170(%rsp)
movq 0x298(%rsp), %rdx
incq %rdx
movss 0x170(%rsp), %xmm0
movq 0x178(%rsp), %rsi
callq 0x196e0
movq %rax, 0x98(%rsp)
movss %xmm0, 0xa4(%rsp)
jmp 0x11acd
movq 0x98(%rsp), %rax
movss 0xa4(%rsp), %xmm0
movss %xmm0, 0x180(%rsp)
movq %rax, 0x188(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x196b0
movq %rax, %rdi
callq 0x2a70
cmpq $-0x1, %rax
je 0x11c02
movq 0xf8(%rsp), %rax
movl 0x38(%rax), %eax
movl %eax, 0x94(%rsp)
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x2a90
movq 0x88(%rsp), %rdi
movw %ax, %dx
movl 0x94(%rsp), %eax
movw %dx, %cx
subl %ecx, %eax
movzwl %ax, %esi
callq 0x2ac0
movq 0xf8(%rsp), %rdi
movups 0x1f0(%rsp), %xmm0
movaps %xmm0, 0x160(%rsp)
movss 0x160(%rsp), %xmm0
movq 0x168(%rsp), %rsi
leaq 0x298(%rsp), %rdx
leaq 0x220(%rsp), %rcx
leaq 0x200(%rsp), %r8
callq 0x19800
jmp 0x11ba4
movq 0xf8(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x19650
movq %rax, 0x78(%rsp)
movss %xmm0, 0x84(%rsp)
jmp 0x11bc9
movq 0x78(%rsp), %rax
movss 0x84(%rsp), %xmm0
movss %xmm0, 0x150(%rsp)
movq %rax, 0x158(%rsp)
leaq 0x1e0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x196b0
jmp 0x11dcf
leaq 0x1e0(%rsp), %rdi
callq 0x2ab0
movq %rax, %rcx
movq 0xf8(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x14c(%rsp)
movss 0x14c(%rsp), %xmm0
movss 0x240(%rsp), %xmm1
mulss 0x34(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x11cda
movq 0x1d36a(%rip), %rdi     # 0x2efb8
leaq 0x10923(%rip), %rsi     # 0x22578
callq 0x2230
movq %rax, 0x70(%rsp)
jmp 0x11c61
movq 0x70(%rsp), %rdi
movss 0x240(%rsp), %xmm0
callq 0x21e0
movq %rax, 0x68(%rsp)
jmp 0x11c7b
movq 0x68(%rsp), %rdi
leaq 0x109b4(%rip), %rsi     # 0x2263b
callq 0x2230
movq %rax, 0x60(%rsp)
jmp 0x11c93
movq 0x60(%rsp), %rdi
movss 0x14c(%rsp), %xmm0
callq 0x21e0
movq %rax, 0x58(%rsp)
jmp 0x11cad
movq 0x58(%rsp), %rdi
leaq 0x10989(%rip), %rsi     # 0x22642
callq 0x2230
movq %rax, 0x50(%rsp)
jmp 0x11cc5
movq 0x50(%rsp), %rdi
movq 0x1d2bf(%rip), %rsi     # 0x2ef90
callq 0x2250
jmp 0x11cd8
jmp 0x11cda
movq 0x2a0(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x2a60
movq %rax, %rsi
leaq 0x138(%rsp), %rdi
leaq 0x260(%rsp), %rdx
callq 0x199a0
jmp 0x11d0e
movq 0x48(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x19950
movb %dl, 0x3f(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x11d2b
movb 0x3f(%rsp), %al
movq 0x40(%rsp), %rcx
movq %rcx, 0x128(%rsp)
movb %al, 0x130(%rsp)
jmp 0x11d45
movq 0xf8(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x199d0
movq %rax, 0x30(%rsp)
movss %xmm0, 0x38(%rsp)
jmp 0x11d67
movq 0x30(%rsp), %rax
movss 0x38(%rsp), %xmm0
movss %xmm0, 0x118(%rsp)
movq %rax, 0x120(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x2a70
cmpq $-0x1, %rax
jne 0x11d98
jmp 0x11dcd
movups 0x118(%rsp), %xmm0
movaps %xmm0, 0x100(%rsp)
movss 0x100(%rsp), %xmm0
movq 0x108(%rsp), %rsi
leaq 0x268(%rsp), %rdi
callq 0x19ac0
jmp 0x11dc8
jmp 0x11d43
jmp 0x11e39
jmp 0x11dd1
jmp 0x11e34
movq 0x1d1de(%rip), %rdi     # 0x2efb8
leaq 0x10797(%rip), %rsi     # 0x22578
callq 0x2230
movq %rax, 0x28(%rsp)
jmp 0x11ded
movq 0x28(%rsp), %rdi
movss 0x240(%rsp), %xmm0
callq 0x21e0
movq %rax, 0x20(%rsp)
jmp 0x11e07
movq 0x20(%rsp), %rdi
leaq 0x1082d(%rip), %rsi     # 0x22640
callq 0x2230
movq %rax, 0x18(%rsp)
jmp 0x11e1f
movq 0x18(%rsp), %rdi
movq 0x1d165(%rip), %rsi     # 0x2ef90
callq 0x2250
jmp 0x11e32
jmp 0x11e39
jmp 0x1180f
leaq 0x200(%rsp), %rdi
callq 0x19b10
leaq 0x220(%rsp), %rdi
callq 0x19b10
movq 0x260(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x260(%rsp)
jmp 0x116e1
leaq 0x220(%rsp), %rdi
callq 0x19b10
jmp 0x11e90
leaq 0x268(%rsp), %rdi
callq 0x19b20
addq $0x2b8, %rsp            # imm = 0x2B8
retq
leaq 0x268(%rsp), %rdi
callq 0x19b20
movq 0x248(%rsp), %rdi
callq 0x2380
nopw (%rax,%rax)