// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/misc/bamcheck.c
// Function: realloc_buffers
void realloc_buffers(stats_t *stats, int seq_len)
{
    int n = 2*(1 + seq_len - stats->nbases) + stats->nbases;

    stats->quals_1st = realloc(stats->quals_1st, n*stats->nquals*sizeof(uint64_t));
    if ( !stats->quals_1st )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*stats->nquals*sizeof(uint64_t));
    memset(stats->quals_1st + stats->nbases*stats->nquals, 0, (n-stats->nbases)*stats->nquals*sizeof(uint64_t));

    stats->quals_2nd = realloc(stats->quals_2nd, n*stats->nquals*sizeof(uint64_t));
    if ( !stats->quals_2nd )
        error("Could not realloc buffers, the sequence too long: %d (2x%ld)\n", seq_len,n*stats->nquals*sizeof(uint64_t));
    memset(stats->quals_2nd + stats->nbases*stats->nquals, 0, (n-stats->nbases)*stats->nquals*sizeof(uint64_t));

    if ( stats->mpc_buf )
    {
        stats->mpc_buf = realloc(stats->mpc_buf, n*stats->nquals*sizeof(uint64_t));
        if ( !stats->mpc_buf )
            error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*stats->nquals*sizeof(uint64_t));
        memset(stats->mpc_buf + stats->nbases*stats->nquals, 0, (n-stats->nbases)*stats->nquals*sizeof(uint64_t));
    }

    stats->acgt_cycles = realloc(stats->acgt_cycles, n*4*sizeof(uint64_t));
    if ( !stats->acgt_cycles )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*4*sizeof(uint64_t));
    memset(stats->acgt_cycles + stats->nbases*4, 0, (n-stats->nbases)*4*sizeof(uint64_t));

    stats->read_lengths = realloc(stats->read_lengths, n*sizeof(uint64_t));
    if ( !stats->read_lengths )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*sizeof(uint64_t));
    memset(stats->read_lengths + stats->nbases, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->insertions = realloc(stats->insertions, n*sizeof(uint64_t));
    if ( !stats->insertions )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*sizeof(uint64_t));
    memset(stats->insertions + stats->nbases, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->deletions = realloc(stats->deletions, n*sizeof(uint64_t));
    if ( !stats->deletions )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,n*sizeof(uint64_t));
    memset(stats->deletions + stats->nbases, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->ins_cycles_1st = realloc(stats->ins_cycles_1st, (n+1)*sizeof(uint64_t));
    if ( !stats->ins_cycles_1st )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,(n+1)*sizeof(uint64_t));
    memset(stats->ins_cycles_1st + stats->nbases + 1, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->ins_cycles_2nd = realloc(stats->ins_cycles_2nd, (n+1)*sizeof(uint64_t));
    if ( !stats->ins_cycles_2nd )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,(n+1)*sizeof(uint64_t));
    memset(stats->ins_cycles_2nd + stats->nbases + 1, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->del_cycles_1st = realloc(stats->del_cycles_1st, (n+1)*sizeof(uint64_t));
    if ( !stats->del_cycles_1st )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,(n+1)*sizeof(uint64_t));
    memset(stats->del_cycles_1st + stats->nbases + 1, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->del_cycles_2nd = realloc(stats->del_cycles_2nd, (n+1)*sizeof(uint64_t));
    if ( !stats->del_cycles_2nd )
        error("Could not realloc buffers, the sequence too long: %d (%ld)\n", seq_len,(n+1)*sizeof(uint64_t));
    memset(stats->del_cycles_2nd + stats->nbases + 1, 0, (n-stats->nbases)*sizeof(uint64_t));

    stats->nbases = n;

    // Realloc the coverage distribution buffer
    int *rbuffer = calloc(sizeof(int),seq_len*5);
    n = stats->cov_rbuf.size-stats->cov_rbuf.start;
    memcpy(rbuffer,stats->cov_rbuf.buffer+stats->cov_rbuf.start,n);
    if ( stats->cov_rbuf.start>1 )
        memcpy(rbuffer+n,stats->cov_rbuf.buffer,stats->cov_rbuf.start);
    stats->cov_rbuf.start = 0;
    free(stats->cov_rbuf.buffer);
    stats->cov_rbuf.buffer = rbuffer;
    stats->cov_rbuf.size = seq_len*5;

    realloc_rseq_buffer(stats);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl 0x8(%rdi), %eax
movl %esi, %ecx
subl %eax, %ecx
leal (%rax,%rcx,2), %r13d
addl $0x2, %r13d
movq 0x18(%rdi), %rdi
movslq 0x4(%r14), %rsi
movslq %r13d, %r15
imulq %r15, %rsi
shlq $0x3, %rsi
callq 0x3430
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x57fa
movl 0x4(%r14), %ebp
movl 0x8(%r14), %ecx
movl %ebp, %edx
imull %ecx, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdi
movl %r13d, %eax
subl %ecx, %eax
imull %ebp, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x20(%r14), %rdi
imull %r13d, %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
callq 0x3430
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x580f
movl 0x4(%r14), %ebp
movl 0x8(%r14), %ecx
movl %ebp, %edx
imull %ecx, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdi
movl %r13d, %eax
subl %ecx, %eax
imull %ebp, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x198(%r14), %rdi
testq %rdi, %rdi
je 0x5591
imull %r13d, %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
callq 0x3430
movq %rax, 0x198(%r14)
testq %rax, %rax
je 0x57fa
movl 0x4(%r14), %ecx
movl 0x8(%r14), %edx
movl %r13d, %esi
subl %edx, %esi
imull %ecx, %esi
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,8), %rdi
movslq %esi, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x50(%r14), %rdi
leal (,%r13,4), %eax
movslq %eax, %r12
shlq $0x3, %r12
movq %r12, %rsi
callq 0x3430
movq %rax, 0x50(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x5, %rcx
addq %rcx, %rax
shlq $0x5, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3260
movq 0x58(%r14), %rdi
leaq (,%r15,8), %r12
movq %r12, %rsi
callq 0x3430
movq %rax, 0x58(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x60(%r14), %rdi
movq %r12, %rsi
callq 0x3430
movq %rax, 0x60(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x68(%r14), %rdi
movq %r12, %rsi
callq 0x3430
movq %rax, 0x68(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x70(%r14), %rdi
leaq 0x8(,%r15,8), %r12
movq %r12, %rsi
callq 0x3430
movq %rax, 0x70(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x78(%r14), %rdi
movq %r12, %rsi
callq 0x3430
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x80(%r14), %rdi
movq %r12, %rsi
callq 0x3430
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
addq $0x8, %rdi
movq %r15, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x3260
movq 0x88(%r14), %rdi
movq %r12, %rsi
callq 0x3430
movq %rax, 0x88(%r14)
testq %rax, %rax
je 0x57ec
movslq 0x8(%r14), %rcx
leaq (%rax,%rcx,8), %rdi
addq $0x8, %rdi
subq %rcx, %r15
shlq $0x3, %r15
xorl %esi, %esi
movq %r15, %rdx
callq 0x3260
movl %r13d, 0x8(%r14)
leal (%rbx,%rbx,4), %ebp
movslq %ebp, %rsi
movl $0x4, %edi
callq 0x32e0
movq %rax, %rbx
movslq 0x170(%r14), %r13
movslq 0x174(%r14), %r12
subq %r12, %r13
movq 0x178(%r14), %r15
leaq (%r15,%r12,4), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x3370
cmpq $0x2, %r12
jl 0x57b5
leaq (%rbx,%r13,4), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3370
movl $0x0, 0x174(%r14)
movq %r15, %rdi
callq 0x3060
movq %rbx, 0x178(%r14)
movl %ebp, 0x170(%r14)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5395
leaq 0x14e02(%rip), %rdi     # 0x1a5f5
movl %ebx, %esi
movq %r12, %rdx
jmp 0x5824
movslq 0x4(%r14), %rdx
imulq %r15, %rdx
shlq $0x3, %rdx
leaq 0x14de8(%rip), %rdi     # 0x1a5f5
jmp 0x5822
movslq 0x4(%r14), %rdx
imulq %r15, %rdx
shlq $0x3, %rdx
leaq 0x14e0f(%rip), %rdi     # 0x1a631
movl %ebx, %esi
xorl %eax, %eax
callq 0x4926