// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x27e44b(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21ffba(%rip), %rdi    # 0x22bb59
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 0x218a76(%rip), %rsi    # 0x22463b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x2279cc(%rip), %rsi    # 0x2335a7
movq %r14, %rdi
callq 0x2210
testq %rax, %rax
jne 0xbbf9
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %r14, (%rsp)
leaq 0x10(%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, 0x8(%rsp)
testq %r14, %r14
jle 0xbcfc
xorl %r14d, %r14d
movq (%rbx), %rax
imulq $0x18, %r14, %r13
leaq (%rax,%r13), %rdi
addq $0x10, %rdi
pushq $0x1
popq %r12
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r13), %rdi
addq $0x11, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
leaq (%rax,%r13), %rdi
addq $0xc, %rdi
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%rbx), %rax
movl 0xc(%rax,%r13), %ecx
movl %ecx, 0x8(%rax,%r13)
andq $0x0, (%rax,%r13)
movq (%rbx), %r12
movl 0xc(%r12,%r13), %eax
testq %rax, %rax
je 0xbcee
imulq $0x28, %rax, %rdi
callq 0x2280
movq %rax, (%r12,%r13)
movq (%rbx), %rax
cmpl $0x0, 0xc(%rax,%r13)
je 0xbcee
addq %r13, %rax
xorl %ebp, %ebp
xorl %r12d, %r12d
movq (%rax), %rdi
addq %rbp, %rdi
movq %r15, %rsi
callq 0x32ae0
incq %r12
movq (%rbx), %rax
movl 0xc(%rax,%r13), %ecx
addq %r13, %rax
addq $0x28, %rbp
cmpq %rcx, %r12
jb 0xbcc9
incq %r14
cmpq 0x8(%rsp), %r14
jne 0xbc37
movq (%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2190
movq 0x27e2cc(%rip), %rax    # 0x289fe0
movq (%rax), %rcx
leaq 0x21fe5c(%rip), %rdi    # 0x22bb7a
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $0x1
popq %rbp
jmp 0xbbe8