// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/bwa.c
// Function: bwa_idx2mem
int bwa_idx2mem(bwaidx_t *idx)
{
	int i;
	int64_t k, x, tmp;
	uint8_t *mem;

	// copy idx->bwt
	x = idx->bwt->bwt_size * 4;
	mem = realloc(idx->bwt->bwt, sizeof(bwt_t) + x); idx->bwt->bwt = 0;
	memmove(mem + sizeof(bwt_t), mem, x);
	memcpy(mem, idx->bwt, sizeof(bwt_t)); k = sizeof(bwt_t) + x;
	x = idx->bwt->n_sa * sizeof(bwtint_t); mem = realloc(mem, k + x); memcpy(mem + k, idx->bwt->sa, x); k += x;
	free(idx->bwt->sa);
	free(idx->bwt); idx->bwt = 0;

	// copy idx->bns
	tmp = idx->bns->n_seqs * sizeof(bntann1_t) + idx->bns->n_holes * sizeof(bntamb1_t);
	for (i = 0; i < idx->bns->n_seqs; ++i) // compute the size of heap-allocated memory
		tmp += strlen(idx->bns->anns[i].name) + strlen(idx->bns->anns[i].anno) + 2;
	mem = realloc(mem, k + sizeof(bntseq_t) + tmp);
	x = sizeof(bntseq_t); memcpy(mem + k, idx->bns, x); k += x;
	x = idx->bns->n_holes * sizeof(bntamb1_t); memcpy(mem + k, idx->bns->ambs, x); k += x;
	free(idx->bns->ambs);
	x = idx->bns->n_seqs * sizeof(bntann1_t); memcpy(mem + k, idx->bns->anns, x); k += x;
	for (i = 0; i < idx->bns->n_seqs; ++i) {
		x = strlen(idx->bns->anns[i].name) + 1; memcpy(mem + k, idx->bns->anns[i].name, x); k += x;
		x = strlen(idx->bns->anns[i].anno) + 1; memcpy(mem + k, idx->bns->anns[i].anno, x); k += x;
		free(idx->bns->anns[i].name); free(idx->bns->anns[i].anno);
	}
	free(idx->bns->anns);

	// copy idx->pac
	//x = idx->bns->l_pac/4+1;
	x = idx->bns->l_pac+1;
	mem = realloc(mem, k + x);
	memcpy(mem + k, idx->pac, x); k += x;
	free(idx->bns); idx->bns = 0;
	free(idx->pac); idx->pac = 0;

	return bwa_mem2idx(k, mem, idx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x118(%rax), %r12
movq 0x120(%rax), %rdi
leaq (,%r12,4), %r15
movl $0x140, %ebp            # imm = 0x140
leaq (%r15,%rbp), %rsi
leaq 0x122c0(%rip), %r14     # 0x23505
leaq 0x12402(%rip), %r8      # 0x2364e
movq %r14, %rdx
movl $0x15a, %ecx            # imm = 0x15A
callq 0x1e0b4
movq %rax, %r13
movq (%rbx), %rax
andq $0x0, 0x120(%rax)
movq %r13, %rdi
addq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3600
movq (%rbx), %rsi
movl $0x140, %edx            # imm = 0x140
movq %r13, %rdi
callq 0x3260
movq (%rbx), %rax
movq 0x130(%rax), %rbp
leaq (%r15,%rbp,8), %rsi
addq $0x140, %rsi            # imm = 0x140
shlq $0x3, %rbp
movq %r13, %rdi
movq %rsi, 0x8(%rsp)
movq %r14, %rdx
movl $0x15d, %ecx            # imm = 0x15D
leaq 0x12396(%rip), %r8      # 0x2364e
callq 0x1e0b4
movq %rax, (%rsp)
leaq (%rax,%r12,4), %rdi
addq $0x140, %rdi            # imm = 0x140
movq (%rbx), %rax
movq 0x138(%rax), %rsi
movq %rbp, %rdx
callq 0x3260
movq (%rbx), %rax
movq 0x138(%rax), %rdi
callq 0x3390
movq (%rbx), %rdi
callq 0x3390
andq $0x0, (%rbx)
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %r13
movslq 0x8(%r13), %rax
imulq $0x28, %rax, %rcx
movslq 0x18(%r13), %rbp
shlq $0x4, %rbp
addq %rcx, %rbp
xorl %r14d, %r14d
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
imulq $0x28, %rcx, %r15
cmpq %r14, %r15
je 0x11356
movq 0x10(%r13), %rbx
movq 0x18(%rbx,%r14), %rdi
callq 0x3100
movq %rax, %r12
movq 0x20(%rbx,%r14), %rdi
callq 0x3100
addq %r12, %rbp
addq %rax, %rbp
addq $0x2, %rbp
addq $0x28, %r14
jmp 0x11326
movq 0x8(%rsp), %rbx
leaq (%rbx,%rbp), %rsi
addq $0x30, %rsi
leaq 0x1219b(%rip), %rdx     # 0x23505
leaq 0x122dd(%rip), %r8      # 0x2364e
movq (%rsp), %rdi
movl $0x165, %ecx            # imm = 0x165
callq 0x1e0b4
movq %rax, %r14
movq 0x10(%rsp), %r13
movq 0x8(%r13), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
leaq 0x30(%r14,%rbx), %rdi
movups %xmm0, -0x30(%rdi)
movups %xmm1, -0x20(%rdi)
movups %xmm2, -0x10(%rdi)
movq 0x8(%r13), %rax
movslq 0x18(%rax), %r12
shlq $0x4, %r12
movq 0x20(%rax), %rsi
movq %r12, %rdx
callq 0x3260
addq %r12, %rbx
addq $0x30, %rbx
movq 0x8(%r13), %rax
movq 0x20(%rax), %rdi
callq 0x3390
movq 0x8(%r13), %rax
movslq 0x8(%rax), %rcx
imulq $0x28, %rcx, %r15
movq %r14, (%rsp)
leaq (%r14,%rbx), %rdi
movq 0x10(%rax), %rsi
movq %r15, %rdx
callq 0x3260
addq %rbx, %r15
xorl %ebp, %ebp
xorl %edx, %edx
movq (%rsp), %r14
movq 0x8(%r13), %rax
movslq 0x8(%rax), %rcx
movq 0x10(%rax), %rdi
cmpq %rcx, %rdx
jge 0x114a8
movq 0x18(%rdi,%rbp), %r12
movq %r12, %rdi
movq %rdx, 0x8(%rsp)
callq 0x3100
movq %rax, %r13
leaq 0x1(%rax), %rdx
leaq (%r14,%r15), %rdi
movq %r12, %rsi
callq 0x3260
leaq (%r15,%r13), %rbx
incq %rbx
movq 0x10(%rsp), %r13
movq 0x8(%r13), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax,%rbp), %r15
movq %r15, %rdi
callq 0x3100
movq %rax, %r12
leaq 0x1(%rax), %rdx
leaq (%r14,%rbx), %rdi
movq %r15, %rsi
callq 0x3260
leaq (%r12,%rbx), %r15
incq %r15
movq 0x8(%r13), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax,%rbp), %rdi
callq 0x3390
movq 0x8(%r13), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax,%rbp), %rdi
callq 0x3390
movq 0x8(%rsp), %rdx
incq %rdx
addq $0x28, %rbp
jmp 0x113fe
callq 0x3390
movq 0x8(%r13), %rax
movq %r13, %rbx
movq (%rax), %r13
leaq (%r15,%r13), %r12
incq %r12
incq %r13
leaq 0x1203d(%rip), %rdx     # 0x23505
leaq 0x1217f(%rip), %r8      # 0x2364e
movq (%rsp), %rdi
movq %r12, %rsi
movl $0x174, %ecx            # imm = 0x174
callq 0x1e0b4
movq %rax, %r14
addq %rax, %r15
movq 0x10(%rbx), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x3260
movq 0x8(%rbx), %rdi
callq 0x3390
andq $0x0, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x3390
andq $0x0, 0x10(%rbx)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x11055
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq