// File: /workspace/github_c_makefile_star2_O3/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 0x15ad6
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 0x15ad9
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 0x15b1d
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 0x15b52
leaq 0x80edc(%rip), %rdx     # 0x96a00
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x13de5
callq 0x4050
movl $0xc, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
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 0x15b80
testb $0x1, %bpl
movq (%rsp), %rcx
je 0x15bd5
cmpq $0x8, %r12
je 0x15bae
cmpq $0x4, %r12
jne 0x15bf3
movl (%rcx), %edi
jmp 0x15bb1
callq 0x4050
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x4150
leaq 0x82936(%rip), %rdx     # 0x984ce
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x13de5
movl %ebp, (%rbx)
jmp 0x15b3e
movq (%rcx), %rdi
movq %r15, %rdx
subq %rdi, %rdx
jbe 0x15bd5
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 0x15be6
cmpq $0x4, %r12
jne 0x15bf3
movl %r15d, (%rcx)
jmp 0x15be9
movq %r15, (%rcx)
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x15b43
callq 0x4270