// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: load_ma_hit_ts(ma_hit_t_alloc**, char*)
int load_ma_hit_ts(ma_hit_t_alloc** x, char* read_file_name)
{
    fprintf(stderr, "Loading ma_hit_ts from disk... \n");
    char* index_name = (char*)malloc(strlen(read_file_name)+15);
    sprintf(index_name, "%s.bin", read_file_name);
    FILE* fp = fopen(index_name, "r");
    if(!fp)
    {
        return 0;
    }


    long long n_read;
    long long i, k;
    int f_flag;
    f_flag = fread(&n_read, sizeof(n_read), 1, fp);
    (*x) = (ma_hit_t_alloc*)malloc(sizeof(ma_hit_t_alloc)*n_read);


    for (i = 0; i < n_read; i++)
    {        
        f_flag += fread(&((*x)[i].is_fully_corrected), sizeof((*x)[i].is_fully_corrected), 1, fp);
        f_flag += fread(&((*x)[i].is_abnormal), sizeof((*x)[i].is_abnormal), 1, fp);
        f_flag += fread(&((*x)[i].length), sizeof((*x)[i].length), 1, fp);
        (*x)[i].size = (*x)[i].length;

        (*x)[i].buffer = NULL;
        if((*x)[i].length == 0) continue;
        
        (*x)[i].buffer = (ma_hit_t*)malloc(sizeof(ma_hit_t)*(*x)[i].length);

        for (k = 0; k < (*x)[i].length; k++)
        {
            read_ma(&((*x)[i].buffer[k]), fp);
        }  
        // fread((*x)[i].buffer, sizeof((*((*x)[i].buffer))), (*x)[i].length, fp);
    }

    free(index_name);    
    fclose(fp);
    fprintf(stderr, "ma_hit_ts has been read.\n");

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x1af65d(%rip), %r12    # 0x252fe0
movq (%r12), %rcx
leaq 0x1462bb(%rip), %rdi    # 0x1e9c49
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq %r15, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %r14
leaq 0x13ec97(%rip), %rsi    # 0x1e264b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14dced(%rip), %rsi    # 0x1f16b7
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
jne 0xa39e8
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %r14, 0x8(%rsp)
leaq 0x20(%rsp), %r13
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
movq %rax, %rcx
callq 0x22f0
movq (%r13), %r14
movq 0x8(%rsp), %r13
imulq $0x18, %r14, %rdi
callq 0x2280
movq %rax, %rbp
movq %rax, (%rbx)
xorl %eax, %eax
testq %r14, %r14
cmovleq %rax, %r14
movq %r14, 0x10(%rsp)
cmpq 0x10(%rsp), %rax
je 0xa3aff
movq %rax, 0x18(%rsp)
imulq $0x18, %rax, %r14
leaq (%r14,%rbp), %rdi
addq $0x10, %rdi
pushq $0x1
popq %rbp
movq %rbp, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r14), %rdi
addq $0x11, %rdi
movq %rbp, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r14), %rdi
addq $0xc, %rdi
pushq $0x4
popq %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
movl 0xc(%rax,%r14), %ecx
movl %ecx, 0x8(%rax,%r14)
andq $0x0, (%rax,%r14)
movq (%rbx), %rbp
movl 0xc(%rbp,%r14), %eax
testq %rax, %rax
je 0xa3af2
imulq $0x28, %rax, %rdi
callq 0x2280
movq %rax, (%rbp,%r14)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rbx), %rbp
movl 0xc(%rbp,%r14), %eax
cmpq %rax, %r13
jae 0xa3ae6
addq %r14, %rbp
movq (%rbp), %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0x6043
incq %r13
addq $0x28, %r12
jmp 0xa3abe
movq 0x1af4f3(%rip), %r12    # 0x252fe0
movq 0x8(%rsp), %r13
movq 0x18(%rsp), %rax
incq %rax
jmp 0xa3a2c
movq %r13, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movq (%r12), %rcx
leaq 0x146150(%rip), %rdi    # 0x1e9c6a
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $0x1
popq %rbp
jmp 0xa39d7