// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
testl %esi, %esi
jle 0x120bd
movq %rdx, %rbp
movl %esi, %r14d
movq %rdi, %r13
callq 0x2130
leaq 0xa(%rax), %rdi
movl $0x1, %esi
callq 0x2230
movq %rax, %r15
movl %r14d, %ebx
xorl %r12d, %r12d
movq %r15, %rdi
leaq 0x1b0e0(%rip), %rsi     # 0x2cfdf
movq %r13, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x23d0
movq %r15, %rdi
leaq 0x1a3f6(%rip), %rsi     # 0x2c30c
callq 0x2390
movq %rax, (%rbp,%r12,8)
testq %rax, %rax
je 0x1208f
incq %r12
cmpq %r12, %rbx
jne 0x11ef5
movl %r14d, (%rsp)
movq %r15, %rdi
callq 0x2040
movl $0x1, %edi
movl $0x60, %esi
callq 0x2230
movq %rax, %r15
movq %rax, %r12
addq $0x8, %r12
shlq $0x2, %rbx
xorl %r14d, %r14d
movq 0x10(%rsp), %r13
movq (%rbp,%r14,2), %rcx
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x58c0
leaq (%r14,%r13), %rdi
movq (%rbp,%r14,2), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x58c0
movl (%r13,%r14), %eax
addl %eax, 0x10(%r15)
addq $0x4, %r14
cmpq %r14, %rbx
jne 0x11f62
movl 0x10(%r15), %edi
movl $0x18, %esi
callq 0x2230
movl (%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %edx
cmovgel %ecx, %edx
movq %rdx, 0x18(%rsp)
movq %r15, (%rsp)
movq %rax, 0x20(%r15)
xorl %ebx, %ebx
xorl %eax, %eax
movq %rbp, 0x20(%rsp)
movq 0x20(%rsp), %r15
movq (%rsp), %rbp
cmpl $0x0, (%r13,%rbx,4)
je 0x1207b
movl %eax, 0x8(%rsp)
cltq
leaq (%rax,%rax,2), %rax
leaq 0x10(,%rax,8), %r14
xorl %r12d, %r12d
movq (%r15,%rbx,8), %rcx
movl $0x1, %esi
movl $0x4, %edx
leaq 0xc(%rsp), %rdi
callq 0x58c0
movl 0xc(%rsp), %r13d
leal 0x1(%r13), %edi
movl $0x1, %esi
callq 0x2230
movq 0x20(%rbp), %rcx
movq %rax, -0x10(%rcx,%r14)
movq (%r15,%rbx,8), %rcx
movl $0x1, %esi
movq %rax, %rdi
movq %r13, %rdx
movq 0x10(%rsp), %r13
callq 0x58c0
movq 0x20(%rbp), %rdi
addq %r14, %rdi
movq (%r15,%rbx,8), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x58c0
incl %r12d
addq $0x18, %r14
cmpl (%r13,%rbx,4), %r12d
jb 0x11fff
movl 0x8(%rsp), %eax
addl %r12d, %eax
incq %rbx
cmpq 0x18(%rsp), %rbx
jne 0x11fde
movq (%rsp), %rax
jmp 0x120bf
leaq 0x2366a(%rip), %rax     # 0x35700
cmpl $0x0, (%rax)
jg 0x120ce
testq %r12, %r12
je 0x120b5
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
callq 0x2120
incq %r14
cmpq %r14, %r12
jne 0x120a3
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 0x3104
jmp 0x1209b