// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_enc_vint
int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
{
    int32_t max = INT32_MIN, min = INT32_MAX;
    int i;
    if (n <= 0) {
        return bcf_enc_size(s, 0, BCF_BT_NULL);
    } else if (n == 1) {
        return bcf_enc_int1(s, a[0]);
    } else {
        if (wsize <= 0) wsize = n;

        // Equivalent to:
        // for (i = 0; i < n; ++i) {
        //     if (a[i] == bcf_int32_missing || a[i] == bcf_int32_vector_end )
        //         continue;
        //     if (max < a[i]) max = a[i];
        //     if (min > a[i]) min = a[i];
        // }
        int max4[4] = {INT32_MIN, INT32_MIN, INT32_MIN, INT32_MIN};
        int min4[4] = {INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX};
        for (i = 0; i < (n&~3); i+=4) {
            // bcf_int32_missing    == INT32_MIN and
            // bcf_int32_vector_end == INT32_MIN+1.
            // We skip these, but can mostly avoid explicit checking
            if (max4[0] < a[i+0]) max4[0] = a[i+0];
            if (max4[1] < a[i+1]) max4[1] = a[i+1];
            if (max4[2] < a[i+2]) max4[2] = a[i+2];
            if (max4[3] < a[i+3]) max4[3] = a[i+3];
            if (min4[0] > a[i+0] && a[i+0] > INT32_MIN+1) min4[0] = a[i+0];
            if (min4[1] > a[i+1] && a[i+1] > INT32_MIN+1) min4[1] = a[i+1];
            if (min4[2] > a[i+2] && a[i+2] > INT32_MIN+1) min4[2] = a[i+2];
            if (min4[3] > a[i+3] && a[i+3] > INT32_MIN+1) min4[3] = a[i+3];
        }
        min = min4[0];
        if (min > min4[1]) min = min4[1];
        if (min > min4[2]) min = min4[2];
        if (min > min4[3]) min = min4[3];
        max = max4[0];
        if (max < max4[1]) max = max4[1];
        if (max < max4[2]) max = max4[2];
        if (max < max4[3]) max = max4[3];
        for (; i < n; ++i) {
            if (max < a[i]) max = a[i];
            if (min > a[i] && a[i] > INT32_MIN+1) min = a[i];
        }

        if (max <= BCF_MAX_BT_INT8 && min >= BCF_MIN_BT_INT8) {
            if (bcf_enc_size(s, wsize, BCF_BT_INT8) < 0 ||
                ks_resize(s, s->l + n) < 0)
                return -1;
            uint8_t *p = (uint8_t *) s->s + s->l;
            for (i = 0; i < n; ++i, p++) {
                if ( a[i]==bcf_int32_vector_end )   *p = bcf_int8_vector_end;
                else if ( a[i]==bcf_int32_missing ) *p = bcf_int8_missing;
                else *p = a[i];
            }
            s->l += n;
        } else if (max <= BCF_MAX_BT_INT16 && min >= BCF_MIN_BT_INT16) {
            uint8_t *p;
            if (bcf_enc_size(s, wsize, BCF_BT_INT16) < 0 ||
                ks_resize(s, s->l + n * sizeof(int16_t)) < 0)
                return -1;
            p = (uint8_t *) s->s + s->l;
            for (i = 0; i < n; ++i)
            {
                int16_t x;
                if ( a[i]==bcf_int32_vector_end ) x = bcf_int16_vector_end;
                else if ( a[i]==bcf_int32_missing ) x = bcf_int16_missing;
                else x = a[i];
                i16_to_le(x, p);
                p += sizeof(int16_t);
            }
            s->l += n * sizeof(int16_t);
        } else {
            uint8_t *p;
            if (bcf_enc_size(s, wsize, BCF_BT_INT32) < 0 ||
                ks_resize(s, s->l + n * sizeof(int32_t)) < 0)
                return -1;
            p = (uint8_t *) s->s + s->l;
            for (i = 0; i < n; ++i) {
                i32_to_le(a[i], p);
                p += sizeof(int32_t);
            }
            s->l += n * sizeof(int32_t);
        }
    }

    return 0;
}

