// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rcx, 0x20(%rsp)
movl %edx, %r15d
movq %rsi, %r13
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
xorl %esi, %esi
callq 0x30596e
movq 0x80(%rsp), %rbp
movq $0x0, (%rbp)
testb %r15b, %r15b
je 0x302fa1
movq 0x60d048(%rip), %rax    # 0x90ffa8
movsd 0x20(%rsp), %xmm1
unpcklps 0x3d20d3(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%rax), %rdi
subpd 0x3d20d8(%rip), %xmm1   # 0x6d5050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3d20a4(%rip), %xmm0   # 0x6d5030
leaq 0x3d2753(%rip), %rsi    # 0x6d56e6
leaq 0x3d3c18(%rip), %rdx    # 0x6d6bb2
movb $0x1, %al
callq 0x29e380
testq %r13, %r13
je 0x30302d
movl %r15d, 0xc(%rsp)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x30300d
leaq 0x10(%rsp), %r15
movq %r13, %r12
movq %r12, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x302fe9
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x302ffb
movq %rbx, %rdi
movq %r15, %rdx
callq 0x30596e
movq (%r14), %rax
movq 0x8(%r14), %rcx
addq %r13, %r12
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rdx, %r12
jb 0x302fcd
movq %rdx, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x303099
movq %rdx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
movl 0xc(%rsp), %eax
jmp 0x3030aa
movb 0x3c(%r12), %cl
testb %cl, %cl
jne 0x303042
cmpb $0x0, 0x3d(%r12)
je 0x30335b
xorl %eax, %eax
cmpb $0x0, 0x3f(%r12)
setne %al
leaq (%rax,%rax,2), %rax
incq %rax
movq %rax, 0x18(%rsp)
movq %r12, 0x30(%rsp)
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %r8
movq (%r14), %rax
movslq (%rax), %rsi
movslq 0x4(%rax), %rdi
movq (%r8), %r8
movq (%rdx), %r9
movq (%r9,%rsi,8), %rdx
subq (%r8,%rsi,8), %rdx
movq (%r9,%rdi,8), %r12
subq (%r8,%rdi,8), %r12
testb %cl, %cl
je 0x303141
imulq %rdx, %r12
jmp 0x303153
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x30596e
movl 0xc(%rsp), %eax
testb %al, %al
je 0x303349
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
je 0x303349
xorl %edx, %edx
movq 0x60ced9(%rip), %r12    # 0x90ffa8
leaq 0x3d3aed(%rip), %r14    # 0x6d6bc3
leaq 0x3d3aff(%rip), %r15    # 0x6d6bdc
leaq 0x1(%rdx), %r13
movq (%rax,%rdx,8), %rcx
movq 0x8(%rax,%rdx,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x3d1f46(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3d1f4e(%rip), %xmm1   # 0x6d5050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3d1f1a(%rip), %xmm0   # 0x6d5030
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 0x3030dd
jmp 0x303349
movq 0x30(%rsp), %rcx
cmpb $0x0, 0x3d(%rcx)
je 0x303424
addq %rdx, %r12
imulq 0x18(%rsp), %r12
shlq $0x2, %r12
movq %r12, (%rbp)
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq $0x2, %rcx
jb 0x3032c7
movl %r15d, 0xc(%rsp)
movq 0x18(%rsp), %rcx
leal (,%rcx,4), %ecx
movq %rcx, 0x28(%rsp)
movl $0x1, %ebp
movq %r12, %r13
movslq (%rax,%rbp,8), %rcx
movslq 0x4(%rax,%rbp,8), %rdx
movq 0x70(%rsp), %rax
movq (%rax), %rsi
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rcx,8), %r15
subq (%rsi,%rcx,8), %r15
movq (%rax,%rdx,8), %rax
subq (%rsi,%rdx,8), %rax
movq 0x30(%rsp), %rcx
cmpb $0x0, 0x3c(%rcx)
je 0x3031d4
imulq 0x28(%rsp), %r15
imulq %rax, %r15
jmp 0x3031f2
cmpb $0x0, 0x3d(%rcx)
je 0x3031e5
addq %r15, %rax
imulq 0x28(%rsp), %rax
jmp 0x3031ef
imulq %r15, %rax
imulq 0x18(%rsp), %rax
movq %rax, %r15
leaq (%r15,%r13), %r12
cmpq 0x20(%rsp), %r12
jbe 0x303298
movq %rbp, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x30321d
movq %rbp, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x30322a
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
callq 0x30596e
movq 0x80(%rsp), %rax
cmpq (%rax), %r13
jbe 0x30323a
movq %r13, (%rax)
cmpb $0x0, 0xc(%rsp)
je 0x303295
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
movq 0x60cd54(%rip), %rax    # 0x90ffa8
movq (%rax), %rdi
movq %r13, %xmm1
punpckldq 0x3d1ddc(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3d1de4(%rip), %xmm1   # 0x6d5050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3d1db0(%rip), %xmm0   # 0x6d5030
leaq 0x3d393c(%rip), %rsi    # 0x6d6bc3
leaq 0x3d394e(%rip), %rdx    # 0x6d6bdc
movb $0x1, %al
callq 0x29e380
movq %r15, %r12
incq %rbp
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbp
jb 0x303191
movq 0x80(%rsp), %rax
cmpq (%rax), %r12
jbe 0x3032c2
movq %r12, (%rax)
movl 0xc(%rsp), %r15d
movq %rcx, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3032e3
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3032f0
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x30596e
testb %r15b, %r15b
je 0x303349
movq 0x8(%rbx), %rax
movq -0x10(%rax), %rcx
movq -0x8(%rax), %r8
movq 0x60cca0(%rip), %rax    # 0x90ffa8
movq %r12, %xmm1
punpckldq 0x3d1d2b(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%rax), %rdi
subpd 0x3d1d30(%rip), %xmm1   # 0x6d5050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3d1cfc(%rip), %xmm0   # 0x6d5030
leaq 0x3d3888(%rip), %rsi    # 0x6d6bc3
leaq 0x3d389a(%rip), %rdx    # 0x6d6bdc
movb $0x1, %al
callq 0x29e380
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
movq %rax, 0x18(%rsp)
cmpb $0x0, 0x3e(%r12)
jne 0x303059
cmpb $0x0, 0x3f(%r12)
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 0x303408
movq %rax, %r12
movl %r15d, 0xc(%rsp)
xorl %ebp, %ebp
movq %r13, %r15
movq %r15, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3033d8
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3033e5
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
callq 0x30596e
incq %rbp
addq %r13, %r15
cmpq %r12, %rbp
jb 0x3033bc
movq 0x8(%r14), %rcx
subq (%r14), %rcx
sarq $0x3, %rcx
movq 0x80(%rsp), %rbp
movl 0xc(%rsp), %r15d
movq %rcx, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x303433
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x30344b
imulq %rdx, %r12
imulq 0x18(%rsp), %r12
jmp 0x30315d
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x30596e
movq 0x8(%r14), %rcx
subq (%r14), %rcx
sarq $0x3, %rcx
cmpq %rcx, %r13
cmovbq %r13, %rcx
imulq 0x20(%rsp), %rcx
movq %rcx, (%rbp)
testb %r15b, %r15b
je 0x303349
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
je 0x303349
xorl %edx, %edx
movq 0x60cb26(%rip), %r12    # 0x90ffa8
leaq 0x3d373a(%rip), %r14    # 0x6d6bc3
leaq 0x3d374c(%rip), %r15    # 0x6d6bdc
leaq 0x1(%rdx), %r13
movq (%rax,%rdx,8), %rcx
movq 0x8(%rax,%rdx,8), %r8
movq (%r12), %rdi
movsd (%rbp), %xmm1
unpcklps 0x3d1b93(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3d1b9b(%rip), %xmm1   # 0x6d5050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3d1b67(%rip), %xmm0   # 0x6d5030
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 0x303490
jmp 0x303349
jmp 0x303500
jmp 0x303500
jmp 0x303500
jmp 0x303500
jmp 0x303500
jmp 0x303500
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x303517
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x29e260
movq %r14, %rdi
callq 0x29e460
nop