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

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

    sd_seg_t *seg = d->seg + d->s[id].s;
    uint32_t i = 0, n = d->s[id].n;
    uint64_t offset = 0;

    if (count_gap) {
        while (i < n && pos >= seg[i].b)
            ++i;
        seg = &seg[i-1];
        offset = pos - seg->b;
    } else {
        while (i < n && pos >= seg[i].a)
            ++i;
        seg = &seg[i-1];
        offset = pos - seg->a;
    }
    
    // check if in gap or exceeds seq length
    if (offset >= seg->y)
        return POS_NOT_IN_RANGE;

    *s = seg->c >> 1;
    *p = seg->c & 1? seg->y - 1 - offset : seg->x + offset;

    return CC_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jb 0x8766
movl $0x1, -0x4(%rbp)
jmp 0x88f8
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x14(%rbp), %edx
imulq $0x58, %rdx, %rdx
addq %rdx, %rcx
movl 0x1c(%rcx), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x8823
jmp 0x87bd
movl -0x44(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0x51(%rbp)
jae 0x87e6
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x10(%rcx), %rax
setae %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x87ef
jmp 0x87fa
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x87bd
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x10(%rcx), %rax
movq %rax, -0x50(%rbp)
jmp 0x8889
jmp 0x8825
movl -0x44(%rbp), %ecx
xorl %eax, %eax
cmpl -0x48(%rbp), %ecx
movb %al, -0x52(%rbp)
jae 0x884e
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
setae %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x8857
jmp 0x8862
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x8825
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x8(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x20(%rcx), %ecx
cmpq %rcx, %rax
jb 0x88a2
movl $0x2, -0x4(%rbp)
jmp 0x88f8
movq -0x40(%rbp), %rax
movl 0x18(%rax), %ecx
shrl %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x88d6
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
subq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x88e5
movq -0x40(%rbp), %rax
movl 0x1c(%rax), %eax
addq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)