// File: /workspace/github_cpp_makefile_star2_O1/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 0xc59c
movsd %xmm0, 0x30(%rbx)
leaq 0x4930d(%rip), %rdi     # 0x50088
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 0x4cb73(%rip), %rsi     # 0x53919
callq 0xf67a
movq 0x28(%rbx), %rcx
movq %rax, 0x198(%rcx)
testq %rax, %rax
je 0x6df9
movq %rax, %rdi
callq 0x1560e
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x6e0d
movq %rax, %r15
movq 0x5d1c2(%rip), %rsi     # 0x63f98
movl $0x38, %edi
callq 0x4a60
testq %rax, %rax
je 0x6e16
movq %rax, %r14
movq 0x28(%rbx), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x8dde
jmp 0x6e19
movq 0x78(%rcx), %rsi
leaq 0x492a0(%rip), %rdi     # 0x500a4
xorl %eax, %eax
callq 0x4a80
jmp 0x6e5f
leaq 0x492bb(%rip), %rdi     # 0x500cf
jmp 0x6e58
xorl %r14d, %r14d
movq %r14, 0x20(%rbx)
testq %r14, %r14
je 0x6e51
movq %r14, %rdi
callq 0x902a
testb %al, %al
je 0x6e51
movq 0x28(%rbx), %rax
movq 0xc0(%rax), %rcx
testq %rcx, %rcx
je 0x6ebb
cmpq $0x0, 0xa0(%rax)
je 0x6e74
leaq 0x492d5(%rip), %rdi     # 0x50124
jmp 0x6e58
leaq 0x492a2(%rip), %rdi     # 0x500fa
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 0x6ebb
movq 0xb8(%rax), %rsi
leaq 0x492ec(%rip), %rdi     # 0x50173
xorl %eax, %eax
callq 0x4cae
movq 0x20(%rbx), %rdi
movl $0xb8, %esi
addq 0x28(%rbx), %rsi
callq 0x9084
testl %eax, %eax
je 0x6f15
movq 0x28(%rbx), %rax
movq 0xb8(%rax), %rsi
leaq 0x492d9(%rip), %rdi     # 0x5018f
jmp 0x6e04
cmpq $0x0, 0xa0(%rax)
je 0x6f07
movq 0x98(%rax), %rsi
leaq 0x492e6(%rip), %rdi     # 0x501b9
xorl %eax, %eax
callq 0x4cae
movq 0x20(%rbx), %rdi
movl $0x98, %esi
addq 0x28(%rbx), %rsi
callq 0x923a
testl %eax, %eax
je 0x6f15
movq 0x28(%rbx), %rax
movq 0x98(%rax), %rsi
leaq 0x492d2(%rip), %rdi     # 0x501d4
jmp 0x6e04
leaq 0x492ec(%rip), %rdi     # 0x501fa
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %rax
cmpq $0x0, 0xe8(%rax)
je 0x714b
movq 0xe0(%rax), %rsi
leaq 0x49324(%rip), %rdi     # 0x50259
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %r12
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x49320(%rip), %rsi     # 0x50275
leaq 0x4931a(%rip), %rdx     # 0x50276
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x967a
movq 0xe8(%r12), %rdx
cmpq 0x8(%r14), %rdx
jne 0x6f9f
testq %rdx, %rdx
je 0x6f9c
movq 0x80(%rsp), %rsi
movq 0xe0(%r12), %rdi
callq 0x4550
testl %eax, %eax
sete %bpl
jmp 0x6f9f
movb $0x1, %bpl
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x6fbc
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4540
testb %bpl, %bpl
je 0x6fd8
movq 0x5cfc8(%rip), %rax     # 0x63f90
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
jmp 0x7003
movq 0x28(%rbx), %rax
movq 0xe0(%rax), %rdi
leaq 0x4928d(%rip), %rsi     # 0x50277
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x180(%rcx)
testq %rax, %rax
je 0x71d2
movq 0x28(%rbx), %rax
movq 0x98(%rax), %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 0x708f
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 0x967a
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %r14
movq %r14, %rsi
callq 0x4660
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x70a2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x70a2
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 0x970a
leaq 0x50(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x970a
movq %rsp, %rdx
leaq 0x40(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x94b4
movq (%r12), %rdi
cmpq %r13, %rdi
je 0x7119
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x4540
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7134
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4540
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x714b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4540
movq 0x28(%rbx), %rax
cmpq $0x0, 0x148(%rax)
je 0x724c
movq 0x140(%rax), %rsi
leaq 0x49134(%rip), %rdi     # 0x5029f
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x4cae
movq 0x28(%rbx), %r12
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x490ea(%rip), %rsi     # 0x50275
leaq 0x490e4(%rip), %rdx     # 0x50276
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x967a
movq 0x148(%r12), %rdx
cmpq 0x8(%r14), %rdx
jne 0x71e8
testq %rdx, %rdx
je 0x71e5
movq 0x80(%rsp), %rsi
movq 0x140(%r12), %rdi
callq 0x4550
testl %eax, %eax
sete %bpl
jmp 0x71e8
movq 0xe0(%rcx), %rsi
leaq 0x4909a(%rip), %rdi     # 0x5027a
jmp 0x6e04
movb $0x1, %bpl
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x7205
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4540
testb %bpl, %bpl
je 0x7221
movq 0x5cd7f(%rip), %rax     # 0x63f90
movq (%rax), %rax
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
jmp 0x724c
movq 0x28(%rbx), %rax
movq 0x140(%rax), %rdi
leaq 0x49044(%rip), %rsi     # 0x50277
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x188(%rcx)
testq %rax, %rax
je 0x734c
movq 0x28(%rbx), %rax
cmpq $0x0, 0x108(%rax)
je 0x72b7
movq 0x100(%rax), %rdi
leaq 0x4900f(%rip), %r14     # 0x50277
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x190(%rcx)
movq 0x100(%rcx), %rsi
leaq 0x4905d(%rip), %rdi     # 0x502e6
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 0x7339
movq 0x28(%rbx), %rax
cmpq $0x0, 0x168(%rax)
je 0x6e62
movq 0x160(%rax), %rdi
leaq 0x48fa0(%rip), %r14     # 0x50277
movq %r14, %rsi
callq 0x4600
movq 0x28(%rbx), %rcx
movq %rax, 0x1a0(%rcx)
movq 0x160(%rcx), %rsi
leaq 0x4903f(%rip), %rdi     # 0x50337
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 0x6e62
movq 0x160(%rcx), %rsi
leaq 0x4901d(%rip), %rdi     # 0x50351
jmp 0x6e04
movq 0x100(%rcx), %rsi
leaq 0x48fbf(%rip), %rdi     # 0x50306
jmp 0x6e04
movq 0x140(%rcx), %rsi
leaq 0x48f64(%rip), %rdi     # 0x502be
jmp 0x6e04
jmp 0x7381
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7384
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x7384
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x73af
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4540
jmp 0x73af
movq %rax, %rbx
movq 0x5cbf1(%rip), %rsi     # 0x63f98
movq %r14, %rdi
callq 0x4320
movq %rbx, %rdi
callq 0x4970
nop