// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/sdict.c
// Function: sd_coordinate_conversion
int sd_coordinate_conversion(asm_dict_t *d, uint32_t id, uint32_t pos, uint32_t *s, uint64_t *p, int count_gap)
{
    *s = UINT32_MAX;
    *p = UINT64_MAX;

    if (id >= d->sdict->n)
        return SEQ_NOT_FOUND;

    uint32_t i, n;
    uint64_t *index = d->index;
    i = (uint32_t) (d->a[id] >> 32);
    n = (uint32_t) (d->a[id]) + i;

    while (i < n && index[i]>>32 <= pos)
        ++i;
    if (i == n)
        return POS_NOT_IN_RANGE;

    sd_seg_t *seg = &d->seg[(uint32_t) index[i]];
    if (pos < seg->x || pos >= seg->x + seg->y)
        return POS_NOT_IN_RANGE;

    uint64_t offset = count_gap? seg->b : seg->a;
    *s = seg->s;
    *p = seg->c & 1? offset + seg->x + seg->y - 1 - pos : offset + pos - seg->x;

    return CC_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movq $-0x1, (%rax)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
cmpl (%rcx), %eax
jb 0x85aa
movl $0x1, -0x4(%rbp)
jmp 0x8713
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
addl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x34(%rbp), %ecx
movb %al, -0x51(%rbp)
jae 0x8609
movq -0x40(%rbp), %rax
movl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x18(%rbp), %ecx
cmpq %rcx, %rax
setbe %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x8612
jmp 0x861d
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x85e1
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x8631
movl $0x2, -0x4(%rbp)
jmp 0x8713
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jb 0x8672
movl -0x18(%rbp), %eax
movq -0x48(%rbp), %rcx
movl 0x1c(%rcx), %ecx
movq -0x48(%rbp), %rdx
addl 0x20(%rdx), %ecx
cmpl %ecx, %eax
jb 0x867e
movl $0x2, -0x4(%rbp)
jmp 0x8713
cmpl $0x0, -0x2c(%rbp)
je 0x8692
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x869e
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x86e9
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movl 0x1c(%rcx), %ecx
addq %rcx, %rax
movq -0x48(%rbp), %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
subq $0x1, %rax
movl -0x18(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x8701
movq -0x50(%rbp), %rax
movl -0x18(%rbp), %ecx
addq %rcx, %rax
movq -0x48(%rbp), %rcx
movl 0x1c(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)