// File: /workspace/github_c_makefile_star2_O2/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 $-0x1
popq %rcx
cmpq %rdx, %rsi
je 0x44fd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r13
movq %rdi, %r12
cmpq %rdx, %rdi
je 0x44ef
testq %r12, %r12
je 0x44ef
movq %rsi, %rbx
testq %rsi, %rsi
je 0x44ef
testq %r13, %r13
je 0x44ef
movq %r13, %rdi
callq 0x3c60
movl 0x18(%r12), %edx
movl 0x18(%rbx), %ebp
xorl %ecx, %ecx
movl %ebp, %eax
addl %edx, %eax
movl %eax, 0x18(%r13)
je 0x44ef
movq %rbx, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq (%r12), %rbx
movq 0x8(%r12), %r15
movq (%r13), %r14
pushq $0x18
popq %r12
movq 0x8(%rbx), %rbx
cmpq %r15, %rbx
je 0x4459
movq %r12, %rdi
callq 0x3160
movq %rax, 0x8(%r14)
movq %r14, 0x10(%rax)
movq (%rbx), %rcx
movq %rcx, (%rax)
movq %rax, %r14
jmp 0x4435
movq %r13, (%rsp)
movq %r14, 0x10(%r13)
movq 0x10(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r12
pushq $0x18
popq %r15
movq %r14, %r13
movq 0x8(%rbx), %rbx
cmpq %r12, %rbx
je 0x4498
movq %r15, %rdi
callq 0x3160
movq %rax, 0x8(%r13)
movq %r13, 0x10(%rax)
movq (%rbx), %rcx
movq %rcx, (%rax)
movq %rax, %r13
jmp 0x4474
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%r13)
movq %r13, 0x10(%rax)
subl 0xc(%rsp), %ebp
leal 0x1(%rbp), %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
testl %ebp, %ebp
jle 0x44ce
xorl %ecx, %ecx
movq (%rsp), %rdx
subl $0x1, %eax
jb 0x44ef
movq 0x8(%r14), %r14
movq %r14, 0x10(%rdx)
jmp 0x44bf
cmpl $-0x2, %ebp
movl $0x0, %ecx
jg 0x44ef
negl %ebp
shrl %ebp
movq (%rsp), %rax
subl $0x1, %ebp
jb 0x44ef
movq 0x10(%r14), %r14
movq %r14, 0x10(%rax)
jmp 0x44e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %ecx, %eax
retq