// File: /workspace/github_c_makefile_star2_O0/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_buffer_alloc
NK_LIB void*
nk_buffer_alloc(struct nk_buffer *b, enum nk_buffer_allocation_type type,
    nk_size size, nk_size align)
{
    int full;
    nk_size alignment;
    void *unaligned;
    void *memory;

    NK_ASSERT(b);
    NK_ASSERT(size);
    if (!b || !size) return 0;
    b->needed += size;

    /* calculate total size with needed alignment + size */
    if (type == NK_BUFFER_FRONT)
        unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated);
    else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size);
    memory = nk_buffer_align(unaligned, align, &alignment, type);

    /* check if buffer has enough memory*/
    if (type == NK_BUFFER_FRONT)
        full = ((b->allocated + size + alignment) > b->size);
    else full = ((b->size - NK_MIN(b->size,(size + alignment))) <= b->allocated);

    if (full) {
        nk_size capacity;
        if (b->type != NK_BUFFER_DYNAMIC)
            return 0;
        NK_ASSERT(b->pool.alloc && b->pool.free);
        if (b->type != NK_BUFFER_DYNAMIC || !b->pool.alloc || !b->pool.free)
            return 0;

        /* buffer is full so allocate bigger buffer if dynamic */
        capacity = (nk_size)((float)b->memory.size * b->grow_factor);
        capacity = NK_MAX(capacity, nk_round_up_pow2((nk_uint)(b->allocated + size)));
        b->memory.ptr = nk_buffer_realloc(b, capacity, &b->memory.size);
        if (!b->memory.ptr) return 0;

        /* align newly allocated pointer */
        if (type == NK_BUFFER_FRONT)
            unaligned = nk_ptr_add(void, b->memory.ptr, b->allocated);
        else unaligned = nk_ptr_add(void, b->memory.ptr, b->size - size);
        memory = nk_buffer_align(unaligned, align, &alignment, type);
    }
    if (type == NK_BUFFER_FRONT)
        b->allocated += size + alignment;
    else b->size -= (size + alignment);
    b->needed += alignment;
    b->calls++;
    return memory;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
