// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
testq %rdi, %rdi
je 0x24076
testq %r14, %r14
je 0x240ae
movq %rcx, %r15
movl %esi, %ebp
movq %rdi, %rbx
addq %r14, 0x60(%rdi)
movq 0x40(%rdi), %rdi
testl %esi, %esi
je 0x240e2
movq 0x70(%rbx), %rax
subq %r14, %rax
jmp 0x240e6
movq 0x60f73(%rip), %rbx     # 0x84ff0
movq (%rbx), %rdi
leaq 0x45c85(%rip), %rsi     # 0x69d0c
leaq 0x45c9c(%rip), %rdx     # 0x69d2a
xorl %r12d, %r12d
movl $0x209d, %ecx           # imm = 0x209D
xorl %eax, %eax
callq 0x12ea0
movq (%rbx), %rdi
callq 0x13960
testq %r14, %r14
jne 0x24311
movq 0x60f3b(%rip), %rbx     # 0x84ff0
movq (%rbx), %rdi
leaq 0x45c4d(%rip), %rsi     # 0x69d0c
leaq 0x45c64(%rip), %rdx     # 0x69d2a
xorl %r12d, %r12d
movl $0x209e, %ecx           # imm = 0x209E
xorl %eax, %eax
callq 0x12ea0
movq (%rbx), %rdi
callq 0x13960
jmp 0x24311
movq 0x58(%rbx), %rax
addq %rax, %rdi
leaq 0x10(%rsp), %rdx
movq %r15, %rsi
movl %ebp, %ecx
callq 0x4ef14
movq %rax, %r12
testl %ebp, %ebp
je 0x2412a
movq 0x70(%rbx), %rcx
movq 0x10(%rsp), %rax
leaq (%rax,%r14), %rdx
xorl %esi, %esi
movq %rcx, %rdi
subq %rdx, %rdi
cmovaeq %rdi, %rsi
cmpq 0x58(%rbx), %rsi
jbe 0x24144
subq %rdx, %rcx
movq %rcx, 0x70(%rbx)
jmp 0x242f5
movq 0x58(%rbx), %rcx
leaq (%rcx,%r14), %rdx
movq 0x10(%rsp), %rax
addq %rax, %rdx
cmpq 0x70(%rbx), %rdx
jbe 0x242eb
cmpl $0x1, 0x38(%rbx)
jne 0x241b8
cmpq $0x0, 0x28(%rbx)
je 0x24158
cmpq $0x0, 0x30(%rbx)
jne 0x24193
movq 0x60e91(%rip), %r13     # 0x84ff0
movq (%r13), %rdi
leaq 0x45ba2(%rip), %rsi     # 0x69d0c
leaq 0x45bb9(%rip), %rdx     # 0x69d2a
xorl %r12d, %r12d
movl $0x20b1, %ecx           # imm = 0x20B1
xorl %eax, %eax
callq 0x12ea0
movq (%r13), %rdi
callq 0x13960
cmpl $0x1, 0x38(%rbx)
jne 0x24311
movq 0x28(%rbx), %r12
testq %r12, %r12
je 0x241b8
cmpq $0x0, 0x30(%rbx)
je 0x241b8
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
movq %rcx, 0x8(%rsp)
js 0x241c0
cvtsi2ss %rcx, %xmm0
jmp 0x241d5
xorl %r12d, %r12d
jmp 0x24311
movq %rcx, %rax
shrq %rax
andl $0x1, %ecx
orq %rax, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
mulss 0x50(%rbx), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0x42666(%rip), %xmm0    # 0x66854
cvttss2si %xmm0, %r13
andq %rcx, %r13
orq %rax, %r13
movl 0x58(%rbx), %edi
addl %r14d, %edi
callq 0x4ef52
movl %eax, %eax
cmpq %rax, %r13
cmovbeq %rax, %r13
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
movq %r13, %rdx
callq *%r12
testq %rax, %rax
je 0x2427b
movq %rax, %r12
movq %r13, 0x48(%rbx)
movq 0x40(%rbx), %rsi
cmpq %rsi, %rax
movq 0x8(%rsp), %rdx
je 0x24252
movq %r12, %rdi
movq 0x8(%rsp), %rdx
callq 0x24323
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq *0x30(%rbx)
movq 0x8(%rsp), %rdx
movq 0x70(%rbx), %rsi
subq %rsi, %rdx
je 0x2426a
subq %rdx, %r13
leaq (%r12,%r13), %rdi
addq %r12, %rsi
callq 0x24323
movq %r13, 0x70(%rbx)
movq %r12, 0x40(%rbx)
testl %ebp, %ebp
je 0x242b1
subq %r14, %r13
jmp 0x242b5
movq 0x60d6e(%rip), %r14     # 0x84ff0
movq (%r14), %rdi
leaq 0x45a80(%rip), %rsi     # 0x69d0c
leaq 0x45a97(%rip), %rdx     # 0x69d2a
xorl %r12d, %r12d
movl $0x207b, %ecx           # imm = 0x207B
xorl %eax, %eax
callq 0x12ea0
movq (%r14), %rdi
callq 0x13960
andq $0x0, 0x40(%rbx)
jmp 0x24311
movq 0x58(%rbx), %r13
addq %r13, %r12
leaq 0x10(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x4ef14
movq %rax, %r12
movq (%r13), %rax
testl %ebp, %ebp
je 0x242e7
movq 0x70(%rbx), %rcx
addq %rax, %r14
movq %r14, %rdx
jmp 0x2411e
movq 0x58(%rbx), %rcx
addq %rax, %r14
addq %rcx, %r14
movq %r14, 0x58(%rbx)
movdqu 0x60(%rbx), %xmm0
movq %rax, %xmm1
shufpd $0x2, 0x42288(%rip), %xmm1 # xmm1 = xmm1[0],mem[1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x60(%rbx)
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq