// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
leaq 0x12490(%rip), %rbp     # 0x23505
leaq 0x1258b(%rip), %r13     # 0x23607
movl $0x140, %edi            # imm = 0x140
movq %rbp, %rsi
movl $0x13e, %edx            # imm = 0x13E
movq %r13, %rcx
callq 0x1e045
movq %rax, (%rbx)
movl $0x140, %edx            # imm = 0x140
movq %rax, %rdi
movq %r14, %rsi
callq 0x3260
movq (%rbx), %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), %r15
addq $0x140, %r15            # imm = 0x140
pushq $0x30
popq %rdi
movq %rbp, %rsi
movl $0x143, %edx            # imm = 0x143
movq %r13, %rcx
callq 0x1e045
movq %rax, 0x8(%rbx)
leaq (%r14,%r15), %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(%rbx), %rax
movslq 0x18(%rax), %rdx
shlq $0x4, %rdx
movq %rcx, 0x20(%rax)
addq %rdx, %r15
addq $0x30, %r15
movslq 0x8(%rax), %rax
imulq $0x28, %rax, %r12
movq %r12, %rdi
movq %rbp, %rsi
movl $0x145, %edx            # imm = 0x145
movq %r13, %rcx
callq 0x1e045
movq 0x8(%rbx), %rcx
movq %rax, 0x10(%rcx)
leaq (%r14,%r15), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x3260
addq %r15, %r12
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %r13
movl 0x8(%r13), %eax
xorl %ebp, %ebp
testl %eax, %eax
cmovlel %ebp, %eax
imulq $0x28, %rax, %r15
leaq (%r14,%r12), %rdi
cmpq %rbp, %r15
je 0x111b6
movq 0x10(%r13), %rbx
movq %rdi, 0x18(%rbx,%rbp)
callq 0x3100
addq %rax, %r12
leaq (%r14,%r12), %rdi
incq %rdi
movq %rdi, 0x20(%rbx,%rbp)
callq 0x3100
addq %rax, %r12
addq $0x2, %r12
addq $0x28, %rbp
jmp 0x1117e
movq 0x10(%rsp), %rcx
movq %rdi, 0x10(%rcx)
movq (%r13), %rax
addq %r12, %rax
incq %rax
movq 0x8(%rsp), %rdx
cmpq %rdx, %rax
jne 0x111ec
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 0x12420(%rip), %rdi     # 0x23613
leaq 0x1230b(%rip), %rsi     # 0x23505
leaq 0x1241d(%rip), %rcx     # 0x2361e
movl $0x14c, %edx            # imm = 0x14C
callq 0x31a0