// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rdi
leaq 0x28a3(%rip), %rsi      # 0x50e5
callq 0x2180
movq %rax, %r15
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2160
movq %r15, %rdi
callq 0x2030
movq %rax, %r12
movq %r15, %rdi
callq 0x2130
movq 0x575f(%rip), %rdi      # 0x7fd0
leaq 0x2870(%rip), %rsi      # 0x50e8
callq 0x2120
movq %rax, %rdi
movl %r12d, %esi
callq 0x2220
movq %rax, %rdi
callq 0x20a0
cmpl $0xbb9, %r12d           # imm = 0xBB9
jl 0x28bc
movq 0x5730(%rip), %rdi      # 0x7fd0
leaq 0x2858(%rip), %rsi      # 0x50ff
callq 0x2120
movq %rax, %rdi
callq 0x20a0
pushq $-0x4
popq %rbx
jmp 0x2969
movb $0x0, (%rbx)
leaq -0x228(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2200
leaq -0x1b0(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x2934
leaq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x20c0
leaq -0x228(%rbp), %rsi
movq %rbx, %rdi
callq 0x2a16
testl %eax, %eax
js 0x2915
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x208(%rbp,%rax)
je 0x297b
movq 0x56d4(%rip), %rdi      # 0x7ff0
leaq 0x2808(%rip), %rsi      # 0x512b
callq 0x2120
movq %rax, %rdi
callq 0x20a0
pushq $-0x1
jmp 0x295c
movq 0x5695(%rip), %rdi      # 0x7fd0
leaq 0x27d3(%rip), %rsi      # 0x5115
callq 0x2120
movq %rax, %rdi
movq %r14, %rsi
callq 0x2100
movq %rax, %rdi
callq 0x20a0
pushq $-0x4
popq %rbx
leaq -0x228(%rbp), %rdi
callq 0x2060
movl %ebx, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq -0x228(%rbp), %rsi
movq %rbx, %rdi
callq 0x2d1c
testl %eax, %eax
js 0x29a3
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x208(%rbp,%rax)
je 0x29c2
movq 0x5646(%rip), %rdi      # 0x7ff0
leaq 0x27a6(%rip), %rsi      # 0x5157
callq 0x2120
movq %rax, %rdi
callq 0x20a0
pushq $-0x2
jmp 0x295c
leaq -0x228(%rbp), %rsi
movq %rbx, %rdi
callq 0x2ef2
testl %eax, %eax
js 0x29dc
movb $0x1, (%rbx)
xorl %ebx, %ebx
jmp 0x295d
movq 0x560d(%rip), %rdi      # 0x7ff0
leaq 0x279e(%rip), %rsi      # 0x5188
callq 0x2120
movq %rax, %rdi
callq 0x20a0
pushq $-0x3
jmp 0x295c
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2240
nop