// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x3, -0x30(%rbp)
jae 0x3f0c
cmpq $0x0, -0x30(%rbp)
je 0x3efe
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3f0a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4128
jmp 0x3f0c
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x4121
movq -0x18(%rbp), %rdi
addq -0x20(%rbp), %rdi
leaq 0x2d1d4(%rip), %rsi     # 0x31105
movl $0x3, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x40ed
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
je 0x3f6d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4128
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x40eb
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x30(%rbp), %rcx
movb %al, -0x31(%rbp)
jae 0x3fe6
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
je 0x3fe6
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x31(%rbp)
je 0x3fe6
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x3fef
jmp 0x3fff
jmp 0x3ff1
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x3f96
movq -0x28(%rbp), %rax
subq -0x20(%rbp), %rax
cmpq $0x3, %rax
jb 0x401f
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl 0x2(%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x402b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4128
movq -0x18(%rbp), %rdi
addq -0x20(%rbp), %rdi
leaq 0x2d0cf(%rip), %rsi     # 0x31109
movl $0x2, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x40da
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq -0x20(%rbp), %rdi
leaq 0x2d0a4(%rip), %rsi     # 0x3110c
movl $0x8, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x4083
movl $0x0, -0x4(%rbp)
jmp 0x4128
movq -0x18(%rbp), %rdi
addq -0x20(%rbp), %rdi
leaq 0x2d083(%rip), %rsi     # 0x31115
movl $0x9, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x40aa
movl $0x1, -0x4(%rbp)
jmp 0x4128
movq -0x18(%rbp), %rdi
addq -0x20(%rbp), %rdi
leaq 0x2d066(%rip), %rsi     # 0x3111f
movl $0xa, %edx
callq 0x20a0
cmpl $0x0, %eax
jne 0x40d1
movl $0x2, -0x4(%rbp)
jmp 0x4128
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4128
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3f79
jmp 0x40ed
jmp 0x40ef
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
je 0x410e
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x40ef
jmp 0x4110
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3f14
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)