// Assembly:
testl %esi, %esi
jle 0x27d5a
cmpl $0x1, %esi
jne 0x27d63
movl (%rdx), %esi
jmp 0x28086
xorl %esi, %esi
xorl %edx, %edx
jmp 0x27feb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, 0x4(%rsp)
movq %rdx, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
andl $0x7ffffffc, %esi       # imm = 0x7FFFFFFC
movq %rsi, 0x20(%rsp)
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl $0x80000000, %edi       # imm = 0x80000000
xorl %ebp, %ebp
movl $0x80000002, %esi       # imm = 0x80000002
movl $0x80000000, %r9d       # imm = 0x80000000
movl $0x80000000, %eax       # imm = 0x80000000
movl $0x80000000, %r10d      # imm = 0x80000000
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
cmpq 0x20(%rsp), %rbp
jae 0x27e42
movq 0x8(%rsp), %rcx
movl (%rcx,%rbp,4), %r14d
cmpl %r14d, %r10d
cmovlel %r14d, %r10d
movl 0x4(%rcx,%rbp,4), %r15d
cmpl %r15d, %eax
cmovlel %r15d, %eax
movl 0x8(%rcx,%rbp,4), %r11d
cmpl %r11d, %r9d
cmovlel %r11d, %r9d
movl 0xc(%rcx,%rbp,4), %ecx
cmpl %ecx, %edi
cmovlel %ecx, %edi
cmpl %r14d, %r13d
movl %r14d, %ebx
cmovll %r13d, %ebx
cmpl %esi, %r14d
cmovgel %ebx, %r13d
cmpl %r15d, %edx
movl %r15d, %ebx
cmovll %edx, %ebx
cmpl %esi, %r15d
cmovgel %ebx, %edx
cmpl %r11d, %r12d
movl %r11d, %ebx
cmovll %r12d, %ebx
cmpl %esi, %r11d
cmovgel %ebx, %r12d
cmpl %ecx, %r8d
movl %ecx, %r11d
cmovll %r8d, %r11d
cmpl %esi, %ecx
cmovgel %r11d, %r8d
addq $0x4, %rbp
jmp 0x27dc3
cmpl %edx, %r13d
cmovll %r13d, %edx
cmpl %r12d, %edx
cmovgel %r12d, %edx
cmpl %r8d, %edx
cmovgel %r8d, %edx
cmpl %eax, %r10d
cmovgl %r10d, %eax
cmpl %r9d, %eax
cmovlel %r9d, %eax
cmpl %edi, %eax
cmovlel %edi, %eax
movq 0x10(%rsp), %r15
movl %r15d, %r12d
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r14
movl 0x4(%rsp), %esi
cmpq %r12, %rbp
jae 0x27ea3
movl (%r14,%rbp,4), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
cmpl %ecx, %edx
movl %ecx, %edi
cmovll %edx, %edi
cmpl $0x80000002, %ecx       # imm = 0x80000002
cmovgel %edi, %edx
incq %rbp
jmp 0x27e80
testl %esi, %esi
cmovlel %r15d, %esi
cmpl $0x7f, %eax
jg 0x27f11
cmpl $-0x78, %edx
jl 0x27f11
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x27feb
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x27fda
movq (%rbx), %rsi
addq %r12, %rsi
movq %rbx, %rdi
callq 0x2811b
testl %eax, %eax
js 0x27fda
movq 0x10(%rbx), %rax
addq (%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %r12
je 0x27fd5
movl (%r14,%rcx,4), %edx
cmpl $0x80000001, %edx       # imm = 0x80000001
je 0x27f07
movl %edx, %esi
negl %esi
jno 0x27f09
movb $-0x80, %dl
jmp 0x27f09
movb $-0x7f, %dl
movb %dl, (%rax,%rcx)
incq %rcx
jmp 0x27ee8
cmpl $0x7fff, %eax           # imm = 0x7FFF
jg 0x27f85
cmpl $0xffff8008, %edx       # imm = 0xFFFF8008
jl 0x27f85
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x27feb
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x27fda
addl %r15d, %r15d
movq (%rbx), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2811b
testl %eax, %eax
js 0x27fda
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
addq %rax, %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x27fcd
movl (%r14,%rdx,4), %esi
cmpl $0x80000001, %esi       # imm = 0x80000001
je 0x27f78
movl %esi, %edi
negl %edi
jno 0x27f7c
movw $0x8000, %si            # imm = 0x8000
jmp 0x27f7c
movw $0x8001, %si            # imm = 0x8001
movw %si, (%rcx,%rdx,2)
incq %rdx
jmp 0x27f5b
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x27feb
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x27fda
movq %r12, %r15
shlq $0x2, %r15
movq (%rbx), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2811b
testl %eax, %eax
js 0x27fda
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
addq %rax, %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x27fcd
movl (%r14,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0x27fbc
addq %r15, %rax
movq %rax, (%rbx)
jmp 0x27fd8
addq %r12, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq