// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: convert_usg_t(usg_t*, ma_ug_t*)
ma_ug_t *convert_usg_t(usg_t *ng, ma_ug_t *ref)
{
    ma_ug_t *ug = NULL; uint32_t k, nv, z; usg_arc_t *av; asg_arc_t *p;
    ma_utg_t *des, *src;
    CALLOC(ug, 1); ug->g = asg_init(); 
    ug->u.n = ug->u.m = ng->n; CALLOC(ug->u.a, ug->u.n);
    for (k = 0; k < ng->n; k++) {
        asg_seq_set(ug->g, k, ng->a[k].len, ng->a[k].del);
        ug->g->seq[k].c = ref->g->seq[ng->a[k].mm].c;

        av = usg_arc_a(ng, (k<<1)); nv = usg_arc_n(ng, (k<<1));
        for (z = 0; z < nv; z++) {
            if(av[z].del) continue;
            p = asg_arc_pushp(ug->g); memset(p, 0, sizeof((*p)));
            p->ul = av[z].ul; p->v = av[z].v; p->ol = av[z].ol; p->del = av[z].del;
        }

        av = usg_arc_a(ng, (k<<1)+1); nv = usg_arc_n(ng, (k<<1)+1);
        for (z = 0; z < nv; z++) {
            if(av[z].del) continue;
            p = asg_arc_pushp(ug->g); memset(p, 0, sizeof((*p)));
            p->ul = av[z].ul; p->v = av[z].v; p->ol = av[z].ol; p->del = av[z].del;
        }

        des = &(ug->u.a[k]); src = &(ref->u.a[ng->a[k].mm]);
        (*des) = (*src); des->a = NULL; des->s = NULL;
        if(src->a) {
            MALLOC(des->a, des->m); 
            memcpy(des->a, src->a, src->n*sizeof((*(src->a))));
        }

        if(src->s) {
            MALLOC(des->s, des->len);
            memcpy(des->s, src->s, src->len*sizeof((*(src->s))));
        }
    }

    asg_cleanup(ug->g);
    return ug;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x1, %edi
movl $0x38, %esi
callq 0x2140
movq %rax, -0x18(%rbp)
callq 0xcd150
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x28, %esi
callq 0x2140
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x367e89
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movzbl 0x70(%rax), %ecx
callq 0xcd8f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x1c(%rbp), %edx
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movb 0x4(%rax,%rcx,8), %dl
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movb %dl, 0x4(%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x1c(%rbp), %ecx
shll %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x1c(%rbp), %ecx
shll %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x367c16
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x367b5c
jmp 0x367c08
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x31b110
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %edx
shrl $0x1f, %edx
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x367b32
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x367d73
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x367cb9
jmp 0x367d65
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x31b110
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %edx
shrl $0x1f, %edx
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x367c8f
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x1c(%rbp), %edx
imulq $0x78, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdi
movl $0x28, %edx
callq 0x2180
movq -0x40(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x367e23
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
shlq $0x3, %rdx
callq 0x2180
movq -0x48(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x367e79
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x0, %rdx
callq 0x2180
jmp 0x367e7b
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x367a45
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xcdd10
movq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq