// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: dump_trans_ovlp(trans_chain*, char const*, ma_ug_t*)
uint64_t dump_trans_ovlp(trans_chain* t_ch, const char *fn, ma_ug_t *ug)
{
    char* gfa_name = NULL; MALLOC(gfa_name, strlen(fn)+50);
    sprintf(gfa_name, "%s.trans.bin", fn);
    FILE* fp = fopen(gfa_name, "w"); free(gfa_name);
    if (!fp) return 0;
    if(ug) write_dbug(ug, fp);

    fwrite(&t_ch->r_num, sizeof(t_ch->r_num), 1, fp);
    fwrite(t_ch->ir_het, sizeof(uint8_t), t_ch->r_num, fp);
    uint64_t i;
    fwrite(&t_ch->bed.n, sizeof(t_ch->bed.n), 1, fp);
    for (i = 0; i < t_ch->bed.n; i++) {
        fwrite(&t_ch->bed.a[i].n, sizeof(t_ch->bed.a[i].n), 1, fp);
        fwrite(t_ch->bed.a[i].a, sizeof(bed_interval), t_ch->bed.a[i].n, fp);
    }

    fwrite(&t_ch->k_trans.n, sizeof(t_ch->k_trans.n), 1, fp);
    fwrite(t_ch->k_trans.a, sizeof(u_trans_t), t_ch->k_trans.n, fp);

    fwrite(&t_ch->k_trans.idx.n, sizeof(t_ch->k_trans.idx.n), 1, fp);
    fwrite(t_ch->k_trans.idx.a, sizeof(uint64_t), t_ch->k_trans.idx.n, fp);

    fclose(fp);
    fprintf(stderr, "[M::%s] Dump trans overlaps\n", __func__);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x32, %rdi
shlq $0x0, %rdi
callq 0x2270
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x27a975(%rip), %rsi    # 0x387afd
movb $0x0, %al
callq 0x2050
movq -0x28(%rbp), %rdi
leaq 0x28c238(%rip), %rsi    # 0x3993d2
callq 0x2200
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x30(%rbp)
jne 0x10d1c0
movq $0x0, -0x8(%rbp)
jmp 0x10d35d
cmpq $0x0, -0x20(%rbp)
je 0x10d1d4
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1018e0
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x30(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edx
movq -0x30(%rbp), %rcx
movl $0x1, %esi
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x10d2a5
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x10, %esi
callq 0x2400
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x10d231
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x138(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x30, %esi
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
addq $0x18, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x150(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x8, %esi
callq 0x2400
movq -0x30(%rbp), %rdi
callq 0x21a0
movq 0x2b6ca3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x27a7c3(%rip), %rsi    # 0x387b0a
leaq 0x27a7d9(%rip), %rdx    # 0x387b27
movb $0x0, %al
callq 0x22a0
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)