// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/src/caller.h
// Function: ococo::caller_t<unsigned short, 3, 4>::caller_t(ococo::params_t*)
caller_t<T, counter_size, refbase_size>::caller_t(params_t *params_)
    : params(params_) {
    /*
     * Read SAM headers.
     */

	t_real = realtime();
    ococo::info("Initialing SAM/BAM reader.\n");

    correctly_initialized = true;
    return_code           = EXIT_SUCCESS;

    iter   = nullptr;
    b      = nullptr;
    header = nullptr;
    stats  = nullptr;

    params->sam_file = sam_open(params->sam_fn.c_str(), "r");
    if (params->sam_file == nullptr) {
        ococo::fatal_error("Problem with opening SAM/BAM file ('%s').\n",
                           params->sam_fn.c_str());
        correctly_initialized = false;
        return;
    }

    if ((header = sam_hdr_read(params->sam_file)) == 0) {
        ococo::fatal_error("SAM/BAM headers are missing or corrupted.\n");
        correctly_initialized = false;
        return;
    }

    stats = new (std::nothrow)
        stats_t<T, counter_size, refbase_size>(params, *header);
    if (stats == nullptr || !stats->check_allocation()) {
        ococo::fatal_error("Allocation of the main structure failed.\n");
        correctly_initialized = false;
        return;
    }

    /*
     * Load FASTA and stats.
     */

    if (!params->stats_in_fn.empty() && !params->fasta_in_fn.empty()) {
        ococo::fatal_error(
            "Initial FASTA reference and input statistics "
            "cannot be used at the same time.\n");
        correctly_initialized = false;
        return;
    }

    if (!params->stats_in_fn.empty()) {
        ococo::info("Loading statistics ('%s').\n",
                    params->stats_in_fn.c_str());

        int error_code = stats->import_stats(params->stats_in_fn);
        if (error_code != 0) {
            ococo::fatal_error("Import of statistics failed (file '%s').\n",
                               params->stats_in_fn.c_str());
            correctly_initialized = false;
            return;
        }
    } else {
        if (!params->fasta_in_fn.empty()) {
            ococo::info("Loading reference ('%s').\n",
                        params->fasta_in_fn.c_str());

            int error_code = stats->load_fasta(params->fasta_in_fn);
            if (error_code != 0) {
                ococo::fatal_error("Loading of FASTA failed (file '%s').\n",
                                   params->fasta_in_fn.c_str());
                correctly_initialized = false;
                return;
            }
        }

        else {
            ococo::info(
                "Neither reference, nor statistics provided. Going "
                "to "
                "consider sequence of N's as a reference.\n");
        }
    }

    /*
     * Open VCF file.
     */

    if (params->vcf_fn.size() > 0) {
        ococo::info("Opening VCF stream ('%s').\n", params->vcf_fn.c_str());

        if (params->vcf_fn == std::string("-")) {
            params->vcf_file = stdout;
        } else {
            params->vcf_file = fopen(params->vcf_fn.c_str(), "w+");
            if (params->vcf_file == nullptr) {
                ococo::fatal_error("Problem with opening VCF file '%s'.\n",
                                   params->vcf_fn.c_str());
                correctly_initialized = false;
                return;
            }
        }

        char buf[PATH_MAX + 1];
        char *res = realpath(params->fasta_in_fn.c_str(), buf);
        std::string fasta_full_path;
        if (res) {
            fasta_full_path = std::string(buf);
        } else {
            fasta_full_path = params->fasta_in_fn;
        }

        stats->print_vcf_header(params->vcf_file, params->command,
                                fasta_full_path);
    }

    /*
     * Open pileup file.
     */

    if (params->pileup_fn.size() > 0) {
        ococo::info("Opening pileup stream ('%s').\n",
                    params->pileup_fn.c_str());

        if (params->pileup_fn == std::string("-")) {
            params->pileup_file = stdout;
        } else {
            params->pileup_file = fopen(params->pileup_fn.c_str(), "w+");
            if (params->pileup_file == nullptr) {
                ococo::fatal_error("Problem with opening pileup file '%s'.\n",
                                   params->pileup_fn.c_str());
                correctly_initialized = false;
                return;
            }
        }
    }

    /*
     * Open consensus FASTA file.
     */

    if (params->fasta_out_fn.size() > 0) {
        params->fasta_out_file = fopen(params->fasta_out_fn.c_str(), "w+");

        ococo::info("Opening consensus file ('%s').\n",
                    params->fasta_out_fn.c_str());
        params->fasta_out_file = fopen(params->fasta_out_fn.c_str(), "w+");

        if (params->fasta_out_file == nullptr) {
            ococo::fatal_error(
                "Problem with opening FASTA for consensus: '%s'.\n",
                params->fasta_out_fn.c_str());
            correctly_initialized = false;
            return;
        }
    }

    /*
     * Open log file.
     */

    if (params->log_fn.size() > 0) {
        params->log_file = fopen(params->log_fn.c_str(), "w+");

        ococo::info("Opening log file ('%s').\n", params->log_fn.c_str());
        params->log_file = fopen(params->log_fn.c_str(), "w+");

        if (params->log_file == nullptr) {
            ococo::fatal_error("Problem with opening log file: '%s'.\n",
                               params->log_fn.c_str());
            correctly_initialized = false;
            return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1088, %rsp           # imm = 0x1088
movq %rdi, %rbx
movq %rsi, 0x28(%rdi)
callq 0xc520
movsd %xmm0, 0x30(%rbx)
leaq 0x473af(%rip), %rdi     # 0x4e088
xorl %eax, %eax
callq 0x4cae
movb $0x1, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rbx)
movups %xmm0, 0x14(%rbx)
movl $0x0, 0x24(%rbx)
movq 0x28(%rbx), %rax
movq 0x78(%rax), %rdi
leaq 0x4ac3d(%rip), %rsi     # 0x51941
callq 0xf5db
movq 0x28(%rbx), %rcx
movq %rax, 0x198(%rcx)
testq %rax, %rax
je 0x6d8c
movq %rax, %rdi
callq 0x1558d
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x6da0
movq %rax, %r15
movq 0x5b264(%rip), %rsi     # 0x61f98
movl $0x38, %edi
callq 0x4a60
testq %rax, %rax
je 0x6da9
movq %rax, %r14
movq 0x28(%rbx), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x8d12
movq %r14, 0x20(%rbx)
movq %r14, %rdi
callq 0x8f4c
testb %al, %al
je 0x6db1
movq 0x28(%rbx), %rax
cmpq $0x0, 0xc0(%rax)
movq 0xa0(%rax), %rcx
je 0x6dd4
testq %rcx, %rcx
je 0x6e1f
leaq 0x4739a(%rip), %rdi     # 0x4e124
jmp 0x6db8
movq 0x78(%rcx), %rsi
leaq 0x4730d(%rip), %rdi     # 0x4e0a4
xorl %eax, %eax
callq 0x4a80
jmp 0x6dbf
leaq 0x47328(%rip), %rdi     # 0x4e0cf
jmp 0x6db8
movq $0x0, 0x20(%rbx)
leaq 0x47342(%rip), %rdi     # 0x4e0fa
xorl %eax, %eax
callq 0x4a80
movb $0x0, (%rbx)
addq $0x1088, %rsp           # imm = 0x1088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x6e61
movq 0x98(%rax), %rsi
leaq 0x473ce(%rip), %rdi     # 0x4e1b9
xorl %eax, %eax
callq 0x4cae
movq 0x20(%rbx), %rdi
movl $0x98, %esi
addq 0x28(%rbx), %rsi
callq 0x914c
testl %eax, %eax
je 0x6e6f
movq 0x28(%rbx), %rax
movq 0x98(%rax), %rsi
leaq 0x473ba(%rip), %rdi     # 0x4e1d4
jmp 0x6d97
movq 0xb8(%rax), %rsi
leaq 0x47346(%rip), %rdi     # 0x4e173
xorl %eax, %eax
callq 0x4cae
movq 0x20(%rbx), %rdi
movl $0xb8, %esi
addq 0x28(%rbx), %rsi
callq 0x8f98
testl %eax, %eax
je 0x6e6f
movq 0x28(%rbx), %rax
movq 0xb8(%rax), %rsi
leaq 0x47333(%rip), %rdi     # 0x4e18f
jmp 0x6d97
leaq 0x47392(%rip), %rdi     # 0x4e1fa
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %rcx
cmpq $0x0, 0xe8(%rcx)
je 0x70ad
movq 0xe0(%rcx), %rsi
leaq 0x473ca(%rip), %rdi     # 0x4e259
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %r12
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x473c8(%rip), %rsi     # 0x4e275
leaq 0x473c2(%rip), %rdx     # 0x4e276
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x95ae
movq 0xe8(%r12), %rdx
cmpq 0x8(%r14), %rdx
jne 0x6ef7
movq 0x80(%rsp), %r14
testq %rdx, %rdx
je 0x6f03
movq 0xe0(%r12), %rdi
movq %r14, %rsi
callq 0x4550
testl %eax, %eax
sete %bpl
jmp 0x6f06
movq 0x80(%rsp), %r14
xorl %ebp, %ebp
jmp 0x6f06
movb $0x1, %bpl
cmpq %r15, %r14
je 0x6f1e
movq 0x90(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x4540
testb %bpl, %bpl
je 0x6f3a
movq 0x5b066(%rip), %rax     # 0x61f90
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
jmp 0x6f65
movq 0x28(%rbx), %rax
movq 0xe0(%rax), %rdi
leaq 0x4732b(%rip), %rsi     # 0x4e277
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
testq %rax, %rax
je 0x713d
movq 0x98(%rcx), %rdi
leaq 0x80(%rsp), %rsi
callq 0x41d0
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
testq %rax, %rax
je 0x6fed
leaq 0x70(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x4230
leaq (%rsp,%rax), %rdx
addq $0x80, %rdx
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x95ae
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %r14
movq %r14, %rsi
callq 0x4660
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x7000
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x7000
movl $0x98, %esi
addq 0x28(%rbx), %rsi
leaq 0x20(%rsp), %rdi
callq 0x42c0
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %rax
movq 0x180(%rax), %r15
leaq 0x10(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x9644
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x9644
movq %rsp, %rdx
leaq 0x40(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x93e8
movq (%r12), %rdi
cmpq %r13, %rdi
je 0x7077
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4540
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7092
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4540
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x70a9
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4540
movq 0x28(%rbx), %rcx
cmpq $0x0, 0x148(%rcx)
je 0x71b2
movq 0x140(%rcx), %rsi
leaq 0x471d6(%rip), %rdi     # 0x4e29f
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %r12
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4718e(%rip), %rsi     # 0x4e275
leaq 0x47188(%rip), %rdx     # 0x4e276
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x95ae
movq 0x148(%r12), %rdx
cmpq 0x8(%r14), %rdx
jne 0x7131
movq 0x80(%rsp), %r14
testq %rdx, %rdx
je 0x7150
movq 0x140(%r12), %rdi
movq %r14, %rsi
callq 0x4550
testl %eax, %eax
sete %bpl
jmp 0x7153
movq 0x80(%rsp), %r14
xorl %ebp, %ebp
jmp 0x7153
movq 0xe0(%rcx), %rsi
leaq 0x4712f(%rip), %rdi     # 0x4e27a
jmp 0x6d97
movb $0x1, %bpl
cmpq %r15, %r14
je 0x716b
movq 0x90(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x4540
testb %bpl, %bpl
je 0x7187
movq 0x5ae19(%rip), %rax     # 0x61f90
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
jmp 0x71b2
movq 0x28(%rbx), %rax
movq 0x140(%rax), %rdi
leaq 0x470de(%rip), %rsi     # 0x4e277
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
testq %rax, %rax
je 0x72a6
cmpq $0x0, 0x108(%rcx)
je 0x7215
movq 0x100(%rcx), %rdi
leaq 0x470ad(%rip), %r14     # 0x4e277
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x190(%rcx)
movq 0x100(%rcx), %rsi
leaq 0x470fb(%rip), %rdi     # 0x4e2e6
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %rax
movq 0x100(%rax), %rdi
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x190(%rcx)
testq %rax, %rax
je 0x7293
cmpq $0x0, 0x168(%rcx)
je 0x6dc2
movq 0x160(%rcx), %rdi
leaq 0x47046(%rip), %r14     # 0x4e277
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x1a0(%rcx)
movq 0x160(%rcx), %rsi
leaq 0x470e5(%rip), %rdi     # 0x4e337
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %rax
movq 0x160(%rax), %rdi
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x1a0(%rcx)
testq %rax, %rax
jne 0x6dc2
movq 0x160(%rcx), %rsi
leaq 0x470c3(%rip), %rdi     # 0x4e351
jmp 0x6d97
movq 0x100(%rcx), %rsi
leaq 0x47065(%rip), %rdi     # 0x4e306
jmp 0x6d97
movq 0x140(%rcx), %rsi
leaq 0x4700a(%rip), %rdi     # 0x4e2be
jmp 0x6d97
jmp 0x72db
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x72de
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x72de
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x7309
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x7309
movq %rax, %rbx
movq 0x5ac97(%rip), %rsi     # 0x61f98
movq %r14, %rdi
callq 0x4320
movq %rbx, %rdi
callq 0x4970
nop