// File: Ripser[P]ripser/ripser.cpp
// Function: read_sparse_distance_matrix(std::istream&)
sparse_distance_matrix read_sparse_distance_matrix(std::istream& input_stream) {
	std::vector<std::vector<index_diameter_t>> neighbors;
	index_t num_edges = 0;

	std::string line;
	while (std::getline(input_stream, line)) {
		std::istringstream s(line);
		size_t i, j;
		value_t value;
		s >> i;
		s.ignore();
		s >> j;
		s.ignore();
		s >> value;
		s.ignore();
		if (i != j) {
			neighbors.resize(std::max({neighbors.size(), i + 1, j + 1}));
			neighbors[i].push_back({j, value});
			neighbors[j].push_back({i, value});
			++num_edges;
		}
	}

	for (size_t i = 0; i < neighbors.size(); ++i)
		std::sort(neighbors[i].begin(), neighbors[i].end());

	return sparse_distance_matrix(std::move(neighbors), num_edges);
}

// Assembly:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x64c0
movq $0x0, 0x278(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x22c0
movq 0x298(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x2070
movq %rax, 0x38(%rsp)
jmp 0x34f6
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2280
movb %al, 0x37(%rsp)
jmp 0x3510
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x351d
jmp 0x373d
leaq 0xc8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
movl $0x8, %edx
callq 0x2340
jmp 0x3539
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x22d0
jmp 0x3550
leaq 0xc8(%rsp), %rdi
callq 0x23c0
jmp 0x355f
leaq 0xc8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x22d0
jmp 0x3576
leaq 0xc8(%rsp), %rdi
callq 0x23c0
jmp 0x3585
leaq 0xc8(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x2080
jmp 0x359c
leaq 0xc8(%rsp), %rdi
callq 0x23c0
jmp 0x35ab
movq 0xc0(%rsp), %rax
cmpq 0xb8(%rsp), %rax
je 0x372b
leaq 0x280(%rsp), %rdi
callq 0x65b0
movq %rax, 0x88(%rsp)
movq 0xc0(%rsp), %rax
incq %rax
movq %rax, 0x90(%rsp)
movq 0xb8(%rsp), %rax
incq %rax
movq %rax, 0x98(%rsp)
leaq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq $0x3, 0xa8(%rsp)
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x6570
movq %rax, 0x28(%rsp)
jmp 0x3634
movq 0x28(%rsp), %rsi
leaq 0x280(%rsp), %rdi
callq 0x64d0
jmp 0x3648
movq 0xc0(%rsp), %rsi
leaq 0x280(%rsp), %rdi
callq 0x65d0
movq %rax, 0x20(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0xb4(%rsp), %rdx
callq 0x6620
jmp 0x367e
movq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x65f0
jmp 0x368f
movq 0xb8(%rsp), %rsi
leaq 0x280(%rsp), %rdi
callq 0x65d0
movq %rax, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xb4(%rsp), %rdx
callq 0x6620
jmp 0x36c5
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x65f0
jmp 0x36d6
movq 0x278(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x278(%rsp)
jmp 0x372b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x3813
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x2110
jmp 0x3813
leaq 0xc8(%rsp), %rdi
callq 0x2110
jmp 0x34da
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x65b0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x37d0
movq 0x60(%rsp), %rsi
leaq 0x280(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x65d0
movq %rax, %rdi
callq 0x6690
movq 0x8(%rsp), %rdi
movq %rax, 0x58(%rsp)
movq 0x60(%rsp), %rsi
callq 0x65d0
movq %rax, %rdi
callq 0x66c0
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x6650
jmp 0x37bb
jmp 0x37bd
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x3746
movq 0x40(%rsp), %rdi
movq 0x278(%rsp), %rdx
leaq 0x280(%rsp), %rsi
callq 0x66f0
jmp 0x37ec
leaq 0x258(%rsp), %rdi
callq 0x2448
leaq 0x280(%rsp), %rdi
callq 0x6730
movq 0x48(%rsp), %rax
addq $0x2a8, %rsp            # imm = 0x2A8
retq
leaq 0x258(%rsp), %rdi
callq 0x2448
leaq 0x280(%rsp), %rdi
callq 0x6730
movq 0x250(%rsp), %rdi
callq 0x2380
nopw (%rax,%rax)