// File: /workspace/github_c_makefile_star2_O1/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:
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rdx, %rsi
je 0x4879
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, %r12
cmpq %rdx, %rdi
je 0x486b
testq %r12, %r12
je 0x486b
movq %rsi, %r15
testq %rsi, %rsi
je 0x486b
testq %rbx, %rbx
je 0x486b
movq %rbx, %rdi
callq 0x3ce0
movl 0x18(%r12), %edx
movl 0x18(%r15), %ebp
xorl %eax, %eax
movl %ebp, %ecx
addl %edx, %ecx
movl %ecx, 0x18(%rbx)
je 0x486b
movq %rbx, 0x10(%rsp)
movq (%rbx), %r14
movq (%r12), %rax
movq 0x8(%r12), %r13
movq 0x8(%rax), %rbx
cmpq %r13, %rbx
movl %edx, 0xc(%rsp)
je 0x47d1
movl $0x18, %edi
callq 0x3160
movq %rax, %r12
movq %rax, 0x8(%r14)
movq %r14, 0x10(%rax)
movq (%rbx), %rax
movq %rax, (%r12)
movq 0x8(%rbx), %rbx
movq %r12, %r14
cmpq %r13, %rbx
jne 0x47a7
jmp 0x47d4
movq %r14, %r12
movq 0x10(%rsp), %r14
movq %r12, 0x10(%r14)
movq (%r15), %rax
movq 0x8(%r15), %r15
movq 0x8(%rax), %rbx
cmpq %r15, %rbx
je 0x4814
movl $0x18, %edi
callq 0x3160
movq %rax, 0x8(%r12)
movq %r12, 0x10(%rax)
movq (%rbx), %rcx
movq %rcx, (%rax)
movq 0x8(%rbx), %rbx
movq %rax, %r12
cmpq %r15, %rbx
jne 0x47ed
jmp 0x4817
movq %r12, %rax
movq 0x8(%r14), %rcx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rcx)
subl 0xc(%rsp), %ebp
testl %ebp, %ebp
jle 0x4843
incl %ebp
shrl %ebp
movq 0x10(%r14), %rax
cmpl $0x1, %ebp
adcl $0x0, %ebp
movq 0x8(%rax), %rax
decl %ebp
jne 0x4839
jmp 0x4865
cmpl $-0x2, %ebp
jg 0x4869
movl %ebp, %ecx
shrl $0x1f, %ecx
addl %ebp, %ecx
sarl %ecx
negl %ecx
movq 0x10(%r14), %rax
cmpl $0x1, %ecx
adcl $0x0, %ecx
movq 0x10(%rax), %rax
decl %ecx
jne 0x485d
movq %rax, 0x10(%r14)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq