// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq 0x2919a9(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2562f3(%rip), %rsi    # 0x388934
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0xf, %rdi
callq 0x2270
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x24edaa(%rip), %rsi    # 0x38141a
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0x25dd54(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x13269e
movl $0x0, -0x4(%rbp)
jmp 0x132893
movq -0x28(%rbp), %rcx
leaq -0x30(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x22e0
movl %eax, -0x44(%rbp)
imulq $0x18, -0x30(%rbp), %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x132862
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x22e0
movq %rax, %rcx
movslq -0x44(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
addq $0x11, %rdi
movq -0x28(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x22e0
movq %rax, %rcx
movslq -0x44(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
addq $0xc, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x44(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jne 0x1327cb
jmp 0x132851
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
imulq $0x28, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0x13284f
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x81d0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x132803
jmp 0x132851
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1326d4
movq -0x20(%rbp), %rdi
callq 0x2210
movq -0x28(%rbp), %rdi
callq 0x21a0
movq 0x291765(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2560d0(%rip), %rsi    # 0x388955
movb $0x0, %al
callq 0x22a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)