// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq %rdx, %r14
testq %rdi, %rdi
je 0x25720
testq %r14, %r14
je 0x25758
movq %rcx, %r12
movl %esi, %ebp
movq %rdi, %rbx
addq %r14, 0x60(%rdi)
movq 0x40(%rdi), %r15
testl %esi, %esi
je 0x2578c
movq 0x70(%rbx), %r13
movq %r13, %rax
subq %r14, %rax
addq %rax, %r15
cmpl $0x1, %ebp
jne 0x257cd
testq %r12, %r12
je 0x257ed
movq %r12, %rcx
negq %rcx
andq %r15, %rcx
subq %rcx, %r15
movq %r15, %rax
jmp 0x257e8
movq 0x618c9(%rip), %rbx     # 0x86ff0
movq (%rbx), %rdi
leaq 0x4b66b(%rip), %rsi     # 0x70d9c
leaq 0x4b682(%rip), %rdx     # 0x70dba
xorl %r15d, %r15d
movl $0x209d, %ecx           # imm = 0x209D
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
testq %r14, %r14
jne 0x2589f
movq 0x61891(%rip), %rbx     # 0x86ff0
movq (%rbx), %rdi
leaq 0x4b633(%rip), %rsi     # 0x70d9c
leaq 0x4b64a(%rip), %rdx     # 0x70dba
xorl %r15d, %r15d
movl $0x209e, %ecx           # imm = 0x209E
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
jmp 0x2589f
movq 0x58(%rbx), %rcx
addq %rcx, %r15
leaq (%r12,%r15), %rax
decq %rax
movq %r12, %rdx
negq %rdx
andq %rax, %rdx
movq %rdx, %rax
subq %r15, %rax
testq %r12, %r12
cmoveq %r12, %rax
cmovneq %rdx, %r15
leaq (%rcx,%r14), %rdx
addq %rax, %rdx
cmpq 0x70(%rbx), %rdx
ja 0x2582d
addq %rcx, %r14
addq %rax, %r14
movq %r14, 0x58(%rbx)
jmp 0x2580f
testq %r12, %r12
je 0x257ed
leaq (%r15,%r12), %rax
decq %rax
movq %r12, %rcx
negq %rcx
andq %rax, %rcx
movq %rcx, %rax
subq %r15, %rax
movq %rcx, %r15
jmp 0x257ef
xorl %eax, %eax
leaq (%rax,%r14), %rcx
xorl %edx, %edx
movq %r13, %rsi
subq %rcx, %rsi
cmovaeq %rsi, %rdx
cmpq 0x58(%rbx), %rdx
jbe 0x2582d
addq %rax, %r14
subq %r14, %r13
movq %r13, 0x70(%rbx)
movdqu 0x60(%rbx), %xmm0
movq %rax, %xmm1
shufpd $0x2, 0x47d6e(%rip), %xmm1 # xmm1 = xmm1[0],mem[1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x60(%rbx)
jmp 0x2589f
cmpl $0x1, 0x38(%rbx)
jne 0x2589c
cmpq $0x0, 0x28(%rbx)
je 0x25841
cmpq $0x0, 0x30(%rbx)
jne 0x25878
movq 0x617a8(%rip), %r13     # 0x86ff0
movq (%r13), %rdi
leaq 0x4b549(%rip), %rsi     # 0x70d9c
leaq 0x4b560(%rip), %rdx     # 0x70dba
xorl %r15d, %r15d
movl $0x20b1, %ecx           # imm = 0x20B1
xorl %eax, %eax
callq 0x12d80
movq (%r13), %rdi
callq 0x13780
cmpl $0x1, 0x38(%rbx)
jne 0x2589f
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x2589c
cmpq $0x0, 0x30(%rbx)
je 0x2589c
movq 0x48(%rbx), %rdx
testq %rdx, %rdx
movq %rdx, (%rsp)
js 0x258b1
cvtsi2ss %rdx, %xmm0
jmp 0x258c6
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rcx
shrq %rcx
andl $0x1, %edx
orq %rcx, %rdx
cvtsi2ss %rdx, %xmm0
addss %xmm0, %xmm0
mulss 0x50(%rbx), %xmm0
cvttss2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subss 0x47fe5(%rip), %xmm0    # 0x6d8c4
cvttss2si %xmm0, %r13
andq %rdx, %r13
orq %rcx, %r13
movl 0x58(%rbx), %ecx
addl %r14d, %ecx
decl %ecx
movl %ecx, %edx
shrl %edx
orl %ecx, %edx
movl %edx, %ecx
shrl $0x2, %ecx
orl %edx, %ecx
movl %ecx, %edx
shrl $0x4, %edx
orl %ecx, %edx
movl %edx, %ecx
shrl $0x8, %ecx
orl %edx, %ecx
movl %ecx, %edx
shrl $0x10, %edx
orl %ecx, %edx
incl %edx
cmpq %rdx, %r13
cmovbeq %rdx, %r13
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
movq %r13, %rdx
callq *%rax
testq %rax, %rax
je 0x259a7
movq %rax, %r15
movq %r13, 0x48(%rbx)
movq 0x40(%rbx), %rsi
cmpq %rsi, %rax
movq (%rsp), %rdx
je 0x2595e
movq %r15, %rdi
movq (%rsp), %rdx
callq 0x25a38
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq *0x30(%rbx)
movq (%rsp), %rdx
movq 0x70(%rbx), %rsi
subq %rsi, %rdx
je 0x25976
subq %rdx, %r13
leaq (%r15,%r13), %rdi
addq %r15, %rsi
callq 0x25a38
movq %r13, 0x70(%rbx)
movq %r15, 0x40(%rbx)
testl %ebp, %ebp
je 0x259e3
movq %r13, %rax
subq %r14, %rax
addq %rax, %r15
cmpl $0x1, %ebp
jne 0x25a0a
testq %r12, %r12
je 0x25a2a
negq %r12
andq %r15, %r12
movq %r15, %rax
subq %r12, %rax
jmp 0x25a22
movq 0x61642(%rip), %r14     # 0x86ff0
movq (%r14), %rdi
leaq 0x4b3e4(%rip), %rsi     # 0x70d9c
leaq 0x4b3fb(%rip), %rdx     # 0x70dba
xorl %r15d, %r15d
movl $0x207b, %ecx           # imm = 0x207B
xorl %eax, %eax
callq 0x12d80
movq (%r14), %rdi
callq 0x13780
movq $0x0, 0x40(%rbx)
jmp 0x2589f
movq 0x58(%rbx), %rcx
addq %rcx, %r15
testq %r12, %r12
je 0x25a31
leaq (%r15,%r12), %rax
decq %rax
negq %r12
andq %rax, %r12
movq %r12, %rax
subq %r15, %rax
movq %r12, %r15
jmp 0x257c1
testq %r12, %r12
je 0x25a2a
leaq (%r15,%r12), %rax
decq %rax
negq %r12
andq %rax, %r12
movq %r12, %rax
subq %r15, %rax
movq %r12, %r15
jmp 0x25805
xorl %eax, %eax
jmp 0x25805
xorl %eax, %eax
jmp 0x257c1