// File: /workspace/github_c_makefile_star2_O0/seojangho[P]clee/simclist.c
// Function: list_clear
int list_clear(list_t *restrict l) {
    struct list_entry_s *s;

    if (l->iter_active) return -1;
    
    if (l->attrs.copy_data) {        /* also free user data */
        /* spare a loop conditional with two loops: spareing elems and freeing elems */
        for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
            /* move elements as spares as long as there is room */
            if (s->data != NULL) free(s->data);
            l->spareels[l->spareelsnum++] = s;
        }
        while (s != l->tail_sentinel) {
            /* free the remaining elems */
            if (s->data != NULL) free(s->data);
            s = s->next;
            free(s->prev);
        }
        l->head_sentinel->next = l->tail_sentinel;
        l->tail_sentinel->prev = l->head_sentinel;
    } else { /* only free element containers */
        /* spare a loop conditional with two loops: spareing elems and freeing elems */
        for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
            /* move elements as spares as long as there is room */
            l->spareels[l->spareelsnum++] = s;
        }
        while (s != l->tail_sentinel) {
            /* free the remaining elems */
            s = s->next;
            free(s->prev);
        }
        l->head_sentinel->next = l->tail_sentinel;
        l->tail_sentinel->prev = l->head_sentinel;
    }
    l->numels = 0;
    l->mid = NULL;

    assert(list_repOk(l));

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x45d2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x47a1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x58(%rax)
je 0x46ca
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x5, 0x28(%rcx)
movb %al, -0x19(%rbp)
jae 0x4610
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setne %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x4619
jmp 0x465e
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x462f
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3030
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x45ef
jmp 0x4660
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x469f
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x4684
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3030
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3030
jmp 0x4660
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
jmp 0x4783
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x5, 0x28(%rcx)
movb %al, -0x1a(%rbp)
jae 0x46fa
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setne %al
movb %al, -0x1a(%rbp)
movb -0x1a(%rbp), %al
testb $0x1, %al
jne 0x4703
jmp 0x4732
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x46d9
jmp 0x4734
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x475d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3030
jmp 0x4734
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)