// File: /workspace/github_c_makefile_star2_O1/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_font_bake_pack
NK_INTERN int
nk_font_bake_pack(struct nk_font_baker *baker,
    nk_size *image_memory, int *width, int *height, struct nk_recti *custom,
    const struct nk_font_config *config_list, int count,
    struct nk_allocator *alloc)
{
    NK_STORAGE const nk_size max_height = 1024 * 32;
    const struct nk_font_config *config_iter, *it;
    int total_glyph_count = 0;
    int total_range_count = 0;
    int range_count = 0;
    int i = 0;

    NK_ASSERT(image_memory);
    NK_ASSERT(width);
    NK_ASSERT(height);
    NK_ASSERT(config_list);
    NK_ASSERT(count);
    NK_ASSERT(alloc);

    if (!image_memory || !width || !height || !config_list || !count) return nk_false;
    for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
        it = config_iter;
        do {range_count = nk_range_count(it->range);
            total_range_count += range_count;
            total_glyph_count += nk_range_glyph_count(it->range, range_count);
        } while ((it = it->n) != config_iter);
    }
    /* setup font baker from temporary memory */
    for (config_iter = config_list; config_iter; config_iter = config_iter->next) {
        it = config_iter;
        do {
            struct stbtt_fontinfo *font_info = &baker->build[i++].info;
            font_info->userdata = alloc;

            if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0)))
                return nk_false;
        } while ((it = it->n) != config_iter);
    }
    *height = 0;
    *width = (total_glyph_count > 1000) ? 1024 : 512;
    stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc);
    {
        int input_i = 0;
        int range_n = 0;
        int rect_n = 0;
        int char_n = 0;

        if (custom) {
            /* pack custom user data first so it will be in the upper left corner*/
            struct stbrp_rect custom_space;
            nk_zero(&custom_space, sizeof(custom_space));
            custom_space.w = (stbrp_coord)(custom->w);
            custom_space.h = (stbrp_coord)(custom->h);

            stbtt_PackSetOversampling(&baker->spc, 1, 1);
            stbrp_pack_rects((struct stbrp_context*)baker->spc.pack_info, &custom_space, 1);
            *height = NK_MAX(*height, (int)(custom_space.y + custom_space.h));

            custom->x = (short)custom_space.x;
            custom->y = (short)custom_space.y;
            custom->w = (short)custom_space.w;
            custom->h = (short)custom_space.h;
        }

        /* first font pass: pack all glyphs */
        for (input_i = 0, config_iter = config_list; input_i < count && config_iter;
            config_iter = config_iter->next) {
            it = config_iter;
            do {int n = 0;
                int glyph_count;
                const nk_rune *in_range;
                const struct nk_font_config *cfg = it;
                struct nk_font_bake_data *tmp = &baker->build[input_i++];

                /* count glyphs + ranges in current font */
                glyph_count = 0; range_count = 0;
                for (in_range = cfg->range; in_range[0] && in_range[1]; in_range += 2) {
                    glyph_count += (int)(in_range[1] - in_range[0]) + 1;
                    range_count++;
                }

                /* setup ranges  */
                tmp->ranges = baker->ranges + range_n;
                tmp->range_count = (nk_rune)range_count;
                range_n += range_count;
                for (i = 0; i < range_count; ++i) {
                    in_range = &cfg->range[i * 2];
                    tmp->ranges[i].font_size = cfg->size;
                    tmp->ranges[i].first_unicode_codepoint_in_range = (int)in_range[0];
                    tmp->ranges[i].num_chars = (int)(in_range[1]- in_range[0]) + 1;
                    tmp->ranges[i].chardata_for_range = baker->packed_chars + char_n;
                    char_n += tmp->ranges[i].num_chars;
                }

                /* pack */
                tmp->rects = baker->rects + rect_n;
                rect_n += glyph_count;
                stbtt_PackSetOversampling(&baker->spc, cfg->oversample_h, cfg->oversample_v);
                n = stbtt_PackFontRangesGatherRects(&baker->spc, &tmp->info,
                    tmp->ranges, (int)tmp->range_count, tmp->rects);
                stbrp_pack_rects((struct stbrp_context*)baker->spc.pack_info, tmp->rects, (int)n);

                /* texture height */
                for (i = 0; i < n; ++i) {
                    if (tmp->rects[i].was_packed)
                        *height = NK_MAX(*height, tmp->rects[i].y + tmp->rects[i].h);
                }
            } while ((it = it->n) != config_iter);
        }
        NK_ASSERT(rect_n == total_glyph_count);
        NK_ASSERT(char_n == total_glyph_count);
        NK_ASSERT(range_n == total_range_count);
    }
    *height = (int)nk_round_up_pow2((nk_uint)*height);
    *image_memory = (nk_size)(*width) * (nk_size)(*height);
    return nk_true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r15
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
testq %rsi, %rsi
jne 0x35993
movq 0x52682(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3c414(%rip), %rsi     # 0x71d8c
leaq 0x3c42b(%rip), %rdx     # 0x71daa
movl $0x4146, %ecx           # imm = 0x4146
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
movl 0xc0(%rsp), %ebp
testq %r15, %r15
jne 0x359cb
movq 0x5264a(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3c3dc(%rip), %rsi     # 0x71d8c
leaq 0x3c3f3(%rip), %rdx     # 0x71daa
movl $0x4149, %ecx           # imm = 0x4149
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
testl %ebp, %ebp
jne 0x359fb
movq 0x5261a(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3c3ac(%rip), %rsi     # 0x71d8c
leaq 0x3c3c3(%rip), %rdx     # 0x71daa
movl $0x414a, %ecx           # imm = 0x414A
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
cmpq $0x0, 0xc8(%rsp)
jne 0x35a32
movq 0x525e3(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3c375(%rip), %rsi     # 0x71d8c
leaq 0x3c38c(%rip), %rdx     # 0x71daa
movl $0x414b, %ecx           # imm = 0x414B
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
testl %ebp, %ebp
sete %al
movq %r15, 0x20(%rsp)
testq %r15, %r15
sete %cl
movq %r14, 0x58(%rsp)
testq %r14, %r14
sete %dl
orb %cl, %dl
movl $0x0, 0x18(%rsp)
orb %al, %dl
jne 0x35eed
xorl %r12d, %r12d
movq 0x20(%rsp), %r15
movq %r15, %rbx
xorl %r13d, %r13d
movq %rbx, %r14
movq 0x30(%r14), %rdi
callq 0x33805
addl %eax, %r12d
movq 0x30(%r14), %rdi
movl %eax, %esi
callq 0x573bd
addl %eax, %r13d
movq 0x48(%r14), %r14
cmpq %rbx, %r14
jne 0x35a70
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x35a6d
xorl %eax, %eax
movq %r15, %rcx
cltq
imulq $0xb8, %rax, %rbp
movq %rcx, %r15
movq %rcx, 0x40(%rsp)
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq 0x58(%rax), %rbx
movq 0xc8(%rsp), %rax
movq %rax, (%rbx,%rbp)
addq %rbp, %rbx
movq 0x8(%r15), %r14
movl $0x0, 0x18(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x137e0
movq %rbx, %rdi
movq 0x10(%rsp), %rbx
movq %r14, %rsi
movl %eax, %edx
callq 0x13d40
testl %eax, %eax
je 0x35eed
movq 0x28(%rsp), %rax
incq %rax
movq 0x48(%r15), %r15
addq $0xb8, %rbp
movq 0x40(%rsp), %rcx
cmpq %rcx, %r15
jne 0x35ab1
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x35aa0
movq 0x30(%rsp), %r14
movl $0x0, (%r14)
xorl %edx, %edx
cmpl $0x3e9, %r13d           # imm = 0x3E9
setge %dl
shll $0x9, %edx
addl $0x200, %edx            # imm = 0x200
movq 0x50(%rsp), %rax
movl %edx, (%rax)
leaq 0x18(%rbx), %rdi
movq 0xc8(%rsp), %rax
movq %rax, (%rsp)
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x12cf0
movq 0x38(%rsp), %r15
testq %r15, %r15
je 0x35c07
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movswl 0x4(%r15), %eax
movl %eax, 0x4(%rbx)
movswl 0x6(%r15), %eax
movl %eax, 0x8(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq 0x10(%rsp), %rcx
movq %rax, 0x3c(%rcx)
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x12d20
movl (%r14), %eax
movl 0x8(%rbx), %ecx
movl 0x10(%rbx), %edx
leal (%rcx,%rdx), %esi
cmpl %esi, %eax
cmovgl %eax, %esi
movl %esi, (%r14)
movzwl 0xc(%rbx), %eax
movw %ax, (%r15)
movw %dx, 0x2(%r15)
movzwl 0x4(%rbx), %eax
movq 0x10(%rsp), %rbx
movw %ax, 0x4(%r15)
movw %cx, 0x6(%r15)
movl $0x0, %r11d
movl $0x0, %ebp
cmpl $0x0, 0xc0(%rsp)
movq 0x20(%rsp), %rax
movl $0x0, %r8d
jle 0x35e00
xorl %ebp, %ebp
xorl %r11d, %r11d
xorl %r8d, %r8d
xorl %r9d, %r9d
movslq %r9d, %r9
movq %rax, %rsi
movq %rax, 0x20(%rsp)
movq 0x30(%rsi), %rax
movl (%rax), %ecx
xorl %r15d, %r15d
xorl %r14d, %r14d
testl %ecx, %ecx
je 0x35c6d
movl 0x4(%rax,%r15,8), %edx
testl %edx, %edx
je 0x35c6d
subl %ecx, %r14d
addl %edx, %r14d
incl %r14d
movl 0x8(%rax,%r15,8), %ecx
incq %r15
jmp 0x35c4d
imulq $0xb8, %r9, %rdx
addq 0x58(%rbx), %rdx
movslq %r8d, %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x3, %rcx
addq 0x70(%rbx), %rcx
movq %rcx, 0xa8(%rdx)
movq %rdx, 0x60(%rsp)
movl %r15d, 0xb0(%rdx)
testl %r15d, %r15d
movq %rsi, 0x28(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x68(%rsp)
je 0x35d00
movss 0x20(%rsi), %xmm0
movq 0x60(%rbx), %rdx
movl %r15d, %esi
xorl %edi, %edi
movss %xmm0, (%rcx)
movl (%rax,%rdi,8), %r8d
movl %r8d, 0x4(%rcx)
movl 0x4(%rax,%rdi,8), %r8d
subl (%rax,%rdi,8), %r8d
leal 0x1(%r8), %r9d
movl %r9d, 0x10(%rcx)
movslq %ebp, %r9
leaq (%r9,%r9,8), %r10
leaq (%r10,%r10,2), %r10
addq %r9, %r10
addq %rdx, %r10
movq %r10, 0x18(%rcx)
leal (%r8,%r9), %ebp
incl %ebp
incq %rdi
addq $0x28, %rcx
cmpq %rdi, %rsi
jne 0x35cbc
movl %r11d, 0x38(%rsp)
movslq %r11d, %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x68(%rbx), %rax
movq 0x60(%rsp), %rbx
movq %rax, 0xa0(%rbx)
movq 0x28(%rsp), %rax
movzbl 0x1c(%rax), %esi
movzbl 0x1b(%rax), %edx
movq 0x18(%rsp), %rdi
callq 0x13ed0
movq 0xa0(%rbx), %r8
movq 0xa8(%rbx), %rdx
movl 0xb0(%rbx), %ecx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x12ca0
movl %eax, %edx
movl %eax, 0x4c(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0xa0(%rbx), %rsi
callq 0x12d20
movl 0x4c(%rsp), %ecx
testl %ecx, %ecx
movq 0x30(%rsp), %r8
movq 0x68(%rsp), %r9
jle 0x35dbb
movq 0xa0(%rbx), %rax
movl %ecx, %ecx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
cmpl $0x0, 0x14(%rax,%rdx)
je 0x35db2
movl (%r8), %esi
movl 0x8(%rax,%rdx), %edi
addl 0x10(%rax,%rdx), %edi
cmpl %edi, %esi
cmovgl %esi, %edi
movl %edi, (%r8)
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x35d98
incq %r9
movq 0x40(%rsp), %r8
addl %r15d, %r8d
movl 0x38(%rsp), %r11d
addl %r14d, %r11d
movq 0x28(%rsp), %rsi
movq 0x48(%rsi), %rsi
movq 0x20(%rsp), %rax
cmpq %rax, %rsi
movq 0x10(%rsp), %rbx
jne 0x35c41
cmpl 0xc0(%rsp), %r9d
jge 0x35e00
movq (%rax), %rax
testq %rax, %rax
jne 0x35c36
cmpl %r13d, %r11d
je 0x35e37
movq 0x521e4(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3bf76(%rip), %rsi     # 0x71d8c
leaq 0x3bf8d(%rip), %rdx     # 0x71daa
movl $0x41a7, %ecx           # imm = 0x41A7
xorl %eax, %eax
movq %r8, %r14
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
movq %r14, %r8
cmpl %r13d, %ebp
movq 0x58(%rsp), %r14
je 0x35e73
movq 0x521a8(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3bf3a(%rip), %rsi     # 0x71d8c
leaq 0x3bf51(%rip), %rdx     # 0x71daa
movl $0x41a8, %ecx           # imm = 0x41A8
xorl %eax, %eax
movq %r8, %r15
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
movq %r15, %r8
cmpl %r12d, %r8d
je 0x35ea4
movq 0x52171(%rip), %rbx     # 0x87ff0
movq (%rbx), %rdi
leaq 0x3bf03(%rip), %rsi     # 0x71d8c
leaq 0x3bf1a(%rip), %rdx     # 0x71daa
movl $0x41a9, %ecx           # imm = 0x41A9
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
movq 0x30(%rsp), %rdx
movl (%rdx), %eax
decl %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, (%rdx)
movq 0x50(%rsp), %rax
movslq (%rax), %rax
movslq %ecx, %rcx
imulq %rax, %rcx
movq %rcx, (%r14)
movl $0x1, 0x18(%rsp)
movl 0x18(%rsp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq