// File: /workspace/github_c_makefile_star2_O0/masyagin1998[P]GCI/src/garbage-collector/allocator.c
// Function: allocator_free_block
void allocator_free_block(allocator_type_t a, void*ptrmem)
{
    void*cur = BLOCK_PTR_FROM_DATA(ptrmem);
    void*arr_prev = NULL;
    void*arr_next = NULL;
    if ((cur == a->mem) ||
        (BLOCK_L_FLAG(BLOCK_ARR_PREV(cur)) == BUSY_BLOCK)) {
        arr_prev = NULL;
    } else {
        arr_prev = BLOCK_ARR_PREV(cur);
    }

    if (((cur + BLOCK_L_DATA_LEN(cur) + BLOCK_OVERHEAD) >= (void*) (a->mem + a->sizemem)) ||
        (BLOCK_L_FLAG(BLOCK_ARR_NEXT(cur)) == BUSY_BLOCK)) {
        arr_next = NULL;
    } else {
        arr_next = BLOCK_ARR_NEXT(cur);
    }

    allocator_list_remove_elem(&(a->busy_list), cur);
    
    if ((arr_prev != NULL) && (arr_next == NULL)) {
        /* concatenate previous free array block with current block. */
        size_t len = BLOCK_L_DATA_LEN(arr_prev) + BLOCK_R_OVERHEAD + BLOCK_L_OVERHEAD + BLOCK_L_DATA_LEN(cur);
        allocator_list_remove_elem(&(a->free_list), arr_prev);
        BLOCK_L_DATA_LEN(arr_prev) = len;
        BLOCK_R_DATA_LEN(cur) = len;
        allocator_list_insert_elem(&(a->free_list), arr_prev);
    } else if ((arr_prev == NULL) && (arr_next != NULL)) {
        /* concatenate current block with next free array block. */
        size_t len = BLOCK_L_DATA_LEN(cur) + BLOCK_R_OVERHEAD + BLOCK_L_OVERHEAD + BLOCK_L_DATA_LEN(arr_next);
        allocator_list_remove_elem(&(a->free_list), arr_next);
        BLOCK_L_DATA_LEN(cur) = len;
        BLOCK_R_DATA_LEN(arr_next) = len;
        allocator_list_insert_elem(&(a->free_list), cur);
    } else if ((arr_prev != NULL) && (arr_next != NULL)) {
        /* concatenate previous free array block with current block with next free array block. */
        size_t len =
            BLOCK_L_DATA_LEN(arr_prev) + BLOCK_R_OVERHEAD +
            BLOCK_L_OVERHEAD + BLOCK_L_DATA_LEN(cur) + BLOCK_R_OVERHEAD +
            BLOCK_L_OVERHEAD + BLOCK_L_DATA_LEN(arr_next);
        allocator_list_remove_elem(&(a->free_list), arr_prev);
        allocator_list_remove_elem(&(a->free_list), arr_next);
        BLOCK_L_DATA_LEN(arr_prev) = len;
        BLOCK_R_DATA_LEN(arr_next) = len;
        allocator_list_insert_elem(&(a->free_list), arr_prev);
    } else {
        BLOCK_L_FLAG(cur) = FREE_BLOCK;
        BLOCK_R_FLAG(cur) = FREE_BLOCK;
        allocator_list_insert_elem(&(a->free_list), cur);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $-0x8, %rax
addq $-0x8, %rax
addq $-0x8, %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
je 0x17624
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x9(%rcx), %rdx
shlq $0x0, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
movsbl -0x22(%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x1762e
movq $0x0, -0x20(%rbp)
jmp 0x17662
movq -0x18(%rbp), %rax
addq $-0x1, %rax
addq $-0x8, %rax
movq -0x18(%rbp), %rcx
movq -0x9(%rcx), %rdx
shlq $0x0, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
addq $-0x8, %rax
addq $-0x8, %rax
addq $-0x8, %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
addq 0x1(%rcx), %rax
addq $0x22, %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movq -0x8(%rbp), %rdx
addq 0x8(%rdx), %rcx
cmpq %rcx, %rax
jae 0x176a0
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
movsbl 0x22(%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x176aa
movq $0x0, -0x28(%rbp)
jmp 0x176d9
movq -0x18(%rbp), %rax
addq $0x1, %rax
addq $0x8, %rax
addq $0x8, %rax
addq $0x8, %rax
movq -0x18(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
addq %rcx, %rax
addq $0x8, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x17120
cmpq $0x0, -0x20(%rbp)
je 0x17760
cmpq $0x0, -0x28(%rbp)
jne 0x17760
movq -0x20(%rbp), %rax
movq 0x1(%rax), %rax
addq $0x9, %rax
addq $0x19, %rax
movq -0x18(%rbp), %rcx
addq 0x1(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x17120
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x1(%rax)
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
movq %rdx, 0x19(%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x17250
jmp 0x178a3
cmpq $0x0, -0x20(%rbp)
jne 0x177d6
cmpq $0x0, -0x28(%rbp)
je 0x177d6
movq -0x18(%rbp), %rax
movq 0x1(%rax), %rax
addq $0x9, %rax
addq $0x19, %rax
movq -0x28(%rbp), %rcx
addq 0x1(%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rsi
callq 0x17120
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1(%rax)
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
movq %rdx, 0x19(%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
callq 0x17250
jmp 0x178a1
cmpq $0x0, -0x20(%rbp)
je 0x17872
cmpq $0x0, -0x28(%rbp)
je 0x17872
movq -0x20(%rbp), %rax
movq 0x1(%rax), %rax
addq $0x9, %rax
addq $0x19, %rax
movq -0x18(%rbp), %rcx
addq 0x1(%rcx), %rax
addq $0x9, %rax
addq $0x19, %rax
movq -0x28(%rbp), %rcx
addq 0x1(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x17120
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x28(%rbp), %rsi
callq 0x17120
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x1(%rax)
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
movq %rdx, 0x19(%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
callq 0x17250
jmp 0x1789f
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x1(%rcx), %rcx
shlq $0x0, %rcx
movb $0x0, 0x21(%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
callq 0x17250
jmp 0x178a1
jmp 0x178a3
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)