// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x332b4
movq %rdx, %r14
movl %esi, %r15d
cmpl $0x1, %esi
jne 0x3330d
movl (%r14), %r15d
movq (%rbx), %rax
addq $0x5, %rax
cmpq %rax, 0x8(%rbx)
jae 0x3328a
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rcx, %rcx
cmoveq %rdx, %r14
addq %rax, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x4860
testq %rax, %rax
je 0x3340c
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movl %r15d, %edx
negl %edx
jo 0x33616
cmpl $0x80000001, %r15d      # imm = 0x80000001
jne 0x3361e
movw $0x8111, (%rcx,%rax)    # imm = 0x8111
jmp 0x33637
movq (%rbx), %rax
incq %rax
cmpq %rax, 0x8(%rbx)
jae 0x332f7
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r14d, %r14d
testq %rcx, %rcx
cmoveq %rdx, %r14
addq %rax, %r14
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x4860
testq %rax, %rax
je 0x3340c
movq %rax, 0x10(%rbx)
movq %r14, 0x8(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movq (%rbx), %r13
incq %r13
jmp 0x3363e
testl %ecx, %ecx
cmovlel %r15d, %ecx
movl %r15d, %eax
andl $0x7ffffffc, %eax       # imm = 0x7FFFFFFC
je 0x33416
movl %ecx, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movl %eax, %eax
movq %rax, 0x20(%rsp)
movl $0x80000000, %edi       # imm = 0x80000000
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %esi, %esi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x80000000, %edx       # imm = 0x80000000
movl $0x80000000, %r9d       # imm = 0x80000000
movl $0x80000000, %r8d       # imm = 0x80000000
movl %ebp, %r15d
movl (%r14,%rsi,4), %ebx
movl 0x4(%r14,%rsi,4), %r12d
cmpl %ebx, %edi
cmovlel %ebx, %edi
movl %edi, 0xc(%rsp)
cmpl %r12d, %edx
cmovlel %r12d, %edx
movl 0x8(%r14,%rsi,4), %ecx
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
movq %r14, %r13
movl 0xc(%r14,%rsi,4), %r14d
cmpl %r14d, %r8d
cmovlel %r14d, %r8d
cmpl %ebx, %ebp
movl %ebx, %ebp
cmovll %r15d, %ebp
movl $0x80000002, %edi       # imm = 0x80000002
cmpl %edi, %ebx
movl %eax, %ebx
cmovll %r15d, %ebp
cmpl %r12d, %eax
movl %r12d, %eax
cmovll %ebx, %eax
cmpl %edi, %r12d
movl %r11d, %r15d
cmovll %ebx, %eax
cmpl %ecx, %r11d
movl %ecx, %r11d
cmovll %r15d, %r11d
cmpl %edi, %ecx
movl %r10d, %ecx
cmovll %r15d, %r11d
cmpl %r14d, %r10d
movl %r14d, %r10d
cmovll %ecx, %r10d
cmpl %edi, %r14d
movl 0xc(%rsp), %edi
movq %r13, %r14
cmovll %ecx, %r10d
addq $0x4, %rsi
cmpq 0x20(%rsp), %rsi
jb 0x33364
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r15
movl 0x8(%rsp), %ecx
jmp 0x33444
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x33643
xorl %esi, %esi
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl $0x80000000, %r8d       # imm = 0x80000000
movl $0x80000000, %r9d       # imm = 0x80000000
movl $0x80000000, %edx       # imm = 0x80000000
movl $0x80000000, %edi       # imm = 0x80000000
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpl %eax, %ebp
cmovll %ebp, %eax
cmpl %r11d, %eax
cmovgel %r11d, %eax
cmpl %r10d, %eax
cmovgel %r10d, %eax
cmpl %edx, %edi
cmovgl %edi, %edx
cmpl %r9d, %edx
cmovlel %r9d, %edx
cmpl %r8d, %edx
cmovlel %r8d, %edx
cmpl %r15d, %esi
jge 0x3349c
movl %esi, %esi
movl %r15d, %edi
movl (%r14,%rsi,4), %r9d
cmpl %r9d, %edx
cmovlel %r9d, %edx
cmpl %r9d, %eax
movl %r9d, %r8d
cmovll %eax, %r8d
cmpl $0x80000002, %r9d       # imm = 0x80000002
cmovgel %r8d, %eax
incq %rsi
cmpq %rsi, %rdi
jne 0x33474
cmpl $0x7f, %edx
jg 0x33554
cmpl $-0x78, %eax
jl 0x33554
movq %rbx, %rdi
movl %ecx, %esi
movl $0x1, %edx
callq 0x33722
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x33643
movl %r15d, %r13d
movq (%rbx), %rax
addq %r13, %rax
cmpq %rax, 0x8(%rbx)
jae 0x33510
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r12d, %r12d
testq %rcx, %rcx
cmoveq %rdx, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4860
testq %rax, %rax
je 0x33643
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq 0x10(%rbx), %rax
addq (%rbx), %rax
cmpl $0x2, %r15d
movl $0x1, %ecx
cmovgel %r15d, %ecx
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
cmpl $0x80000001, %esi       # imm = 0x80000001
je 0x3353d
movl %esi, %edi
negl %edi
jno 0x33540
movb $-0x80, %sil
jmp 0x33540
movb $-0x7f, %sil
movb %sil, (%rax,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x33526
addq (%rbx), %r13
jmp 0x3363e
cmpl $0x7fff, %edx           # imm = 0x7FFF
jg 0x33654
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jl 0x33654
movq %rbx, %rdi
movl %ecx, %esi
movl $0x2, %edx
callq 0x33722
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x33643
leal (%r15,%r15), %r8d
movq (%rbx), %rax
addq %r8, %rax
cmpq %rax, 0x8(%rbx)
jae 0x335d0
movq %r8, %r13
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r12d, %r12d
testq %rcx, %rcx
cmoveq %rdx, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4860
testq %rax, %rax
je 0x33643
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq %r13, %r8
movq (%rbx), %r13
movq 0x10(%rbx), %rax
addq %r13, %rax
cmpl $0x2, %r15d
movl $0x1, %ecx
cmovgel %r15d, %ecx
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
cmpl $0x80000001, %esi       # imm = 0x80000001
je 0x33601
movl %esi, %edi
negl %edi
jno 0x33605
movw $0x8000, %si            # imm = 0x8000
jmp 0x33605
movw $0x8001, %si            # imm = 0x8001
movw %si, (%rax,%rdx,2)
incq %rdx
cmpq %rdx, %rcx
jne 0x335e9
addq %r8, %r13
jmp 0x3363e
movw $0x8011, (%rcx,%rax)    # imm = 0x8011
jmp 0x33637
leal 0x78(%r15), %edx
cmpl $0xf7, %edx
ja 0x336e8
movb $0x11, (%rcx,%rax)
movb %r15b, 0x1(%rcx,%rax)
movq (%rbx), %r13
addq $0x2, %r13
movq %r13, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl %ecx, %esi
movl $0x3, %edx
callq 0x33722
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x33643
movl %r15d, %edi
shlq $0x2, %rdi
movq (%rbx), %rax
addq %rdi, %rax
cmpq %rax, 0x8(%rbx)
jae 0x336b8
movq %rdi, %r13
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %r12d, %r12d
testq %rcx, %rcx
cmoveq %rdx, %r12
addq %rax, %r12
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x4860
testq %rax, %rax
je 0x33643
movq %rax, 0x10(%rbx)
movq %r12, 0x8(%rbx)
movq %r13, %rdi
movq (%rbx), %r13
movq 0x10(%rbx), %rax
addq %r13, %rax
cmpl $0x2, %r15d
movl $0x1, %ecx
cmovgel %r15d, %ecx
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x336d1
addq %rdi, %r13
jmp 0x3363e
leal 0x7ff8(%r15), %edx
cmpl $0xfff7, %edx           # imm = 0xFFF7
ja 0x3370d
movb $0x12, (%rcx,%rax)
movw %r15w, 0x1(%rcx,%rax)
movq (%rbx), %r13
addq $0x3, %r13
jmp 0x3363e
movb $0x13, (%rcx,%rax)
movl %r15d, 0x1(%rcx,%rax)
movq (%rbx), %r13
addq $0x5, %r13
jmp 0x3363e