// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: write_asg_t(asg_t*, char*)
int write_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, "w");
    uint32_t tmp/**, i**/;
    
    tmp = sg->n_arc;
    fwrite(&tmp, sizeof(tmp), 1, fp);
    // tmp = sg->m_arc;
    fwrite(&tmp, sizeof(tmp), 1, fp);

    tmp = sg->is_srt;
    fwrite(&tmp, sizeof(tmp), 1, fp);


    tmp = sg->n_seq;
    fwrite(&tmp, sizeof(tmp), 1, fp);
    // tmp = sg->m_seq;
    fwrite(&tmp, sizeof(tmp), 1, fp);
    
    tmp = sg->is_symm;
    fwrite(&tmp, sizeof(tmp), 1, fp);
    tmp = sg->r_seq;
    fwrite(&tmp, sizeof(tmp), 1, fp);


    uint32_t Len;

    Len = sg->n_seq*2;
    fwrite(sg->seq_vis, sizeof(sg->seq_vis[0]), Len, fp);

    Len = sg->n_seq*2;
    fwrite(sg->idx, sizeof(sg->idx[0]), Len, fp);


    // for (i = 0; i < sg->n_arc; i++)
    // {
    //     tmp = sg->arc[i].del;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->arc[i].el;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->arc[i].no_l_indel;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->arc[i].ol;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->arc[i].strong;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);

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

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


    // for (i = 0; i < sg->n_seq; i++)
    // {
    //     tmp = sg->seq[i].c;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->seq[i].del;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    //     tmp = sg->seq[i].len;
    //     fwrite(&tmp, sizeof(tmp), 1, fp);
    // }
    fwrite(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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x2090
leaq 0xf(%rax), %rdi
callq 0x2280
movq %rax, %rbx
leaq 0x133cb5(%rip), %rsi    # 0x22463b
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14ba64(%rip), %rsi    # 0x23c3fe
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl 0x4(%r14), %eax
andl %ebp, %eax
leaq 0xc(%rsp), %r12
movl %eax, (%r12)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl 0x4(%r14), %eax
shrl $0x1f, %eax
movl %eax, (%r12)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
andl 0x14(%r14), %ebp
movl %ebp, (%r12)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %eax
shrl $0x1f, %eax
movl %eax, (%r12)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl 0x18(%r14), %eax
movl %eax, (%r12)
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %edx
addl %edx, %edx
movq 0x30(%r14), %rdi
movl $0x1, %esi
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %edx
addl %edx, %edx
movq 0x28(%r14), %rdi
movl $0x8, %esi
movq %r15, %rcx
callq 0x2410
movq 0x8(%r14), %rdi
movl 0x4(%r14), %edx
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
andq %r12, %rdx
movl $0x18, %esi
movq %r15, %rcx
callq 0x2410
movq 0x20(%r14), %rdi
movl 0x14(%r14), %edx
andq %r12, %rdx
movl $0x8, %esi
movq %r15, %rcx
callq 0x2410
movq %rbx, %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x2190
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq