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