// File: /workspace/github_c_makefile_star2_O0/seojangho[P]clee/simclist.c
// Function: list_concat
int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest) {
    struct list_entry_s *el, *srcel;
    unsigned int cnt;
    int err;


    if (l1 == NULL || l2 == NULL || dest == NULL || l1 == dest || l2 == dest)
        return -1;

    list_init(dest);

    dest->numels = l1->numels + l2->numels;
    if (dest->numels == 0)
        return 0;

    /* copy list1 */
    srcel = l1->head_sentinel->next;
    el = dest->head_sentinel;
    while (srcel != l1->tail_sentinel) {
        el->next = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
        el->next->prev = el;
        el = el->next;
        el->data = srcel->data;
        srcel = srcel->next;
    }
    dest->mid = el;     /* approximate position (adjust later) */
    /* copy list 2 */
    srcel = l2->head_sentinel->next;
    while (srcel != l2->tail_sentinel) {
        el->next = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
        el->next->prev = el;
        el = el->next;
        el->data = srcel->data;
        srcel = srcel->next;
    }
    el->next = dest->tail_sentinel;
    dest->tail_sentinel->prev = el;
    
    /* fix mid pointer */
    err = l2->numels - l1->numels;
    if ((err+1)/2 > 0) {        /* correct pos RIGHT (err-1)/2 moves */
        err = (err+1)/2;
        for (cnt = 0; cnt < (unsigned int)err; cnt++) dest->mid = dest->mid->next;
    } else if (err/2 < 0) { /* correct pos LEFT (err/2)-1 moves */
        err = -err/2;
        for (cnt = 0; cnt < (unsigned int)err; cnt++) dest->mid = dest->mid->prev;
    }
 
    assert(!(list_repOk(l1) && list_repOk(l2)) || list_repOk(dest));

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x556d
cmpq $0x0, -0x18(%rbp)
je 0x556d
cmpq $0x0, -0x20(%rbp)
je 0x556d
movq -0x10(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x556d
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x5579
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5776
movq -0x20(%rbp), %rdi
callq 0x43b0
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x18(%rbp), %rax
addl 0x18(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x55ad
movl $0x0, -0x4(%rbp)
jmp 0x5776
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x5622
movl $0x18, %edi
callq 0x3180
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x55c7
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x5698
movl $0x18, %edi
callq 0x3180
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x563d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x18(%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %eax
jle 0x571d
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x571b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x56f4
jmp 0x576f
movl -0x38(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %eax
jge 0x576d
xorl %eax, %eax
subl -0x38(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x576b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5744
jmp 0x576d
jmp 0x576f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop