// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, %r14
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movl %edx, %r15d
movq %rsi, %r13
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq %rsp, %rsi
andq $0x0, (%rsi)
callq 0x2a85ee
movq 0x90(%rsp), %rbp
andq $0x0, (%rbp)
testb %r15b, %r15b
je 0x2a5cab
movq 0x5cf33e(%rip), %rax    # 0x874fa8
movsd 0x18(%rsp), %xmm1
unpcklps 0x3ce3c9(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%rax), %rdi
subpd 0x3ce3ce(%rip), %xmm1   # 0x674050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3ce39a(%rip), %xmm0   # 0x674030
leaq 0x3cea29(%rip), %rsi    # 0x6746c6
leaq 0x3cfeee(%rip), %rdx    # 0x675b92
movb $0x1, %al
callq 0x2a0380
testq %r13, %r13
movq 0x20(%rsp), %r10
movl %r15d, 0xc(%rsp)
je 0x2a5d7d
movq %rsp, %r15
movq %r13, %r12
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %rax, %r12
jae 0x2a5ce8
movq %r12, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2a85ee
addq %r13, %r12
jmp 0x2a5cc4
movq %rsp, %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0x2a85ee
cmpb $0x0, 0xc(%rsp)
je 0x2a5fb2
xorl %eax, %eax
movq 0x5cf29e(%rip), %r12    # 0x874fa8
leaq 0x3cfe92(%rip), %r14    # 0x675ba3
leaq 0x3cfea4(%rip), %r15    # 0x675bbc
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %rcx, %rax
jae 0x2a5fb2
leaq 0x1(%rax), %r13
movq (%rdx,%rax,8), %rcx
movq 0x8(%rdx,%rax,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x3ce2f1(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3ce2f9(%rip), %xmm1   # 0x674050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3ce2c5(%rip), %xmm0   # 0x674030
movq %r14, %rsi
movq %r15, %rdx
movb $0x1, %al
callq 0x2a0380
movq %r13, %rax
jmp 0x2a5d18
movb 0x3c(%r10), %cl
testb %cl, %cl
jne 0x2a5d90
cmpb $0x0, 0x3d(%r10)
je 0x2a5fc4
xorl %eax, %eax
cmpb $0x0, 0x3f(%r10)
setne %al
leaq (%rax,%rax,2), %rax
incq %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %r11
movq 0x80(%rsp), %rdx
movq (%r14), %rax
movslq (%rax), %rsi
movslq 0x4(%rax), %rdi
movq (%rdx), %r8
movq (%r11), %r9
movq (%r9,%rsi,8), %rdx
subq (%r8,%rsi,8), %rdx
movq (%r9,%rdi,8), %r13
subq (%r8,%rdi,8), %r13
testb %cl, %cl
je 0x2a5de0
imulq %rdx, %r13
jmp 0x2a5dee
cmpb $0x0, 0x3d(%r10)
je 0x2a5fd3
addq %rdx, %r13
movq 0x10(%rsp), %rdx
imulq %rdx, %r13
shlq $0x2, %r13
pushq $0x1
popq %rbp
movq 0x90(%rsp), %rcx
movq %r13, (%rcx)
leal (,%rdx,4), %ecx
movq %rcx, 0x28(%rsp)
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq %r13, %xmm0
cmpq %rcx, %rbp
jae 0x2a5f32
movslq (%rax,%rbp,8), %rcx
movslq 0x4(%rax,%rbp,8), %rdx
movq 0x80(%rsp), %rax
movq (%rax), %rsi
movq (%r11), %rax
movq (%rax,%rcx,8), %r12
subq (%rsi,%rcx,8), %r12
movq (%rax,%rdx,8), %rax
subq (%rsi,%rdx,8), %rax
cmpb $0x0, 0x3c(%r10)
je 0x2a5e68
imulq 0x28(%rsp), %r12
imulq %rax, %r12
jmp 0x2a5e87
cmpb $0x0, 0x3d(%r10)
je 0x2a5e7a
addq %r12, %rax
imulq 0x28(%rsp), %rax
jmp 0x2a5e84
imulq %r12, %rax
imulq 0x10(%rsp), %rax
movq %rax, %r12
leaq (%r12,%r13), %rcx
cmpq 0x18(%rsp), %rcx
jbe 0x2a5f24
movdqa %xmm0, 0x30(%rsp)
movq %r11, %r15
movq %rbp, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x2a85ee
movq 0x90(%rsp), %rax
cmpq (%rax), %r13
movapd 0x30(%rsp), %xmm1
jbe 0x2a5ec4
movq %r13, (%rax)
cmpb $0x0, 0xc(%rsp)
je 0x2a5f19
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
movq 0x5cf0ca(%rip), %rax    # 0x874fa8
movq (%rax), %rdi
unpcklps 0x3ce158(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3ce160(%rip), %xmm1   # 0x674050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3ce12c(%rip), %xmm0   # 0x674030
leaq 0x3cfc98(%rip), %rsi    # 0x675ba3
leaq 0x3cfcaa(%rip), %rdx    # 0x675bbc
movb $0x1, %al
callq 0x2a0380
movq %r12, %rcx
movq 0x20(%rsp), %r10
movq %r15, %r11
incq %rbp
movq (%r14), %rax
movq %rcx, %r13
jmp 0x2a5e15
movdqa %xmm0, 0x30(%rsp)
movq 0x90(%rsp), %rax
cmpq (%rax), %r13
jbe 0x2a5f48
movq %r13, (%rax)
movq %rsp, %rsi
movq %rcx, (%rsi)
movq %rbx, %rdi
callq 0x2a85ee
movl 0xc(%rsp), %eax
testb %al, %al
movapd 0x30(%rsp), %xmm1
je 0x2a5fb2
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
unpcklps 0x3ce0c9(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq 0x5cf02a(%rip), %rax    # 0x874fa8
movq (%rax), %rdi
subpd 0x3ce0c7(%rip), %xmm1   # 0x674050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3ce093(%rip), %xmm0   # 0x674030
leaq 0x3cfbff(%rip), %rsi    # 0x675ba3
leaq 0x3cfc11(%rip), %rdx    # 0x675bbc
movb $0x1, %al
callq 0x2a0380
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x3e(%r10)
je 0x2a5fe5
pushq $0x1
popq %rax
jmp 0x2a5da1
imulq %rdx, %r13
movq 0x10(%rsp), %rdx
imulq %rdx, %r13
jmp 0x2a5dfb
cmpb $0x0, 0x3f(%r10)
pushq $0x18
popq %rax
pushq $0x30
popq %rcx
cmoveq %rax, %rcx
xorl %ebp, %ebp
movq 0x18(%rsp), %rax
xorl %edx, %edx
movq %rcx, 0x18(%rsp)
divq %rcx
movq %rax, %r13
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
xorl %edx, %edx
divq %r13
movq %rax, %r12
movq %r13, %r15
cmpq %r12, %rbp
jae 0x2a603a
movq %r15, (%rsp)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x2a85ee
addq %r13, %r15
incq %rbp
jmp 0x2a601e
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0x2a85ee
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %rax, %r13
cmovbq %r13, %rax
imulq 0x18(%rsp), %rax
movq 0x90(%rsp), %rbp
movq %rax, (%rbp)
cmpb $0x0, 0xc(%rsp)
je 0x2a5fb2
xorl %eax, %eax
movq 0x5cef1d(%rip), %r12    # 0x874fa8
leaq 0x3cfb11(%rip), %r14    # 0x675ba3
leaq 0x3cfb23(%rip), %r15    # 0x675bbc
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
decq %rcx
cmpq %rcx, %rax
jae 0x2a5fb2
leaq 0x1(%rax), %r13
movq (%rdx,%rax,8), %rcx
movq 0x8(%rdx,%rax,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x3cdf70(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3cdf78(%rip), %xmm1   # 0x674050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3cdf44(%rip), %xmm0   # 0x674030
movq %r14, %rsi
movq %r15, %rdx
movb $0x1, %al
callq 0x2a0380
movq %r13, %rax
jmp 0x2a6099
jmp 0x2a610a
jmp 0x2a610a
jmp 0x2a610a
jmp 0x2a610a
jmp 0x2a610a
jmp 0x2a610a
movq %rax, %r14
movq %rbx, %rdi
callq 0x2a877e
movq %r14, %rdi
callq 0x2a0450
nop