// File: /workspace/github_c_makefile_star2_O1/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 0x16093
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 0x16096
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 0x160da
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 0x1610f
leaq 0x8387f(%rip), %rdx     # 0x99960
movl $0x1, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x14378
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 0x1613d
testb $0x1, %bpl
movq (%rsp), %rcx
je 0x16192
cmpq $0x8, %r12
je 0x1616b
cmpq $0x4, %r12
jne 0x161b0
movl (%rcx), %edi
jmp 0x1616e
callq 0x4050
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x4150
leaq 0x85372(%rip), %rdx     # 0x9b4c7
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rcx
xorl %eax, %eax
callq 0x14378
movl %ebp, (%rbx)
jmp 0x160fb
movq (%rcx), %rdi
movq %r15, %rdx
subq %rdi, %rdx
jbe 0x16192
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 0x161a3
cmpq $0x4, %r12
jne 0x161b0
movl %r15d, (%rcx)
jmp 0x161a6
movq %r15, (%rcx)
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x16100
callq 0x4270