cmpq $0x0, 0x78(%rsp)
jne 0x2f335
movq 0x95ce7(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
leaq 0x8208d(%rip), %rsi     # 0xb13a0
leaq 0x820a4(%rip), %rdx     # 0xb13be
movl $0x209d, %ecx           # imm = 0x209D
movb $0x0, %al
callq 0x13ec0
movq 0x95cc3(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
callq 0x149a0
jmp 0x2f337
jmp 0x2f339
cmpq $0x0, 0x68(%rsp)
jne 0x2f374
movq 0x95ca8(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
leaq 0x8204e(%rip), %rsi     # 0xb13a0
leaq 0x82065(%rip), %rdx     # 0xb13be
movl $0x209e, %ecx           # imm = 0x209E
movb $0x0, %al
callq 0x13ec0
movq 0x95c84(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
callq 0x149a0
jmp 0x2f376
cmpq $0x0, 0x78(%rsp)
je 0x2f386
cmpq $0x0, 0x68(%rsp)
jne 0x2f397
movq $0x0, 0x80(%rsp)
jmp 0x2f737
movq 0x68(%rsp), %rcx
movq 0x78(%rsp), %rax
addq 0x60(%rax), %rcx
movq %rcx, 0x60(%rax)
cmpl $0x0, 0x74(%rsp)
jne 0x2f3c9
movq 0x78(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x78(%rsp), %rcx
addq 0x58(%rcx), %rax
movq %rax, 0x48(%rsp)
jmp 0x2f3e8
movq 0x78(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x78(%rsp), %rcx
movq 0x70(%rcx), %rcx
subq 0x68(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x74(%rsp), %ecx
leaq 0x50(%rsp), %rdx
callq 0x7cae0
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x74(%rsp)
jne 0x2f436
movq 0x78(%rsp), %rax
movq 0x58(%rax), %rax
addq 0x68(%rsp), %rax
addq 0x50(%rsp), %rax
movq 0x78(%rsp), %rcx
cmpq 0x70(%rcx), %rax
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x5c(%rsp)
jmp 0x2f49d
movq 0x78(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x78(%rsp), %rax
movq 0x70(%rax), %rax
movq 0x68(%rsp), %rcx
addq 0x50(%rsp), %rcx
cmpq %rcx, %rax
jae 0x2f46c
movq 0x78(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x2f47b
movq 0x68(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
subq %rcx, %rax
movq 0x78(%rsp), %rcx
cmpq 0x58(%rcx), %rax
setbe %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
je 0x2f6cd
movq 0x78(%rsp), %rax
cmpl $0x1, 0x38(%rax)
je 0x2f4c4
movq $0x0, 0x80(%rsp)
jmp 0x2f737
jmp 0x2f4c6
movq 0x78(%rsp), %rax
cmpq $0x0, 0x28(%rax)
je 0x2f4de
movq 0x78(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x2f511
movq 0x95b0b(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
leaq 0x81eb1(%rip), %rsi     # 0xb13a0
leaq 0x81ec8(%rip), %rdx     # 0xb13be
movl $0x20b1, %ecx           # imm = 0x20B1
movb $0x0, %al
callq 0x13ec0
movq 0x95ae7(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
callq 0x149a0
jmp 0x2f513
movq 0x78(%rsp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x2f536
movq 0x78(%rsp), %rax
cmpq $0x0, 0x28(%rax)
je 0x2f536
movq 0x78(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x2f547
movq $0x0, 0x80(%rsp)
jmp 0x2f737
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rax), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x20(%rsp)
testq %rax, %rax
movss %xmm0, 0x24(%rsp)
js 0x2f58e
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x18(%rsp), %rax
movss 0x24(%rsp), %xmm0
movss 0x50(%rax), %xmm1
mulss %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttss2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movss 0x7df4f(%rip), %xmm1    # 0xad508
subss %xmm1, %xmm0
cvttss2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq 0x58(%rax), %rax
addq 0x68(%rsp), %rax
movl %eax, %edi
callq 0x7cbe0
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x2f618
movq 0x78(%rsp), %rax
movq 0x58(%rax), %rax
addq 0x68(%rsp), %rax
movl %eax, %edi
callq 0x7cbe0
movl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0x2f622
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x78(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq $0x40, %rdx
addq $0x8, %rdx
callq 0x7cc50
movq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x78(%rsp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x2f671
movq $0x0, 0x80(%rsp)
jmp 0x2f737
cmpl $0x0, 0x74(%rsp)
jne 0x2f691
movq 0x78(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x78(%rsp), %rcx
addq 0x58(%rcx), %rax
movq %rax, 0x48(%rsp)
jmp 0x2f6b0
movq 0x78(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x78(%rsp), %rcx
movq 0x70(%rcx), %rcx
subq 0x68(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x74(%rsp), %ecx
leaq 0x50(%rsp), %rdx
callq 0x7cae0
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x74(%rsp)
jne 0x2f6ed
movq 0x68(%rsp), %rcx
addq 0x50(%rsp), %rcx
movq 0x78(%rsp), %rax
addq 0x58(%rax), %rcx
movq %rcx, 0x58(%rax)
jmp 0x2f707
movq 0x68(%rsp), %rdx
addq 0x50(%rsp), %rdx
movq 0x78(%rsp), %rax
movq 0x70(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x70(%rax)
movq 0x50(%rsp), %rcx
movq 0x78(%rsp), %rax
addq 0x60(%rax), %rcx
movq %rcx, 0x60(%rax)
movq 0x78(%rsp), %rax
movq 0x68(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x68(%rax)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
addq $0x88, %rsp
retq
nopw (%rax,%rax)