// File: /workspace/github_cpp_makefile_star2_O3/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 0x2894d2(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22c231(%rip), %rdi    # 0x237d49
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 0x224b0d(%rip), %rsi    # 0x23064b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x233ca3(%rip), %rsi    # 0x23f7f7
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
jne 0xbb72
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), %r12
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0x22f0
movq (%r12), %r14
imulq $0x18, %r14, %rdi
callq 0x2280
movq %rax, (%rbx)
movq %r14, 0x10(%rsp)
testq %r14, %r14
jle 0xbc85
movq %rax, %rbp
xorl %eax, %eax
movq %rax, 0x18(%rsp)
imulq $0x18, %rax, %r14
leaq (%r14,%rbp), %rdi
addq $0x10, %rdi
pushq $0x1
popq %r12
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r14), %rdi
addq $0x11, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r14), %rdi
addq $0xc, %rdi
pushq $0x4
popq %rsi
movq %r12, %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 0xbc72
imulq $0x28, %rax, %rdi
callq 0x2280
movq %rax, (%rbp,%r14)
movq (%rbx), %rbp
cmpl $0x0, 0xc(%rbp,%r14)
je 0xbc72
addq %r14, %rbp
xorl %r12d, %r12d
movq %rbp, %rax
xorl %r13d, %r13d
movq (%rax), %rdi
addq %r12, %rdi
movq %r15, %rsi
callq 0x321f3
incq %r13
movq (%rbx), %rbp
leaq (%r14,%rbp), %rax
movl 0xc(%rbp,%r14), %ecx
addq $0x28, %r12
cmpq %rcx, %r13
jb 0xbc4c
movq 0x18(%rsp), %rax
incq %rax
cmpq 0x10(%rsp), %rax
jne 0xbbb3
movq 0x8(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movq 0x289342(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x22c0c2(%rip), %rdi    # 0x237d6a
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $0x1
popq %rbp
jmp 0xbb61