// File: /workspace/github_c_makefile_star2_O1/seojangho[P]clee/simclist.c
// Function: list_insert_at
int list_insert_at(list_t *restrict l, const void *data, unsigned int pos) {
    struct list_entry_s *lent, *succ, *prec;
    
    if (l->iter_active || pos > l->numels) return -1;
    
    /* this code optimizes malloc() with a free-list */
    if (l->spareelsnum > 0) {
        lent = l->spareels[l->spareelsnum-1];
        l->spareelsnum--;
    } else {
        lent = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
        if (lent == NULL)
            return -1;
    }

    if (l->attrs.copy_data) {
        /* make room for user' data (has to be copied) */
        size_t datalen = l->attrs.meter(data);
        lent->data = (struct list_entry_s *)malloc(datalen);
        memcpy(lent->data, data, datalen);
    } else {
        lent->data = (void*)data;
    }

    /* actually append element */
    prec = list_findpos(l, pos-1);
    succ = prec->next;
    
    prec->next = lent;
    lent->prev = prec;
    lent->next = succ;
    succ->prev = lent;

    l->numels++;

    /* fix mid pointer */
    if (l->numels == 1) { /* first element, set pointer */
        l->mid = lent;
    } else if (l->numels % 2) {    /* now odd */
        if (pos >= (l->numels-1)/2) l->mid = l->mid->next;
    } else {                /* now even */
        if (pos <= (l->numels-1)/2) l->mid = l->mid->prev;
    }

    assert(list_repOk(l));

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x0, 0x2c(%rdi)
jne 0x409b
movl %edx, %r14d
movq %rdi, %rbx
movl 0x18(%rdi), %r15d
cmpl %edx, %r15d
jb 0x409b
movq %rsi, %r12
movl 0x28(%rbx), %eax
testl %eax, %eax
je 0x3f7f
movq 0x20(%rbx), %rcx
decl %eax
movq (%rcx,%rax,8), %rcx
movq %rcx, (%rsp)
movl %eax, 0x28(%rbx)
jmp 0x3f96
movl $0x18, %edi
callq 0x3160
movq %rax, (%rsp)
testq %rax, %rax
je 0x409b
cmpl $0x0, 0x58(%rbx)
je 0x3fc5
movq %r12, %rdi
callq *0x50(%rbx)
movq %rax, %r13
movq %rax, %rdi
callq 0x3160
movq (%rsp), %rbp
movq %rax, (%rbp)
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x3130
jmp 0x3fcd
movq (%rsp), %rbp
movq %r12, (%rbp)
leal -0x1(%r14), %ecx
cmpl $0x80000001, %r14d      # imm = 0x80000001
setae %al
cmpl %ecx, %r15d
setl %dl
orb %al, %dl
je 0x3fe9
xorl %eax, %eax
jmp 0x4041
cvtsi2ss %r14d, %xmm0
movl %r15d, %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss 0x2dda(%rip), %xmm1     # 0x6ddc
ucomiss %xmm0, %xmm1
jae 0x402f
movss 0x2dd1(%rip), %xmm1     # 0x6de0
ucomiss %xmm0, %xmm1
jbe 0x40ac
leal -0x1(%r15), %edx
shrl %edx
incl %edx
movq %rbx, %rax
movq 0x10(%rax), %rax
decl %edx
cmpl %ecx, %edx
jg 0x4023
jmp 0x4041
movq (%rbx), %rax
testl %ecx, %ecx
js 0x4041
movl %r14d, %ecx
movq 0x8(%rax), %rax
decl %ecx
jne 0x4039
movq 0x8(%rax), %rcx
movq %rbp, 0x8(%rax)
movq %rax, 0x10(%rbp)
movq %rcx, 0x8(%rbp)
movq %rbp, 0x10(%rcx)
leal 0x1(%r15), %eax
movl %eax, 0x18(%rbx)
testl %r15d, %r15d
je 0x407f
movl %r15d, %eax
shrl %r15d
movl $0x1, %ebp
testb $0x1, %al
jne 0x408a
cmpl %r14d, %r15d
ja 0x409b
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
jmp 0x4097
movq %rbp, 0x10(%rbx)
movl $0x1, %ebp
jmp 0x409b
cmpl %r14d, %r15d
jb 0x409b
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movss 0x2d30(%rip), %xmm1     # 0x6de4
ucomiss %xmm0, %xmm1
jae 0x40d8
movq 0x8(%rbx), %rax
cmpl %ecx, %r15d
jle 0x4041
movl %r15d, %edx
decl %edx
movq 0x10(%rax), %rax
cmpl %ecx, %edx
jg 0x40c9
jmp 0x4041
leal -0x1(%r15), %edx
shrl %edx
movq 0x10(%rbx), %rax
cmpl %ecx, %edx
jge 0x4041
notl %edx
addl %r14d, %edx
movq 0x8(%rax), %rax
decl %edx
jne 0x40ef
jmp 0x4041