// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: load_asg_t(asg_t**, char*)
int load_asg_t(asg_t **sg, char* read_file_name)
{
    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;
    }
    uint32_t tmp/**, i**/;

    (*sg) = (asg_t*)calloc(1, sizeof(asg_t));
    int f_flag = 0;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->n_arc = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->m_arc = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->is_srt = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->n_seq = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->m_seq = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->is_symm = tmp;
    f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    (*sg)->r_seq = tmp;

    uint32_t Len;

    Len = (*sg)->n_seq*2;
    (*sg)->seq_vis = (uint8_t*)malloc(sizeof(uint8_t)*Len);
    f_flag += fread((*sg)->seq_vis, sizeof((*sg)->seq_vis[0]), Len, fp);



    Len = (*sg)->n_seq*2;
    (*sg)->idx = (uint64_t*)malloc(sizeof(uint64_t)*Len);
    f_flag += fread((*sg)->idx, sizeof((*sg)->idx[0]), Len, fp);
    
    



    (*sg)->arc = (asg_arc_t*)malloc(sizeof(asg_arc_t)*(*sg)->m_arc);
    (*sg)->seq = (asg_seq_t*)malloc(sizeof(asg_seq_t)*(*sg)->m_seq);
    

    // for (i = 0; i < (*sg)->n_arc; i++)
    // {
    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].del = tmp;

    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].el = tmp;

    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].no_l_indel = tmp;

    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].ol = tmp;

    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].strong = tmp;

    //     uint64_t tmp_64;
    //     f_flag += fread(&tmp_64, sizeof(tmp_64), 1, fp);
    //     (*sg)->arc[i].ul = tmp_64;

    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->arc[i].v = tmp;
    // }
    fread((*sg)->arc, sizeof((*((*sg)->arc))), (*sg)->n_arc, fp);


    // for (i = 0; i < (*sg)->n_seq; i++)
    // {
    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->seq[i].c = tmp;
    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->seq[i].del = tmp;
    //     f_flag += fread(&tmp, sizeof(tmp), 1, fp);
    //     (*sg)->seq[i].len = tmp;
    // }
    fread((*sg)->seq, sizeof((*((*sg)->seq))), (*sg)->n_seq, fp);
    
    free(index_name);    
    fflush(fp);
    fclose(fp);

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
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 0x2338e2(%rip), %rsi    # 0x38141a
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0x24288c(%rip), %rsi    # 0x3903d6
callq 0x2200
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x14db66
movl $0x0, -0x4(%rbp)
jmp 0x14de93
movl $0x1, %edi
movl $0x48, %esi
callq 0x2140
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdi
movl -0x34(%rbp), %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rdi
movl -0x34(%rbp), %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x8, %esi
callq 0x22e0
movq %rax, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
imulq $0x18, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x18, %esi
callq 0x22e0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x28(%rbp), %rcx
movl $0x8, %esi
callq 0x22e0
movq -0x20(%rbp), %rdi
callq 0x2210
movq -0x28(%rbp), %rdi
callq 0x21f0
movq -0x28(%rbp), %rdi
callq 0x21a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)