// File: /workspace/github_c_makefile_star2_O3/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 0x481c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, %r15
cmpq %rdx, %rdi
je 0x480e
testq %r15, %r15
je 0x480e
movq %rsi, %r12
testq %rsi, %rsi
je 0x480e
testq %rbx, %rbx
je 0x480e
movq %rbx, %rdi
callq 0x3cdc
movl 0x18(%r15), %edx
movl 0x18(%r12), %ebp
xorl %eax, %eax
movl %ebp, %ecx
addl %edx, %ecx
movl %ecx, 0x18(%rbx)
je 0x480e
movl %edx, 0xc(%rsp)
movq %rbx, 0x10(%rsp)
movq (%rbx), %r14
movq (%r15), %rax
movq 0x8(%r15), %r13
movq 0x8(%rax), %rbx
cmpq %r13, %rbx
je 0x4781
movl $0x18, %edi
callq 0x3160
movq %rax, %r15
movq %rax, 0x8(%r14)
movq %r14, 0x10(%rax)
movq (%rbx), %rax
movq %rax, (%r15)
movq 0x8(%rbx), %rbx
movq %r15, %r14
cmpq %r13, %rbx
jne 0x4758
jmp 0x4784
movq %r14, %r15
movq 0x10(%rsp), %r14
movq %r15, 0x10(%r14)
movq (%r12), %rax
movq 0x8(%r12), %r12
movq 0x8(%rax), %r13
movq %r15, %rax
cmpq %r12, %r13
je 0x47ca
movq %r15, %rbx
movl $0x18, %edi
callq 0x3160
movq %rax, 0x8(%rbx)
movq %rbx, 0x10(%rax)
movq (%r13), %rcx
movq %rcx, (%rax)
movq 0x8(%r13), %r13
movq %rax, %rbx
cmpq %r12, %r13
jne 0x47a5
movq 0x8(%r14), %rcx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rcx)
subl 0xc(%rsp), %ebp
testl %ebp, %ebp
jle 0x47f4
incl %ebp
shrl %ebp
cmpl $0x1, %ebp
adcl $0x0, %ebp
xorl %eax, %eax
movq 0x8(%r15), %r15
decl %ebp
jne 0x47ea
jmp 0x480a
cmpl $-0x2, %ebp
movl $0x0, %eax
jg 0x480e
negl %ebp
shrl %ebp
movq 0x10(%r15), %r15
decl %ebp
jne 0x4802
movq %r15, 0x10(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq