// File: /workspace/github_c_makefile_star2_O1/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 0x15852(%rip), %rbp     # 0x284d5
leaq 0x1594d(%rip), %r13     # 0x285d7
movl $0x140, %edi            # imm = 0x140
movq %rbp, %rsi
movl $0x13e, %edx            # imm = 0x13E
movq %r13, %rcx
callq 0x22d2b
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 0x22d2b
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 0x22d2b
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 0x12dd4
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 0x12d9e
leaq (%r14,%r12), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq (%rsp), %rax
movq (%rax), %rax
addq %r12, %rax
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x12e0e
movq %rax, 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 0x157ce(%rip), %rdi     # 0x285e3
leaq 0x156b9(%rip), %rsi     # 0x284d5
leaq 0x157cb(%rip), %rcx     # 0x285ee
movl $0x14c, %edx            # imm = 0x14C
callq 0x31a0