// File: /workspace/github_cpp_makefile_star2_O2/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 %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
movq %rax, 0x8(%rsp)
leaq 0x12f649(%rip), %rsi    # 0x1e264b
movq %rax, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2050
leaq 0x14768b(%rip), %rsi    # 0x1fa6a1
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl 0x4(%r14), %eax
andl %ebx, %eax
leaq 0x14(%rsp), %r13
movl %eax, (%r13)
pushq $0x4
popq %rbp
pushq $0x1
popq %r12
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movl 0x4(%r14), %eax
shrl $0x1f, %eax
movl %eax, (%r13)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
andl 0x14(%r14), %ebx
movl %ebx, (%r13)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %eax
shrl $0x1f, %eax
movl %eax, (%r13)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movl 0x18(%r14), %eax
movl %eax, (%r13)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %edx
addl %edx, %edx
movq 0x30(%r14), %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x2410
movl 0x14(%r14), %edx
addl %edx, %edx
movq 0x28(%r14), %rdi
pushq $0x8
popq %r12
movq %r12, %rsi
movq %r15, %rcx
callq 0x2410
movq 0x8(%r14), %rdi
movl 0x4(%r14), %edx
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rdx
pushq $0x18
popq %rsi
movq %r15, %rcx
callq 0x2410
movq 0x20(%r14), %rdi
movl 0x14(%r14), %edx
andq %rbx, %rdx
movq %r12, %rsi
movq %r15, %rcx
callq 0x2410
movq 0x8(%rsp), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x2190
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq