// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]yahs/bamlite.c
// Function: bam_hrecs_sort_order
enum bam_sort_order bam_hrecs_sort_order(bam_header_t *header)
{
    char *hdr;
    size_t i, j, len;

    len = header->l_text;
    hdr = header->text;
    
    if (len < 3)
        if (len == 0 || *hdr == '\0')
            return ORDER_UNKNOWN;

    for (i = 0; i < len; i++) {
        if (!strncmp(hdr + i, "@HD", 3)) {
            i += 3;
            if (hdr[i] != '\t')
                return ORDER_UNKNOWN;
            i++;
            while (hdr[i]!='\n') {
                for (j = i; j < len && hdr[j] != '\0' && hdr[j] != '\n' && hdr[j] != '\t'; j++)
                    ;

                if (j - i < 3 || hdr[i + 2] != ':') {
                    return ORDER_UNKNOWN;
                }

                if (!strncmp(hdr + i, "SO", 2)) {
                    i += 3;
                    if (!strncmp(hdr + i, "unsorted", 8))
                        return ORDER_UNSORTED;
                    else if (!strncmp(hdr + i, "queryname", 9))
                        return ORDER_NAME;
                    else if (!strncmp(hdr + i, "coordinate", 10))
                        return ORDER_COORD;
                    else
                        return ORDER_UNKNOWN;
                }

                i = j + 1;
            }
        }
        while(hdr[i]!='\n')
            i++;
    }
    
    return ORDER_UNKNOWN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18(%rdi), %r14
movq 0x28(%rdi), %r13
cmpq $0x2, %r14
ja 0x5559
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x5690
cmpb $0x0, (%r13)
je 0x5690
xorl %r12d, %r12d
movl $0x601, %ebx            # imm = 0x601
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq (%r12,%r13), %r15
movl $0x3, %edx
movq %r15, %rdi
leaq 0x1bba7(%rip), %rsi     # 0x21120
callq 0x20b0
testl %eax, %eax
jne 0x559d
cmpb $0x9, 0x3(%r15)
jne 0x5690
leaq 0x4(%r12), %rax
cmpb $0xa, 0x4(%r13,%r12)
jne 0x55b4
movq %rax, %r12
cmpb $0xa, (%r13,%r12)
leaq 0x1(%r12), %r12
jne 0x559d
cmpq %r14, %r12
jb 0x5566
jmp 0x5680
leaq (%r12,%r13), %r15
addq $0x4, %r15
movq %rax, %r12
cmpq %r14, %rax
jae 0x55e2
movq %rax, %r12
movzbl (%r13,%r12), %ecx
cmpl $0xa, %ecx
ja 0x55d7
btl %ecx, %ebx
jb 0x55e2
incq %r12
cmpq %r12, %r14
jne 0x55c7
movq %r14, %r12
movq %r12, %rcx
subq %rax, %rcx
cmpq $0x3, %rcx
jb 0x5690
cmpb $0x3a, 0x2(%r15)
jne 0x5690
movl $0x2, %edx
movq %r15, %rdi
leaq 0x1bb18(%rip), %rsi     # 0x21124
callq 0x20b0
testl %eax, %eax
je 0x562d
leaq (%r12,%r13), %r15
incq %r15
incq %r12
cmpb $0xa, (%r15)
movq %r12, %rax
jne 0x55bf
jmp 0x559d
addq $0x3, %r15
leaq 0x1baef(%rip), %rsi     # 0x21127
movl $0x8, %edx
movq %r15, %rdi
callq 0x20b0
testl %eax, %eax
je 0x5687
leaq 0x1bae0(%rip), %rsi     # 0x21130
movl $0x9, %edx
movq %r15, %rdi
callq 0x20b0
testl %eax, %eax
je 0x568b
leaq 0x1bad2(%rip), %rsi     # 0x2113a
movl $0xa, %edx
movq %r15, %rdi
callq 0x20b0
xorl %ebp, %ebp
negl %eax
sbbl %ebp, %ebp
orl $0x2, %ebp
jmp 0x5690
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5690
xorl %ebp, %ebp
jmp 0x5690
movl $0x1, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq