// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tigr.c
// Function: tigrLoadGlyphs
int tigrLoadGlyphs(TigrFont* font, int codepage) {
    int i, x = 0, y = 0, w, h, rowh = 1;
    TigrGlyph* g;
    switch (codepage) {
        case 0:
            font->numGlyphs = 128 - 32;
            break;
        case 1252:
            font->numGlyphs = 256 - 32;
            break;
    }

    font->glyphs = (TigrGlyph*)calloc(font->numGlyphs, sizeof(TigrGlyph));
    for (i = 32; i < font->numGlyphs + 32; i++) {
        // Find the next glyph.
        scan(font->bitmap, &x, &y, &rowh);
        if (y >= font->bitmap->h) {
            errno = EINVAL;
            return 0;
        }

        // Scan the width and height
        w = h = 0;
        while (!border(font->bitmap, x + w, y))
            w++;
        while (!border(font->bitmap, x, y + h))
            h++;

        // Look up the Unicode code point.
        g = &font->glyphs[i - 32];
        if (i < 128)
            g->code = i;  // ASCII
        else if (codepage == 1252)
            g->code = cp1252[i - 128];
        else {
            errno = EINVAL;
            return 0;
        }

        g->x = x;
        g->y = y;
        g->w = w;
        g->h = h;
        x += w;
        if (h != font->glyphs[0].h) {
            errno = EINVAL;
            return 0;
        }

        if (h > rowh)
            rowh = h;
    }

    // Sort by code point.
    for (i = 1; i < font->numGlyphs; i++) {
        int j = i;
        TigrGlyph g = font->glyphs[i];
        while (j > 0 && font->glyphs[j - 1].code > g.code) {
            font->glyphs[j] = font->glyphs[j - 1];
            j--;
        }
        font->glyphs[j] = g;
    }

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0x63cc
jmp 0x63c0
movl -0x54(%rbp), %eax
subl $0x4e4, %eax            # imm = 0x4E4
je 0x63d9
jmp 0x63e4
movq -0x10(%rbp), %rax
movl $0x60, 0x8(%rax)
jmp 0x63e4
movq -0x10(%rbp), %rax
movl $0xe0, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rdi
movl $0x14, %esi
callq 0x3270
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x20, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x20, %ecx
cmpl %ecx, %eax
jge 0x65ac
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x1c(%rbp), %rsi
leaq -0x20(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
callq 0x66c0
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x4(%rcx), %eax
jl 0x645b
callq 0x3050
movl $0x16, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x66b2
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
addl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x6750
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x648c
jmp 0x6497
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6469
jmp 0x6499
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
addl -0x28(%rbp), %edx
callq 0x6750
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x64bc
jmp 0x64c7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6499
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
subl $0x20, %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x80, -0x18(%rbp)
jge 0x64f7
movl -0x18(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6536
cmpl $0x4e4, -0x14(%rbp)     # imm = 0x4E4
jne 0x651d
movl -0x18(%rbp), %eax
subl $0x80, %eax
movslq %eax, %rcx
leaq 0xdf0e(%rip), %rax      # 0x14420
movl (%rax,%rcx,4), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6534
callq 0x3050
movl $0x16, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x66b2
jmp 0x6536
movl -0x1c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x20(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x28(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x24(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl 0x10(%rcx), %eax
je 0x658e
callq 0x3050
movl $0x16, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x66b2
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x659c
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x659e
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x6408
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x66ab
movl -0x18(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x55(%rbp)
jle 0x661f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x50(%rbp), %eax
setg %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x6628
jmp 0x6675
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x65f1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %ecx
movl %ecx, 0x10(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x65b3
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)