// File: /workspace/github_c_makefile_star2_O0/vidarr[P]ringbuffer/test/cached_ringbuffer_test.c
// Function: test_cached_free
void test_cached_free() {

    size_t frees_count = 0;

    Ringbuffer* cache =
        ringbuffer_create(50, free_data_buffer, &frees_count);

    Ringbuffer* buffer = ringbuffer_create(21, cache_free, cache);

    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 ... */
        DataBuffer* db = get_data_buffer(0, 13);
        buffer->add(buffer, db);
    };

    size_t initial_count = frees_count;

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

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

    cache = cache->free(cache);

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

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq $0x0, -0x8(%rbp)
movl $0x32, %edi
leaq -0x9c(%rip), %rsi       # 0x17f0
leaq -0x8(%rbp), %rdx
callq 0x1190
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdx
movl $0x15, %edi
leaq -0x349(%rip), %rsi      # 0x1560
callq 0x1190
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0xa, %eax
cmpq -0x8(%rbp), %rax
jbe 0x18f7
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
xorl %eax, %eax
movl %eax, %edi
movl $0xd, %esi
callq 0x1720
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq *%rax
jmp 0x18ba
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq %rax, %rcx
movq -0x40(%rbp), %rax
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
jae 0x1985
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1720
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1946
jmp 0x1965
leaq 0x17ac(%rip), %rdi      # 0x30f9
leaq 0x16d9(%rip), %rsi      # 0x302d
movl $0xc8, %edx
leaq 0x179e(%rip), %rcx      # 0x30fe
callq 0x1040
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq *%rax
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1907
movq -0x30(%rbp), %rax
cmpq -0x8(%rbp), %rax
jne 0x1991
jmp 0x19b0
leaq 0x177e(%rip), %rdi      # 0x3116
leaq 0x168e(%rip), %rsi      # 0x302d
movl $0xcc, %edx
leaq 0x1753(%rip), %rcx      # 0x30fe
callq 0x1040
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x19ca
jmp 0x19e9
leaq 0x1762(%rip), %rdi      # 0x3133
leaq 0x1655(%rip), %rsi      # 0x302d
movl $0xcd, %edx
leaq 0x171a(%rip), %rcx      # 0x30fe
callq 0x1040
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rdi
callq *%rax
movq %rax, -0x10(%rbp)
movq 0x35d6(%rip), %rax      # 0x4fd8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x173d(%rip), %rsi      # 0x314d
movb $0x0, %al
callq 0x1070
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)