// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x133b0f(%rip), %rsi    # 0x22463b
xorl %ebp, %ebp
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x142a65(%rip), %rsi    # 0x2335a7
movq %rbx, %rdi
callq 0x2210
testq %rax, %rax
je 0xf0d59
movq %rax, %r15
movl $0x1, %edi
movl $0x48, %esi
callq 0x2120
movq %rax, (%r14)
leaq 0x4(%rsp), %r12
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movq (%r14), %rax
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl (%r12), %ecx
andl %ebp, %ecx
movl $0x80000000, %r13d      # imm = 0x80000000
movl 0x4(%rax), %edx
andl %r13d, %edx
orl %ecx, %edx
movl %edx, 0x4(%rax)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movl (%r12), %eax
movq (%r14), %rcx
movl %eax, (%rcx)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movl (%r12), %eax
movq (%r14), %rcx
shll $0x1f, %eax
movl 0x4(%rcx), %edx
andl %ebp, %edx
orl %eax, %edx
movl %edx, 0x4(%rcx)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movq (%r14), %rax
movl (%r12), %ecx
andl %ebp, %ecx
andl 0x14(%rax), %r13d
orl %ecx, %r13d
movl %r13d, 0x14(%rax)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movl (%r12), %eax
movq (%r14), %rcx
movl %eax, 0x10(%rcx)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movl (%r12), %eax
movq (%r14), %rcx
shll $0x1f, %eax
andl 0x14(%rcx), %ebp
orl %eax, %ebp
movl %ebp, 0x14(%rcx)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x22f0
movl (%r12), %eax
movq (%r14), %r13
movl %eax, 0x18(%r13)
movl 0x14(%r13), %r12d
addl %r12d, %r12d
movq %r12, %rdi
callq 0x2280
movq %rax, 0x30(%r13)
movq (%r14), %rax
movq 0x30(%rax), %rdi
movl $0x1, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%r14), %r13
movl 0x14(%r13), %r12d
addl %r12d, %r12d
leaq (,%r12,8), %rdi
callq 0x2280
movq %rax, 0x28(%r13)
movq (%r14), %rax
movq 0x28(%rax), %rdi
movl $0x8, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x22f0
movq (%r14), %r12
movl (%r12), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
callq 0x2280
movq %rax, 0x8(%r12)
movq (%r14), %r12
movl 0x10(%r12), %edi
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x20(%r12)
movq (%r14), %rax
movq 0x8(%rax), %rdi
movl 0x4(%rax), %edx
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
andq %r12, %rdx
movl $0x18, %esi
movq %r15, %rcx
callq 0x22f0
movq (%r14), %rax
movq 0x20(%rax), %rdi
movl 0x14(%rax), %edx
andq %r12, %rdx
movl $0x8, %esi
movq %r15, %rcx
callq 0x22f0
movq %rbx, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x2190
movl $0x1, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq