// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hts.c
// Function: hts_resize_array_
int hts_resize_array_(size_t item_size, size_t num, size_t size_sz,
                      void *size_in_out, void **ptr_in_out, int flags,
                      const char *func) {
    /* If new_size and item_size are both below this limit, multiplying them
       together can't overflow */
    const size_t safe = (size_t) 1 << (sizeof(size_t) * 4);
    void *new_ptr;
    size_t bytes, new_size;

    new_size = num;
    kroundup_size_t(new_size);
    bytes = item_size * new_size;

    /* Check for overflow.  Both ensure that alloc will fit in alloc_in_out (we
       make the pessimistic assumption that *alloc_in_out is signed), and that
       bytes has not wrapped around. */

    if ((new_size > (((size_t) 1 << (size_sz * 8 - 1)) - 1))
        || (((item_size > safe) || (new_size > safe))
            && bytes / new_size != item_size)) {
        hts_log(HTS_LOG_ERROR, func, "Memory allocation too large");
        errno = ENOMEM;
        return -1;
    }

    new_ptr = realloc(*ptr_in_out, bytes);
    if (new_ptr == NULL) {
        int save_errno = errno;
        hts_log(HTS_LOG_ERROR, func, "%s", strerror(errno));
        errno = save_errno;
        return -1;
    }

    if (flags & HTS_RESIZE_CLEAR) {
        size_t old_size;
        switch (size_sz) {
        case 4: old_size = *((uint32_t *) size_in_out); break;
        case 8: old_size = *((uint64_t *) size_in_out); break;
        default: abort();
        }
        if (new_size > old_size) {
            memset((char *) new_ptr + old_size * item_size, 0,
                   (new_size - old_size) * item_size);
        }
    }

    switch (size_sz) {
    case 4: *((uint32_t *) size_in_out) = new_size; break;
    case 8: *((uint64_t *) size_in_out) = new_size; break;
    default: abort();
    }

    *ptr_in_out = new_ptr;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %ebp
movq %r8, %rbx
movq %rcx, %r8
movq %rdx, %r12
movq %rdi, %r13
testq %rsi, %rsi
je 0x12cc9
movq %rsi, %r15
leaq -0x1(%rsi), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x20, %rax
orq %rcx, %rax
negq %r15
shrq $0x3f, %r15
addq %rax, %r15
jmp 0x12ccc
xorl %r15d, %r15d
movq %r15, %rax
mulq %r13
seto %dl
leal (,%r12,8), %ecx
decb %cl
movq %r15, %rsi
shrq %cl, %rsi
movq 0x40(%rsp), %r14
testq %rsi, %rsi
jne 0x12d10
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpq %rcx, %r13
seta %sil
cmpq %rcx, %r15
seta %cl
orb %sil, %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x12d41
leaq 0x65cda(%rip), %rdx     # 0x789f1
pushq $0x1
popq %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x110c6
callq 0x4050
movl $0xc, (%rax)
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, (%rsp)
movq (%rbx), %rdi
movq %rax, %rsi
callq 0x4840
testq %rax, %rax
je 0x12d6f
testb $0x1, %bpl
movq (%rsp), %rcx
je 0x12dc2
cmpq $0x8, %r12
je 0x12d9b
cmpq $0x4, %r12
jne 0x12de0
movl (%rcx), %edi
jmp 0x12d9e
callq 0x4050
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x4150
leaq 0x676a2(%rip), %rdx     # 0x7a429
pushq $0x1
popq %rdi
movq %r14, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
movl %ebp, (%rbx)
jmp 0x12d2f
movq (%rcx), %rdi
movq %r15, %rdx
subq %rdi, %rdx
jbe 0x12dc2
imulq %r13, %rdi
addq %rax, %rdi
imulq %r13, %rdx
xorl %esi, %esi
movq %rax, %r14
callq 0x4260
movq %r14, %rax
movq (%rsp), %rcx
cmpq $0x8, %r12
je 0x12dd3
cmpq $0x4, %r12
jne 0x12de0
movl %r15d, (%rcx)
jmp 0x12dd6
movq %r15, (%rcx)
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x12d32
callq 0x4270