// File: /workspace/github_cpp_makefile_star2_O1/adamjanovsky[P]PA193_test_parser_monero/src/block.cpp
// Function: Block::init_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int Block::init_from_file(string filename) {
    
    // First check the file size
    FILE *p_file = NULL;
    p_file = fopen(filename.c_str(),"rb");
    fseek(p_file,0,SEEK_END);
    int size = ftell(p_file);
    fclose(p_file);
    std::cout<<"File size (in bytes): " << size << std::endl;
    if(size > 3000){
        std::cout << "Couldn not be a block" << std::endl;
        return ERR_BL_INIT_FILE_ERROR;
    }
   
    // Set init to false to be sure the block stays unitialized if we encounter an error in the middle of init
    initialized = false;
    
    // Open the in file
    std::ifstream in_file(filename);
    if (!in_file.is_open()) {
        std::cout << "Could not open file: " << filename << std::endl;
        return ERR_BL_INIT_FILE_ERROR;
    }
    
    // Save the filename
    this->filename = filename;
    
    
    // Try to parse header, miner_tx and tx_hashes
    
    if (load_header(in_file) < 0 || !in_file.good()) {
        std::cerr << "Block header: Could not parse block header." << std::endl;
        return ERR_BL_INIT_HEADER;
    }
    
    if (load_miner_tx(in_file) < 0 || !in_file.good()) {
        std::cerr << "Block header: Could not parse miner transaction." << std::endl;
        return ERR_BL_INIT_MINER_TX;
    }
    
    if (load_tx_hashes(in_file) < 0) {
        std::cerr << "Block header: Could not parse transaction hashes." << std::endl;
        return ERR_BL_INIT_TX_HASHES;
    }
    
    // Everything went fine...
    initialized = true;
    return OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rdi
leaq 0x26da(%rip), %rsi      # 0x5130
callq 0x2170
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2150
movq %r15, %rdi
callq 0x2030
movq %rax, %r12
movq %r15, %rdi
callq 0x2130
movq 0x5549(%rip), %r15      # 0x7fd0
leaq 0x26a5(%rip), %rsi      # 0x5133
movl $0x16, %edx
movq %r15, %rdi
callq 0x2160
movq %r15, %rdi
movl %r12d, %esi
callq 0x2200
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
cmpl $0xbb9, %r12d           # imm = 0xBB9
jl 0x2b1e
leaq 0x266a(%rip), %rsi      # 0x514a
movl $0x15, %edx
movq %r15, %rdi
callq 0x2160
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0x2c34
movb $0x0, (%rbx)
leaq -0x230(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x21e0
leaq -0x1b8(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x2bce
leaq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x20b0
leaq -0x230(%rbp), %rsi
movq %rbx, %rdi
callq 0x2d22
testl %eax, %eax
js 0x2b81
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x210(%rbp,%rax)
je 0x2c48
movq 0x5468(%rip), %rbx      # 0x7ff0
leaq 0x25e7(%rip), %rsi      # 0x5176
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x5436(%rip), %rdi      # 0x7ff0
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20d0
jmp 0x2c28
movq 0x53fb(%rip), %rdi      # 0x7fd0
leaq 0x2584(%rip), %rsi      # 0x5160
movl $0x15, %edx
callq 0x2160
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x53dc(%rip), %rdi      # 0x7fd0
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
movq %rax, %rdi
callq 0x20d0
leaq -0x230(%rbp), %rdi
callq 0x2070
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x230(%rbp), %rsi
movq %rbx, %rdi
callq 0x3188
testl %eax, %eax
js 0x2c70
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x210(%rbp,%rax)
je 0x2cc0
movq 0x5379(%rip), %rbx      # 0x7ff0
leaq 0x2524(%rip), %rsi      # 0x51a2
movl $0x30, %edx
movq %rbx, %rdi
callq 0x2160
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq 0x5347(%rip), %rdi      # 0x7ff0
callq 0x2040
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movq %rax, %rdi
callq 0x20d0
jmp 0x2c28
leaq -0x230(%rbp), %rsi
movq %rbx, %rdi
callq 0x3406
testl %eax, %eax
js 0x2cdd
movb $0x1, (%rbx)
xorl %ebx, %ebx
jmp 0x2c28
movq 0x530c(%rip), %rdi      # 0x7ff0
leaq 0x24e8(%rip), %rsi      # 0x51d3
movl $0x31, %edx
callq 0x2160
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
movq 0x52ef(%rip), %rdi      # 0x7ff0
callq 0x2090
jmp 0x2c28
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2220