// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bwashm.c
// Function: index_load_from_shm
bwaidx_t *index_load_from_shm(const char *hint)
{
	const char *name;
	uint8_t *shm, *shm_idx;
	uint16_t *cnt, i;
	char *p, path[PATH_MAX + 1];
	int shmid;
	int64_t l_mem;
	bwaidx_t *idx;

	if (hint == 0 || hint[0] == 0) return 0;
	for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
	++name;
	if ((shmid = shm_open("/bwactl", O_RDONLY, 0)) < 0) return 0;
	shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
	cnt = (uint16_t*)shm;
	if (cnt[0] == 0) return 0;
	for (i = 0, p = (char*)(shm + 4); i < cnt[0]; ++i) {
		memcpy(&l_mem, p, 8); p += 8;
		if (strcmp(p, name) == 0) break;
		p += strlen(p) + 1;
	}
	if (i == cnt[0]) return 0;

	strcat(strcpy(path, "/bwaidx-"), name);
	if ((shmid = shm_open(path, O_RDONLY, 0)) < 0) return 0;
	shm_idx = mmap(0, l_mem, PROT_READ, MAP_SHARED, shmid, 0);
	idx = calloc(1, sizeof(bwaidx_t));
	bwa_mem2idx(l_mem, shm_idx, idx);
	idx->is_shm = 1;
	return idx;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1080, %rsp           # imm = 0x1080
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe862
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xe86f
movq $0x0, -0x8(%rbp)
jmp 0xea90
movq -0x10(%rbp), %rax
movq %rax, -0x1070(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30f0
movq %rax, %rcx
movq -0x1070(%rbp), %rax
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpq -0x10(%rbp), %rcx
movb %al, -0x1071(%rbp)
jb 0xe8bd
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
setne %al
movb %al, -0x1071(%rbp)
movb -0x1071(%rbp), %al
testb $0x1, %al
jne 0xe8c9
jmp 0xe8d9
jmp 0xe8cb
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xe898
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
leaq 0x2aee8(%rip), %rdi     # 0x397d4
xorl %edx, %edx
movl %edx, %esi
callq 0x3630
movl %eax, -0x1054(%rbp)
cmpl $0x0, %eax
jge 0xe90d
movq $0x0, -0x8(%rbp)
jmp 0xea90
movl -0x1054(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x10000, %esi          # imm = 0x10000
movl $0x1, %ecx
movq %r9, %rdi
movl %ecx, %edx
callq 0x36a0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xe952
movq $0x0, -0x8(%rbp)
jmp 0xea90
movw $0x0, -0x32(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movzwl -0x32(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xe9c4
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1060(%rbp)
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x34b0
cmpl $0x0, %eax
jne 0xe9a1
jmp 0xe9c4
movq -0x40(%rbp), %rdi
callq 0x30f0
addq $0x1, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movw -0x32(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x32(%rbp)
jmp 0xe964
movzwl -0x32(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jne 0xe9e0
movq $0x0, -0x8(%rbp)
jmp 0xea90
leaq -0x1050(%rbp), %rdi
leaq 0x2ae43(%rip), %rsi     # 0x39831
callq 0x32b0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x3690
leaq -0x1050(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x3630
movl %eax, -0x1054(%rbp)
cmpl $0x0, %eax
jge 0xea24
movq $0x0, -0x8(%rbp)
jmp 0xea90
movq -0x1060(%rbp), %rsi
movl -0x1054(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, %ecx
movq %r9, %rdi
movl %ecx, %edx
callq 0x36a0
movq %rax, -0x28(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x31a0
movq %rax, -0x1068(%rbp)
movq -0x1060(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x1068(%rbp), %rdx
callq 0x1a110
movq -0x1068(%rbp), %rax
movl $0x1, 0x18(%rax)
movq -0x1068(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1080, %rsp           # imm = 0x1080
popq %rbp
retq
nopl (%rax)