// File: /workspace/github_c_makefile_star2_O3/vidarr[P]ringbuffer/test/caching_ringbuffer_test.c
// Function: test_caching_free
void test_caching_free() {

    const size_t NUM_ELEMENTS = 114;
    size_t frees_count = 0;

    int test_data[NUM_ELEMENTS];

    for(size_t i = 0; i < NUM_ELEMENTS; ++i) {

        test_data[i] = i;

    }

    Ringbuffer* buffer =
        caching_ringbuffer_create(NUM_ELEMENTS / 2, count_free, &frees_count);

    size_t i = 0;

    while(10 > frees_count) {
        /* just some abritrary data that has been allocated dynamically */
        ++i;
        /* We want to create really new data buffers, thus cache == 0 ... */
        buffer->add(buffer, test_data + i);
    };

    const size_t initial_count = frees_count;

    /* Shift some elements out of cache into ringbuffer */
    for(i = 0; i < 3 * buffer->capacity(buffer); ++i) {
        void* item = caching_ringbuffer_get_cached(buffer);
        assert(item);
        buffer->add(buffer, item);
    }

    assert(initial_count == frees_count);
    assert(0 == buffer->free(buffer));

    fprintf(stdout, "free() OK: %zu\n", frees_count);

}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsp, %r15
movq $0x0, 0x8(%rsp)
movdqa 0x18e9(%rip), %xmm0     # 0x3010
xorl %eax, %eax
movdqa 0x18ef(%rip), %xmm1     # 0x3020
movdqa 0x18f7(%rip), %xmm2     # 0x3030
pshufd $0xf5, %xmm2, %xmm3     # xmm3 = xmm2[1,1,3,3]
movdqa 0x18fa(%rip), %xmm4     # 0x3040
movdqa %xmm0, %xmm5
pxor %xmm1, %xmm5
movdqa %xmm2, %xmm6
pcmpgtd %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pcmpeqd %xmm3, %xmm5
pand %xmm6, %xmm5
movd %xmm5, %ecx
testb $0x1, %cl
je 0x1770
movl %eax, 0x10(%rsp,%rax,4)
pextrw $0x4, %xmm5, %ecx
testb $0x1, %cl
je 0x1781
leal 0x1(%rax), %ecx
movl %ecx, 0x14(%rsp,%rax,4)
addq $0x2, %rax
paddq %xmm4, %xmm0
cmpq $0x72, %rax
jne 0x1746
leaq 0x10c(%rip), %rsi       # 0x18a2
leaq 0x8(%rsp), %r14
movl $0x39, %edi
movq %r14, %rdx
callq 0x119c
movq %rax, %rbx
movq (%r14), %r12
cmpq $0x9, %r12
ja 0x17d1
leaq 0x14(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rbx)
movq 0x8(%rsp), %r12
addq $0x4, %r14
cmpq $0xa, %r12
jb 0x17b9
movq %rbx, %rdi
callq *(%rbx)
testq %rax, %rax
je 0x1804
xorl %r14d, %r14d
movq 0x28(%rbx), %rdi
callq *0x10(%rdi)
testq %rax, %rax
je 0x1845
movq %rbx, %rdi
movq %rax, %rsi
callq *0x8(%rbx)
incq %r14
movq %rbx, %rdi
callq *(%rbx)
leaq (%rax,%rax,2), %rax
cmpq %rax, %r14
jb 0x17de
cmpq 0x8(%rsp), %r12
jne 0x1864
movq %rbx, %rdi
callq *0x18(%rbx)
testq %rax, %rax
jne 0x1883
movq 0x37bb(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq 0x8(%rsp), %rdx
leaq 0x1adb(%rip), %rsi      # 0x3307
xorl %eax, %eax
callq 0x1060
movq %r15, %rsp
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x1a66(%rip), %rdi      # 0x32b2
leaq 0x1804(%rip), %rsi      # 0x3057
leaq 0x1a5d(%rip), %rcx      # 0x32b7
movl $0x9c, %edx
callq 0x1040
leaq 0x1a65(%rip), %rdi      # 0x32d0
leaq 0x17e5(%rip), %rsi      # 0x3057
leaq 0x1a3e(%rip), %rcx      # 0x32b7
movl $0xa0, %edx
callq 0x1040
leaq 0x1a63(%rip), %rdi      # 0x32ed
leaq 0x17c6(%rip), %rsi      # 0x3057
leaq 0x1a1f(%rip), %rcx      # 0x32b7
movl $0xa1, %edx
callq 0x1040