// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rcx, 0x20(%rsp)
movq %rdx, 0x8(%rsp)
testl %esi, %esi
jle 0x104b2
movl %esi, %ebp
movq %rdi, %r13
callq 0x2130
leaq 0xa(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x2230
movq %rax, %r15
movl %ebp, %ebx
leaq 0x18d0a(%rip), %r14     # 0x28ffb
leaq 0x18038(%rip), %rbp     # 0x28330
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x10335
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x23d0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2390
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
testq %rax, %rax
je 0x10484
incq %r12
jmp 0x102fb
movq %r15, %rdi
callq 0x2040
pushq $0x1
popq %rdi
pushq $0x60
popq %rsi
callq 0x2230
movq %rax, %r13
movq %rax, (%rsp)
addq $0x8, %r13
movq %rbx, 0x28(%rsp)
leaq (,%rbx,4), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
pushq $0x4
popq %rbp
xorl %eax, %eax
movq 0x8(%rsp), %r15
pushq $0x1
popq %rbx
movq 0x20(%rsp), %r12
cmpq %r14, 0x10(%rsp)
je 0x103ba
movq (%r15,%r14,2), %rcx
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x4592
leaq (%r12,%r14), %rdi
movq (%r15,%r14,2), %rcx
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x4592
movq (%rsp), %rcx
movl 0x10(%rcx), %eax
addl (%r12,%r14), %eax
movl %eax, 0x10(%rcx)
addq $0x4, %r14
jmp 0x1037a
movl %eax, %edi
pushq $0x18
popq %rsi
callq 0x2230
movq (%rsp), %rcx
movq %rax, 0x20(%rcx)
xorl %r14d, %r14d
xorl %eax, %eax
movq 0x8(%rsp), %r15
pushq $0x1
popq %rbx
movq (%rsp), %r13
cmpq 0x28(%rsp), %r14
je 0x1047e
cltq
movq %rax, 0x30(%rsp)
imulq $0x18, %rax, %rbp
addq $0x10, %rbp
xorl %ecx, %ecx
movq 0x20(%rsp), %rax
cmpl (%rax,%r14,4), %ecx
jae 0x1046e
movq %rcx, 0x10(%rsp)
movq (%r15,%r14,8), %rcx
leaq 0x1c(%rsp), %rdi
movq %rbx, %rsi
pushq $0x4
popq %rdx
callq 0x4592
movl 0x1c(%rsp), %r12d
leal 0x1(%r12), %edi
movq %rbx, %rsi
callq 0x2230
movq 0x20(%r13), %rcx
movq %rax, -0x10(%rcx,%rbp)
movq (%r15,%r14,8), %rcx
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4592
movq 0x20(%r13), %rdi
addq %rbp, %rdi
movq (%r15,%r14,8), %rcx
pushq $0x4
popq %rsi
movq %rbx, %rdx
callq 0x4592
movq 0x10(%rsp), %rcx
incq %rcx
addq $0x18, %rbp
jmp 0x103f9
incq %r14
movq 0x30(%rsp), %rax
addq %rcx, %rax
jmp 0x103dd
movq (%rsp), %rax
jmp 0x104b4
leaq 0x22275(%rip), %rax     # 0x32700
cmpl $0x0, (%rax)
jg 0x104c3
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x104aa
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2120
incq %rbx
jmp 0x10492
movq %r15, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x21b2e(%rip), %rax     # 0x31ff8
movq (%rax), %r14
callq 0x2060
movl (%rax), %edi
callq 0x2420
leaq 0x18b66(%rip), %rsi     # 0x29046
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2260
jmp 0x10490