// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwa.c
// Function: bwa_mem2idx
int bwa_mem2idx(int64_t l_mem, uint8_t *mem, bwaidx_t *idx)
{
	int64_t k = 0, x;
	int i;

	// generate idx->bwt
	x = sizeof(bwt_t); idx->bwt = malloc(x); memcpy(idx->bwt, mem + k, x); k += x;
	x = idx->bwt->bwt_size * 4; idx->bwt->bwt = (uint32_t*)(mem + k); k += x;
	x = idx->bwt->n_sa * sizeof(bwtint_t); idx->bwt->sa = (bwtint_t*)(mem + k); k += x;

	// generate idx->bns and idx->pac
	x = sizeof(bntseq_t); idx->bns = malloc(x); memcpy(idx->bns, mem + k, x); k += x;
	x = idx->bns->n_holes * sizeof(bntamb1_t); idx->bns->ambs = (bntamb1_t*)(mem + k); k += x;
	x = idx->bns->n_seqs  * sizeof(bntann1_t); idx->bns->anns = malloc(x); memcpy(idx->bns->anns, mem + k, x); k += x;
	for (i = 0; i < idx->bns->n_seqs; ++i) {
		idx->bns->anns[i].name = (char*)(mem + k); k += strlen(idx->bns->anns[i].name) + 1;
		idx->bns->anns[i].anno = (char*)(mem + k); k += strlen(idx->bns->anns[i].anno) + 1;
	}
	//idx->pac = (uint8_t*)(mem + k); k += idx->bns->l_pac/4+1;
	idx->pac = (uint8_t*)(mem + k); k += idx->bns->l_pac+1;
	assert(k == l_mem);

	idx->l_mem = k; idx->mem = mem;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x15526(%rip), %rbp     # 0x2856d
leaq 0x15621(%rip), %r13     # 0x2866f
movl $0x140, %edi            # imm = 0x140
movq %rbp, %rsi
movl $0x13e, %edx            # imm = 0x13E
movq %r13, %rcx
callq 0x23213
movq %rax, (%r15)
movl $0x140, %edx            # imm = 0x140
movq %rax, %rdi
movq %r14, %rsi
callq 0x3260
movq (%r15), %rax
movq 0x118(%rax), %rcx
movq 0x130(%rax), %rdx
leaq 0x140(%r14), %rsi
movq %rsi, 0x120(%rax)
leaq (%r14,%rcx,4), %rsi
addq $0x140, %rsi            # imm = 0x140
shlq $0x2, %rcx
movq %rsi, 0x138(%rax)
leaq (%rcx,%rdx,8), %rbx
addq $0x140, %rbx            # imm = 0x140
movl $0x30, %edi
movq %rbp, %rsi
movl $0x143, %edx            # imm = 0x143
movq %r13, %rcx
callq 0x23213
movq %rax, 0x8(%r15)
leaq (%r14,%rbx), %rcx
addq $0x30, %rcx
movups -0x30(%rcx), %xmm0
movups -0x20(%rcx), %xmm1
movups -0x10(%rcx), %xmm2
movups %xmm0, (%rax)
movups %xmm1, 0x10(%rax)
movups %xmm2, 0x20(%rax)
movq 0x8(%r15), %rax
movslq 0x18(%rax), %rdx
shlq $0x4, %rdx
movq %rcx, 0x20(%rax)
addq %rdx, %rbx
addq $0x30, %rbx
movslq 0x8(%rax), %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
movq %r12, %rdi
movq %rbp, %rsi
movl $0x145, %edx            # imm = 0x145
movq %r13, %rcx
callq 0x23213
movq 0x8(%r15), %rcx
movq %rax, 0x10(%rcx)
leaq (%r14,%rbx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x3260
addq %rbx, %r12
movq %r15, 0x10(%rsp)
movq 0x8(%r15), %rcx
movslq 0x8(%rcx), %rax
testq %rax, %rax
movq %rcx, (%rsp)
jle 0x13198
movq 0x10(%rcx), %r15
shlq $0x3, %rax
leaq (%rax,%rax,4), %rbp
xorl %ebx, %ebx
leaq (%r14,%r12), %rdi
movq %rdi, 0x18(%r15,%rbx)
callq 0x3100
movq %rax, %r13
addq %r12, %r13
leaq (%r14,%r13), %rdi
incq %rdi
movq %rdi, 0x20(%r15,%rbx)
callq 0x3100
leaq (%rax,%r13), %r12
addq $0x2, %r12
addq $0x28, %rbx
cmpq %rbx, %rbp
jne 0x13162
leaq (%r14,%r12), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq (%rsp), %rax
movq (%rax), %rax
addq %r12, %rax
incq %rax
movq 0x8(%rsp), %rdx
cmpq %rdx, %rax
jne 0x131d5
movq %rdx, 0x20(%rcx)
movq %r14, 0x28(%rcx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1549f(%rip), %rdi     # 0x2867b
leaq 0x1538a(%rip), %rsi     # 0x2856d
leaq 0x1549c(%rip), %rcx     # 0x28686
movl $0x14c, %edx            # imm = 0x14C
callq 0x31a0