// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap2/splitidx.c
// Function: mm_split_merge_prep
mm_idx_t *mm_split_merge_prep(const char *prefix, int n_splits, FILE **fp, uint32_t *n_seq_part)
{
	mm_idx_t *mi = 0;
	char *fn;
	int i, j;

	if (n_splits < 1) return 0;
	fn = CALLOC(char, strlen(prefix) + 10);
	for (i = 0; i < n_splits; ++i) {
		sprintf(fn, "%s.%.4d.tmp", prefix, i);
		if ((fp[i] = fopen(fn, "rb")) == 0) {
			if (mm_verbose >= 1)
				fprintf(stderr, "ERROR: failed to open temporary file '%s': %s\n", fn, strerror(errno));
			for (j = 0; j < i; ++j)
				fclose(fp[j]);
			free(fn);
			return 0;
		}
	}
	free(fn);

	mi = CALLOC(mm_idx_t, 1);
	for (i = 0; i < n_splits; ++i) {
		mm_err_fread(&mi->k, 4, 1, fp[i]); // TODO: check if k is all the same
		mm_err_fread(&n_seq_part[i], 4, 1, fp[i]);
		mi->n_seq += n_seq_part[i];
	}
	mi->seq = CALLOC(mm_idx_seq_t, mi->n_seq);
	for (i = j = 0; i < n_splits; ++i) {
		uint32_t k;
		for (k = 0; k < n_seq_part[i]; ++k, ++j) {
			uint32_t l;
			mm_err_fread(&l, 1, 4, fp[i]);
			mi->seq[j].name = (char*)calloc(l + 1, 1);
			mm_err_fread(mi->seq[j].name, 1, l, fp[i]);
			mm_err_fread(&mi->seq[j].len, 4, 1, fp[i]);
		}
	}
	return mi;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
testl %esi, %esi
jle 0x12034
movq %rdx, %rbp
movl %esi, %ebx
movq %rdi, %r13
callq 0x2130
leaq 0xa(%rax), %rdi
movl $0x1, %esi
callq 0x2230
movq %rax, %r15
movl %ebx, %r14d
leaq 0x1b4c4(%rip), %rbx     # 0x2d330
xorl %r12d, %r12d
movq %r15, %rdi
leaq 0x1c182(%rip), %rsi     # 0x2dffb
movq %r13, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x23d0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2390
movq %rax, (%rbp,%r12,8)
testq %rax, %rax
je 0x12006
incq %r12
cmpq %r12, %r14
jne 0x11e6f
movq %r15, %rdi
callq 0x2040
movl $0x1, %edi
movl $0x60, %esi
callq 0x2230
movq %rax, %r15
movq %rax, %r12
addq $0x8, %r12
movq %r14, 0x8(%rsp)
leaq (,%r14,4), %rbx
xorl %r13d, %r13d
movq 0x18(%rsp), %r14
movq (%rbp,%r13,2), %rcx
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x5828
leaq (%r14,%r13), %rdi
movq (%rbp,%r13,2), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x5828
movl 0x10(%r15), %eax
addl (%r14,%r13), %eax
movl %eax, 0x10(%r15)
addq $0x4, %r13
cmpq %r13, %rbx
jne 0x11edd
movl %eax, %edi
movl $0x18, %esi
callq 0x2230
movq %r15, 0x10(%rsp)
movq %rax, 0x20(%r15)
xorl %r15d, %r15d
xorl %ecx, %ecx
movq %r14, %r13
movq 0x8(%rsp), %rax
movq %rbp, 0x20(%rsp)
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %rbp
cmpl $0x0, (%r13,%r15,4)
je 0x11ff3
movl %ecx, (%rsp)
movslq %ecx, %rax
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,8), %r14
xorl %r12d, %r12d
movq (%rbx,%r15,8), %rcx
movl $0x1, %esi
movl $0x4, %edx
leaq 0x4(%rsp), %rdi
callq 0x5828
movl 0x4(%rsp), %r13d
leal 0x1(%r13), %edi
movl $0x1, %esi
callq 0x2230
movq 0x20(%rbp), %rcx
movq %rax, -0x10(%rcx,%r14)
movq (%rbx,%r15,8), %rcx
movl $0x1, %esi
movq %rax, %rdi
movq %r13, %rdx
movq 0x18(%rsp), %r13
callq 0x5828
movq 0x20(%rbp), %rdi
addq %r14, %rdi
movq (%rbx,%r15,8), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x5828
incl %r12d
addq $0x18, %r14
cmpl (%r13,%r15,4), %r12d
jb 0x11f73
movl (%rsp), %ecx
addl %r12d, %ecx
movq 0x8(%rsp), %rax
incq %r15
cmpq %rax, %r15
jne 0x11f52
movq 0x10(%rsp), %rax
jmp 0x12036
leaq 0x246f3(%rip), %rax     # 0x36700
cmpl $0x0, (%rax)
jg 0x12045
testq %r12, %r12
je 0x1202c
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
callq 0x2120
incq %r14
cmpq %r14, %r12
jne 0x1201a
movq %r15, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x30fa
jmp 0x12012