// File: /workspace/github_c_makefile_star2_O1/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 %rcx, %r13
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
testq %rdi, %rdi
jne 0x25592
movq 0x62a83(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x4c815(%rip), %rsi     # 0x71d8c
leaq 0x4c82c(%rip), %rdx     # 0x71daa
movl $0x209d, %ecx           # imm = 0x209D
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
testq %r14, %r14
jne 0x255c3
movq 0x62a52(%rip), %r15     # 0x87ff0
movq (%r15), %rdi
leaq 0x4c7e4(%rip), %rsi     # 0x71d8c
leaq 0x4c7fb(%rip), %rdx     # 0x71daa
movl $0x209e, %ecx           # imm = 0x209E
xorl %eax, %eax
callq 0x12d80
movq (%r15), %rdi
callq 0x13780
testq %r14, %r14
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x25830
addq %r14, 0x60(%rbx)
movq 0x40(%rbx), %r12
testl %ebp, %ebp
je 0x255ec
movq 0x70(%rbx), %rax
subq %r14, %rax
jmp 0x255f0
movq 0x58(%rbx), %rax
addq %rax, %r12
cmpl $0x1, %ebp
jne 0x25611
testq %r13, %r13
je 0x25631
movq %r13, %rax
negq %rax
andq %r12, %rax
subq %rax, %r12
movq %r12, %r15
movq %rax, %r12
jmp 0x25634
testq %r13, %r13
je 0x25631
leaq (%r12,%r13), %rax
decq %rax
movq %r13, %rcx
negq %rcx
andq %rax, %rcx
movq %rcx, %r15
subq %r12, %r15
movq %rcx, %r12
jmp 0x25634
xorl %r15d, %r15d
leaq (%r15,%r14), %rax
testl %ebp, %ebp
je 0x25652
movq 0x70(%rbx), %rcx
xorl %edx, %edx
subq %rax, %rcx
cmovaeq %rcx, %rdx
cmpq 0x58(%rbx), %rdx
setbe %al
jmp 0x2565d
addq 0x58(%rbx), %rax
cmpq 0x70(%rbx), %rax
seta %al
testb %al, %al
je 0x25823
cmpl $0x1, 0x38(%rbx)
jne 0x2581d
cmpq $0x0, 0x28(%rbx)
je 0x2567d
cmpq $0x0, 0x30(%rbx)
jne 0x256b0
movq 0x6296c(%rip), %rax     # 0x87ff0
movq (%rax), %rdi
leaq 0x4c6fe(%rip), %rsi     # 0x71d8c
leaq 0x4c715(%rip), %rdx     # 0x71daa
movl $0x20b1, %ecx           # imm = 0x20B1
xorl %eax, %eax
callq 0x12d80
movq 0x62948(%rip), %rax     # 0x87ff0
movq (%rax), %rdi
callq 0x13780
cmpl $0x1, 0x38(%rbx)
jne 0x2581d
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x2581d
cmpq $0x0, 0x30(%rbx)
je 0x2581d
movq 0x48(%rbx), %rdx
testq %rdx, %rdx
movq %rdx, 0x8(%rsp)
js 0x256e7
cvtsi2ss %rdx, %xmm0
jmp 0x256fc
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, %rsi
sarq $0x3f, %rsi
subss 0x491bf(%rip), %xmm0    # 0x6e8d4
cvttss2si %xmm0, %rdx
andq %rsi, %rdx
orq %rcx, %rdx
movl 0x58(%rbx), %ecx
addl %r14d, %ecx
decl %ecx
movl %ecx, %esi
shrl %esi
orl %ecx, %esi
movl %esi, %ecx
shrl $0x2, %ecx
orl %esi, %ecx
movl %ecx, %esi
shrl $0x4, %esi
orl %ecx, %esi
movl %esi, %ecx
shrl $0x8, %ecx
orl %esi, %ecx
movl %ecx, %esi
shrl $0x10, %esi
orl %ecx, %esi
incl %esi
cmpq %rsi, %rdx
cmovbeq %rsi, %rdx
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
movq %rdx, (%rsp)
callq *%rax
testq %rax, %rax
je 0x257d2
movq (%rsp), %rcx
movq %rcx, 0x48(%rbx)
movq 0x40(%rbx), %rsi
cmpq %rsi, %rax
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%rsp)
je 0x257a7
movq %rax, %rdi
movq 0x8(%rsp), %rdx
callq 0x258b3
movq 0x20(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq *0x30(%rbx)
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
movq 0x10(%rsp), %rax
movq 0x70(%rbx), %rsi
subq %rsi, %rdx
je 0x257cc
subq %rdx, %rcx
movq %rcx, (%rsp)
leaq (%rax,%rcx), %rdi
addq %rax, %rsi
callq 0x258b3
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, 0x70(%rbx)
jmp 0x25807
movq 0x62817(%rip), %rax     # 0x87ff0
movq (%rax), %rdi
leaq 0x4c5a9(%rip), %rsi     # 0x71d8c
leaq 0x4c5c0(%rip), %rdx     # 0x71daa
movl $0x207b, %ecx           # imm = 0x207B
xorl %eax, %eax
callq 0x12d80
movq 0x627f3(%rip), %rax     # 0x87ff0
movq (%rax), %rdi
callq 0x13780
xorl %eax, %eax
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x2581d
testl %ebp, %ebp
je 0x25867
movq 0x70(%rbx), %rcx
subq %r14, %rcx
jmp 0x2586b
xorl %edx, %edx
testb %dl, %dl
je 0x25830
addq %r15, %r14
testl %ebp, %ebp
je 0x25835
subq %r14, 0x70(%rbx)
jmp 0x25839
xorl %r12d, %r12d
jmp 0x25855
addq %r14, 0x58(%rbx)
movdqu 0x60(%rbx), %xmm0
movq %r15, %xmm1
shufpd $0x2, 0x48d44(%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
movq 0x58(%rbx), %rcx
addq %rcx, %rax
movb $0x1, %dl
cmpl $0x1, %ebp
jne 0x25888
testq %r13, %r13
je 0x258a8
negq %r13
andq %rax, %r13
subq %r13, %rax
movq %rax, %r15
jmp 0x258a0
testq %r13, %r13
je 0x258a8
leaq (%rax,%r13), %rcx
decq %rcx
negq %r13
andq %rcx, %r13
movq %r13, %r15
subq %rax, %r15
movq %r13, %r12
jmp 0x2581f
xorl %r15d, %r15d
movq %rax, %r12
jmp 0x2581f