// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1098, %rsp           # imm = 0x1098
movq %rdi, %rbx
movq %rsi, 0x28(%rdi)
callq 0xa67e
movsd %xmm0, 0x30(%rbx)
leaq 0x3bde5(%rip), %rdi     # 0x410a8
xorl %eax, %eax
callq 0xa59c
movb $0x1, (%rbx)
xorps %xmm0, %xmm0
andl $0x0, 0x24(%rbx)
movups %xmm0, 0x4(%rbx)
movups %xmm0, 0x14(%rbx)
movq 0x28(%rbx), %rax
movq 0x78(%rax), %rdi
leaq 0x3f5ca(%rip), %rsi     # 0x448b5
callq 0xca17
movq 0x28(%rbx), %rcx
movq %rax, 0x198(%rcx)
testq %rax, %rax
je 0x5371
movq %rax, %rdi
callq 0x11ef2
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x5385
movq %rax, %r15
movq 0x51c8d(%rip), %rsi     # 0x56fa8
pushq $0x38
popq %rdi
callq 0x4a50
testq %rax, %rax
je 0x538e
movq %rax, %r14
movq 0x28(%rbx), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x6f28
movq %r14, 0x20(%rbx)
movq %r14, %rdi
callq 0x7144
testb %al, %al
je 0x5393
movq 0x28(%rbx), %rax
cmpq $0x0, 0xc0(%rax)
movq 0xa0(%rax), %rcx
je 0x53b6
testq %rcx, %rcx
je 0x5401
leaq 0x3bdd5(%rip), %rdi     # 0x41144
jmp 0x539a
movq 0x78(%rcx), %rsi
leaq 0x3bd48(%rip), %rdi     # 0x410c4
xorl %eax, %eax
callq 0xa36e
jmp 0x53a1
leaq 0x3bd63(%rip), %rdi     # 0x410ef
jmp 0x539a
andq $0x0, 0x20(%rbx)
leaq 0x3bd80(%rip), %rdi     # 0x4111a
xorl %eax, %eax
callq 0xa36e
movb $0x0, (%rbx)
addq $0x1098, %rsp           # imm = 0x1098
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x5443
movq 0x98(%rax), %rsi
leaq 0x3be0c(%rip), %rdi     # 0x411d9
xorl %eax, %eax
callq 0xa59c
movq 0x20(%rbx), %rdi
movl $0x98, %esi
addq 0x28(%rbx), %rsi
callq 0x7340
testl %eax, %eax
je 0x5451
movq 0x28(%rbx), %rax
movq 0x98(%rax), %rsi
leaq 0x3bdf8(%rip), %rdi     # 0x411f4
jmp 0x537c
movq 0xb8(%rax), %rsi
leaq 0x3bd84(%rip), %rdi     # 0x41193
xorl %eax, %eax
callq 0xa59c
movq 0x20(%rbx), %rdi
movl $0xb8, %esi
addq 0x28(%rbx), %rsi
callq 0x7196
testl %eax, %eax
je 0x5451
movq 0x28(%rbx), %rax
movq 0xb8(%rax), %rsi
leaq 0x3bd71(%rip), %rdi     # 0x411af
jmp 0x537c
leaq 0x3bdd0(%rip), %rdi     # 0x4121a
xorl %eax, %eax
callq 0xa59c
movq 0x28(%rbx), %rcx
cmpq $0x0, 0xe8(%rcx)
je 0x55cf
movq 0xe0(%rcx), %rsi
leaq 0x3be08(%rip), %rdi     # 0x41279
xorl %eax, %eax
callq 0xa59c
movl $0xe0, %r14d
addq 0x28(%rbx), %r14
leaq 0x3be0c(%rip), %rsi     # 0x41295
leaq 0x90(%rsp), %r15
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x7576
movq %r14, %rdi
movq %r15, %rsi
callq 0x754d
movl %eax, %ebp
movq %r15, %rdi
callq 0x4230
testb %bpl, %bpl
je 0x54cf
movq 0x51ae1(%rip), %rax     # 0x56fa0
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
jmp 0x54fa
movq 0x28(%rbx), %rax
movq 0xe0(%rax), %rdi
leaq 0x3bdb6(%rip), %rsi     # 0x41297
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
testq %rax, %rax
je 0x5768
movq 0x98(%rcx), %rdi
leaq 0x90(%rsp), %rsi
callq 0x41b0
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
testq %rax, %rax
je 0x5557
leaq 0x70(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x7576
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %r14
movq %r14, %rsi
callq 0x4650
movq %r14, %rdi
callq 0x4230
jmp 0x556a
movl $0x98, %esi
addq 0x28(%rbx), %rsi
leaq 0x10(%rsp), %rdi
callq 0x42d0
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %rsi
movq 0x180(%rsi), %r15
addq $0x8, %rsi
leaq 0x30(%rsp), %rdi
callq 0x4710
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4710
leaq 0x30(%rsp), %r12
leaq 0x50(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x75b2
movq %r13, %rdi
callq 0x4230
movq %r12, %rdi
callq 0x4230
leaq 0x10(%rsp), %rdi
callq 0x4230
movq 0x28(%rbx), %rcx
cmpq $0x0, 0x148(%rcx)
je 0x5674
movq 0x140(%rcx), %rsi
leaq 0x3bcd4(%rip), %rdi     # 0x412bf
xorl %eax, %eax
callq 0xa59c
movl $0x140, %r14d           # imm = 0x140
addq 0x28(%rbx), %r14
leaq 0x3bc92(%rip), %rsi     # 0x41295
leaq 0x90(%rsp), %r15
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x7576
movq %r14, %rdi
movq %r15, %rsi
callq 0x754d
movl %eax, %ebp
movq %r15, %rdi
callq 0x4230
testb %bpl, %bpl
je 0x5649
movq 0x51967(%rip), %rax     # 0x56fa0
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
jmp 0x5674
movq 0x28(%rbx), %rax
movq 0x140(%rax), %rdi
leaq 0x3bc3c(%rip), %rsi     # 0x41297
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
testq %rax, %rax
je 0x577b
cmpq $0x0, 0x108(%rcx)
je 0x56d7
movq 0x100(%rcx), %rdi
leaq 0x3bc0b(%rip), %r14     # 0x41297
movq %r14, %rsi
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x190(%rcx)
movq 0x100(%rcx), %rsi
leaq 0x3bc59(%rip), %rdi     # 0x41306
xorl %eax, %eax
callq 0xa59c
movq 0x28(%rbx), %rax
movq 0x100(%rax), %rdi
movq %r14, %rsi
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x190(%rcx)
testq %rax, %rax
je 0x5755
cmpq $0x0, 0x168(%rcx)
je 0x53a4
movq 0x160(%rcx), %rdi
leaq 0x3bba4(%rip), %r14     # 0x41297
movq %r14, %rsi
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x1a0(%rcx)
movq 0x160(%rcx), %rsi
leaq 0x3bc43(%rip), %rdi     # 0x41357
xorl %eax, %eax
callq 0xa59c
movq 0x28(%rbx), %rax
movq 0x160(%rax), %rdi
movq %r14, %rsi
callq 0x45f0
movq 0x28(%rbx), %rcx
movq %rax, 0x1a0(%rcx)
testq %rax, %rax
jne 0x53a4
movq 0x160(%rcx), %rsi
leaq 0x3bc21(%rip), %rdi     # 0x41371
jmp 0x537c
movq 0x100(%rcx), %rsi
leaq 0x3bbc3(%rip), %rdi     # 0x41326
jmp 0x537c
movq 0xe0(%rcx), %rsi
leaq 0x3bb24(%rip), %rdi     # 0x4129a
jmp 0x537c
movq 0x140(%rcx), %rsi
leaq 0x3bb55(%rip), %rdi     # 0x412de
jmp 0x537c
jmp 0x579f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x4230
jmp 0x57a2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4230
jmp 0x57c0
movq %rax, %rbx
movq 0x517f0(%rip), %rsi     # 0x56fa8
movq %r14, %rdi
callq 0x4330
movq %rbx, %rdi
callq 0x4950