// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq $0x72, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq %rsp, %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
cmpq $0x72, -0x20(%rbp)
jae 0x1ab0
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, -0x210(%rbp,%rax,4)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1a8a
movl $0x39, %edi
leaq 0x174(%rip), %rsi       # 0x1c30
leaq -0x10(%rbp), %rdx
callq 0x1190
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0xa, %eax
cmpq -0x10(%rbp), %rax
jbe 0x1b0a
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rcx
leaq -0x210(%rbp), %rsi
shlq $0x2, %rcx
addq %rcx, %rsi
callq *%rax
jmp 0x1ad1
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rdi
callq *%rax
movq %rax, %rcx
movq -0x218(%rbp), %rax
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
jae 0x1b9a
movq -0x28(%rbp), %rdi
callq 0x1470
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x1b5b
jmp 0x1b7a
leaq 0x274e(%rip), %rdi      # 0x42b0
leaq 0x24a2(%rip), %rsi      # 0x400b
movl $0x9c, %edx
leaq 0x2740(%rip), %rcx      # 0x42b5
callq 0x1040
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq *%rax
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1b1a
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
jne 0x1ba6
jmp 0x1bc5
leaq 0x2721(%rip), %rdi      # 0x42ce
leaq 0x2457(%rip), %rsi      # 0x400b
movl $0xa0, %edx
leaq 0x26f5(%rip), %rcx      # 0x42b5
callq 0x1040
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rdi
callq *%rax
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x1bdf
jmp 0x1bfe
leaq 0x2705(%rip), %rdi      # 0x42eb
leaq 0x241e(%rip), %rsi      # 0x400b
movl $0xa1, %edx
leaq 0x26bc(%rip), %rcx      # 0x42b5
callq 0x1040
movq 0x43d3(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x26f2(%rip), %rsi      # 0x4305
movb $0x0, %al
callq 0x1070
movq -0x18(%rbp), %rax
movq %rax, %rsp
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
nopw (%rax,%rax)