// File: /workspace/github_c_makefile_star2_O1/nh13[P]ksw/src/parasail/apps/parasail_aligner.cpp
// Function: std::vector<long long, std::allocator<long long>> calc_batches<parasail_function_info>(long long, bool, unsigned long, parasail_function_info const*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, std::vector<long, std::allocator<long>> const&, std::vector<long, std::allocator<long>> const&, unsigned long&)
vector<long long> calc_batches(
        long long batch_size,
        bool verbose_memory,
        size_t memory_budget,
        const info *function_info,
        const PairVec &vpairs,
        const vector<long> &BEG,
        const vector<long> &END,
        size_t &memory_estimate)
{
    vector<long long> batches;
    batches.push_back(0);
    size_t result_size = sizeof(parasail_result_t);
    memory_estimate = 0;

    if (verbose_memory) {
        eprintf(stdout, "%20s: %.4f GB\n", "memory remaining", memory_budget*GB);
    }

    /* if user specified batch size on command line, we use it */
    if (0 != batch_size) {
        size_t batch_size_ = static_cast<size_t>(batch_size);
        for (size_t batch=batch_size_; batch<vpairs.size(); batch+=batch_size_) {
            batches.push_back(batch);
        }
        batches.push_back(vpairs.size());
        if (verbose_memory) {
            for (size_t batch=0; batch<batches.size()-1; ++batch) {
                long long start = batches[batch];
                long long stop = batches[batch+1];
                eprintf(stdout, "%20s: %lld-%lld\t%.4f GB\n", "batch",
                        start, stop, memory_estimate*GB);
            }
        }
        return batches;
    }

    if (function_info->is_table
            || function_info->is_rowcol
            || function_info->is_trace) {
        size_t multiplier = 1;
        if (function_info->is_table) {
            if (function_info->is_stats) {
                multiplier = 4;
                result_size += sizeof(parasail_result_extra_stats_t);
                result_size += sizeof(parasail_result_extra_stats_tables_t);
            }
            else {
                multiplier = 1;
                result_size += sizeof(parasail_result_extra_tables_t);
            }
        }
        else if (function_info->is_rowcol) {
            if (function_info->is_stats) {
                multiplier = 4;
                result_size += sizeof(parasail_result_extra_stats_t);
                result_size += sizeof(parasail_result_extra_stats_rowcols_t);
            }
            else {
                multiplier = 1;
                result_size += sizeof(parasail_result_extra_rowcols_t);
            }
        }
        else /* if (function_info->is_trace) */ {
            result_size += sizeof(parasail_result_extra_trace_t);
        }
        int i = vpairs[0].first;
        int j = vpairs[0].second;
        long i_beg = BEG[i];
        long i_end = END[i];
        long i_len = i_end-i_beg;
        long j_beg = BEG[j];
        long j_end = END[j];
        long j_len = j_end-j_beg;
        size_t current_size = 0;
        if (function_info->is_table) {
            current_size = sizeof(int) * multiplier * i_len * j_len;
        }
        else if (function_info->is_rowcol) {
            current_size = sizeof(int) * multiplier * (i_len + j_len);
        }
        else /* if (function_info->is_trace) */ {
            current_size = sizeof(int8_t) * multiplier * i_len * j_len;
        }
        memory_estimate = current_size;
        for (size_t index=1; index<vpairs.size(); ++index) {
            i = vpairs[index].first;
            j = vpairs[index].second;
            i_beg = BEG[i];
            i_end = END[i];
            i_len = i_end-i_beg;
            j_beg = BEG[j];
            j_end = END[j];
            j_len = j_end-j_beg;
            unsigned long local_size = 0;
            if (function_info->is_table) {
                local_size = sizeof(int) * multiplier * i_len * j_len;
            }
            else if (function_info->is_rowcol) {
                local_size = sizeof(int) * multiplier * (i_len + j_len);
            }
            else /* if (function_info->is_trace) */ {
                local_size = sizeof(int8_t) * multiplier * i_len * j_len;
            }
            if ((current_size + local_size) > memory_budget) {
                batches.push_back(index);
                if (current_size > memory_estimate) {
                    memory_estimate = current_size;
                }
                if (verbose_memory) {
                    long long start = batches[batches.size()-2];
                    long long stop = batches[batches.size()-1];
                    eprintf(stdout, "%20s: %lld-%lld\t%.4f GB\n", "batch",
                            start, stop, current_size*GB);
                }
                current_size = local_size;
            }
            else {
                current_size += local_size;
            }
        }
        if (current_size > memory_estimate) {
            memory_estimate = current_size;
        }
        batches.push_back(vpairs.size());
        if (verbose_memory) {
            long long start = batches[batches.size()-2];
            long long stop = batches[batches.size()-1];
            eprintf(stdout, "%20s: %lld-%lld\t%.4f GB\n", "batch",
                    start, stop, current_size*GB);
        }
    }
    else {
        if (function_info->is_stats) {
            result_size += sizeof(parasail_result_extra_stats_t);
        }
        /* the score, and perhaps stats */
        size_t results_per_batch = memory_budget / result_size;
        size_t how_many_batches = vpairs.size() / results_per_batch;
        for (size_t i=0; i<how_many_batches; ++i) {
            batches.push_back((i+1)*results_per_batch);
        }
        batches.push_back(vpairs.size());
        if (results_per_batch > vpairs.size()) {
            memory_estimate = result_size*vpairs.size();
        }
        else {
            memory_estimate = result_size*results_per_batch;
        }
        if (verbose_memory) {
            for (size_t batch=0; batch<batches.size()-1; ++batch) {
                long long start = batches[batch];
                long long stop = batches[batch+1];
                eprintf(stdout, "%20s: %lld-%lld\t%.4f GB\n", "batch",
                        start, stop, memory_estimate*GB);
            }
        }
    }

    return batches;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r14
movq %r8, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq %rax, 0x8(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x302f40
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x302f4d
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x3056c0
movq 0x80(%rsp), %rbp
movq $0x0, (%rbp)
cmpb $0x0, 0x14(%rsp)
je 0x302fac
movq 0x5d903d(%rip), %rax    # 0x8dbfa8
movsd 0x20(%rsp), %xmm1
unpcklps 0x39f0c8(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%rax), %rdi
subpd 0x39f0cd(%rip), %xmm1   # 0x6a2050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x39f099(%rip), %xmm0   # 0x6a2030
leaq 0x39f728(%rip), %rsi    # 0x6a26c6
leaq 0x3a0bed(%rip), %rdx    # 0x6a3b92
movb $0x1, %al
callq 0x29e380
testq %r13, %r13
je 0x303026
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %r13, %rax
jbe 0x303003
leaq 0x8(%rsp), %r15
movq %r13, %r12
movq %r12, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x302fe5
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x302ff0
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3056c0
addq %r13, %r12
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %rax, %r12
jb 0x302fc9
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3030a5
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3030b2
movq 0x30(%rsp), %r9
movb 0x3c(%r9), %al
testb %al, %al
jne 0x303054
cmpb $0x0, 0x3d(%r9)
jne 0x303045
cmpb $0x0, 0x3e(%r9)
je 0x303372
testb %al, %al
jne 0x303054
cmpb $0x0, 0x3d(%r9)
je 0x30341a
xorl %ecx, %ecx
cmpb $0x0, 0x3f(%r9)
setne %cl
leaq (%rcx,%rcx,2), %rcx
incq %rcx
movq %rcx, 0x18(%rsp)
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %rdi
movq (%r14), %rcx
movslq (%rcx), %rdx
movslq 0x4(%rcx), %rsi
movq (%rdi), %rdi
movq (%r8), %r8
movq (%r8,%rdx,8), %rcx
subq (%rdi,%rdx,8), %rcx
movq (%r8,%rsi,8), %r12
subq (%rdi,%rsi,8), %r12
testb %al, %al
je 0x30314c
imulq %rcx, %r12
jmp 0x30315a
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x3056c0
cmpb $0x0, 0x14(%rsp)
je 0x303351
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
je 0x303351
xorl %edx, %edx
movq 0x5d8ece(%rip), %r12    # 0x8dbfa8
leaq 0x3a0ac2(%rip), %r14    # 0x6a3ba3
leaq 0x3a0ad4(%rip), %r15    # 0x6a3bbc
leaq 0x1(%rdx), %r13
movq (%rax,%rdx,8), %rcx
movq 0x8(%rax,%rdx,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x39ef3b(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x39ef43(%rip), %xmm1   # 0x6a2050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x39ef0f(%rip), %xmm0   # 0x6a2030
movq %r14, %rsi
movq %r15, %rdx
movb $0x1, %al
callq 0x29e380
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
decq %rcx
movq %r13, %rdx
cmpq %rcx, %r13
jb 0x3030e8
jmp 0x303351
cmpb $0x0, 0x3d(%r9)
je 0x303363
addq %rcx, %r12
imulq 0x18(%rsp), %r12
shlq $0x2, %r12
movq %r12, (%rbp)
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq $0x2, %rcx
jb 0x3032ba
movq 0x18(%rsp), %rcx
leal (,%rcx,4), %ecx
movq %rcx, 0x28(%rsp)
movl $0x1, %r15d
movslq (%rax,%r15,8), %rcx
movslq 0x4(%rax,%r15,8), %rdx
movq 0x70(%rsp), %rax
movq (%rax), %rsi
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rcx,8), %rbp
subq (%rsi,%rcx,8), %rbp
movq (%rax,%rdx,8), %rax
subq (%rsi,%rdx,8), %rax
movq 0x30(%rsp), %rcx
cmpb $0x0, 0x3c(%rcx)
je 0x3031d7
imulq 0x28(%rsp), %rbp
imulq %rax, %rbp
jmp 0x3031f5
cmpb $0x0, 0x3d(%rcx)
je 0x3031e8
addq %rbp, %rax
imulq 0x28(%rsp), %rax
jmp 0x3031f2
imulq %rbp, %rax
imulq 0x18(%rsp), %rax
movq %rax, %rbp
leaq (%r12,%rbp), %r13
cmpq 0x20(%rsp), %r13
jbe 0x30329b
movq %r15, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x303220
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x30322d
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0x3056c0
movq 0x80(%rsp), %rax
cmpq (%rax), %r12
jbe 0x30323d
movq %r12, (%rax)
cmpb $0x0, 0x14(%rsp)
je 0x303298
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
movq 0x5d8d51(%rip), %rax    # 0x8dbfa8
movq (%rax), %rdi
movq %r12, %xmm1
punpckldq 0x39edd9(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x39ede1(%rip), %xmm1   # 0x6a2050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x39edad(%rip), %xmm0   # 0x6a2030
leaq 0x3a0919(%rip), %rsi    # 0x6a3ba3
leaq 0x3a092b(%rip), %rdx    # 0x6a3bbc
movb $0x1, %al
callq 0x29e380
movq %rbp, %r13
incq %r15
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq %r13, %r12
cmpq %rcx, %r15
jb 0x303197
jmp 0x3032bd
movq %r12, %r13
movq 0x80(%rsp), %rax
cmpq (%rax), %r13
jbe 0x3032cd
movq %r13, (%rax)
movq %rcx, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3032e9
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3032f6
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x3056c0
cmpb $0x0, 0x14(%rsp)
je 0x303351
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
movq 0x5d8c98(%rip), %rax    # 0x8dbfa8
movq %r13, %xmm1
punpckldq 0x39ed23(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%rax), %rdi
subpd 0x39ed28(%rip), %xmm1   # 0x6a2050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x39ecf4(%rip), %xmm0   # 0x6a2030
leaq 0x3a0860(%rip), %rsi    # 0x6a3ba3
leaq 0x3a0872(%rip), %rdx    # 0x6a3bbc
movb $0x1, %al
callq 0x29e380
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
imulq %rcx, %r12
imulq 0x18(%rsp), %r12
jmp 0x303164
cmpb $0x0, 0x3f(%r9)
movl $0x18, %eax
movl $0x30, %ecx
cmoveq %rax, %rcx
movq 0x20(%rsp), %rax
xorl %edx, %edx
movq %rcx, 0x20(%rsp)
divq %rcx
movq %rax, %r13
movq 0x8(%r14), %rcx
subq (%r14), %rcx
sarq $0x3, %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %r13
cmpq %rcx, %r13
ja 0x3033eb
movq %rax, %r12
xorl %ebp, %ebp
movq %r13, %r15
movq %r15, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3033d3
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3033e0
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0x3056c0
incq %rbp
addq %r13, %r15
cmpq %r12, %rbp
jb 0x3033b7
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x303424
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
movq 0x80(%rsp), %rbp
jmp 0x303439
movl $0x1, %ecx
jmp 0x303065
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x3056c0
movq 0x80(%rsp), %rbp
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %rax, %r13
cmovbq %r13, %rax
imulq 0x20(%rsp), %rax
movq %rax, (%rbp)
cmpb $0x0, 0x14(%rsp)
je 0x303351
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
je 0x303351
xorl %edx, %edx
movq 0x5d8b2b(%rip), %r12    # 0x8dbfa8
leaq 0x3a071f(%rip), %r14    # 0x6a3ba3
leaq 0x3a0731(%rip), %r15    # 0x6a3bbc
leaq 0x1(%rdx), %r13
movq (%rax,%rdx,8), %rcx
movq 0x8(%rax,%rdx,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x39eb98(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x39eba0(%rip), %xmm1   # 0x6a2050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x39eb6c(%rip), %xmm0   # 0x6a2030
movq %r14, %rsi
movq %r15, %rdx
movb $0x1, %al
callq 0x29e380
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
decq %rcx
movq %r13, %rdx
cmpq %rcx, %r13
jb 0x30348b
jmp 0x303351
jmp 0x3034fb
jmp 0x3034fb
jmp 0x3034fb
jmp 0x3034fb
jmp 0x3034fb
jmp 0x3034fb
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x303512
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x29e260
movq %r14, %rdi
callq 0x29e460