// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: prepare_fills
STATIC void
_prepare_fills(lxw_workbook *self)
{

    lxw_hash_table *fills = lxw_hash_new(128, 1, 1);
    lxw_hash_element *hash_element;
    lxw_hash_element *used_format_element;
    uint16_t index = 2;
    lxw_fill *default_fill_1 = NULL;
    lxw_fill *default_fill_2 = NULL;
    uint16_t *fill_index1 = NULL;
    uint16_t *fill_index2 = NULL;

    default_fill_1 = calloc(1, sizeof(lxw_fill));
    GOTO_LABEL_ON_MEM_ERROR(default_fill_1, mem_error);

    default_fill_2 = calloc(1, sizeof(lxw_fill));
    GOTO_LABEL_ON_MEM_ERROR(default_fill_2, mem_error);

    fill_index1 = calloc(1, sizeof(uint16_t));
    GOTO_LABEL_ON_MEM_ERROR(fill_index1, mem_error);

    fill_index2 = calloc(1, sizeof(uint16_t));
    GOTO_LABEL_ON_MEM_ERROR(fill_index2, mem_error);

    /* Add the default fills. */
    default_fill_1->pattern = LXW_PATTERN_NONE;
    default_fill_1->fg_color = LXW_COLOR_UNSET;
    default_fill_1->bg_color = LXW_COLOR_UNSET;
    *fill_index1 = 0;
    lxw_insert_hash_element(fills, default_fill_1, fill_index1,
                            sizeof(lxw_fill));

    default_fill_2->pattern = LXW_PATTERN_GRAY_125;
    default_fill_2->fg_color = LXW_COLOR_UNSET;
    default_fill_2->bg_color = LXW_COLOR_UNSET;
    *fill_index2 = 1;
    lxw_insert_hash_element(fills, default_fill_2, fill_index2,
                            sizeof(lxw_fill));

    /* For DXF formats we only need to check if the properties have changed. */
    LXW_FOREACH_ORDERED(used_format_element, self->used_dxf_formats) {
        lxw_format *format = (lxw_format *) used_format_element->value;

        if (format->pattern || format->bg_color || format->fg_color) {
            format->has_dxf_fill = LXW_TRUE;
            format->dxf_bg_color = format->bg_color;
            format->dxf_fg_color = format->fg_color;
        }
    }

    LXW_FOREACH_ORDERED(used_format_element, self->used_xf_formats) {
        lxw_format *format = (lxw_format *) used_format_element->value;
        lxw_fill *key = lxw_format_get_fill_key(format);

        /* The following logical statements jointly take care of special */
        /* cases in relation to cell colors and patterns:                */
        /* 1. For a solid fill (pattern == 1) Excel reverses the role of */
        /*    foreground and background colors, and                      */
        /* 2. If the user specifies a foreground or background color     */
        /*    without a pattern they probably wanted a solid fill, so    */
        /*    we fill in the defaults.                                   */
        if (format->pattern == LXW_PATTERN_SOLID
            && format->bg_color != LXW_COLOR_UNSET
            && format->fg_color != LXW_COLOR_UNSET) {
            lxw_color_t tmp = format->fg_color;
            format->fg_color = format->bg_color;
            format->bg_color = tmp;
        }

        if (format->pattern <= LXW_PATTERN_SOLID
            && format->bg_color != LXW_COLOR_UNSET
            && format->fg_color == LXW_COLOR_UNSET) {
            format->fg_color = format->bg_color;
            format->bg_color = LXW_COLOR_UNSET;
            format->pattern = LXW_PATTERN_SOLID;
        }

        if (format->pattern <= LXW_PATTERN_SOLID
            && format->bg_color == LXW_COLOR_UNSET
            && format->fg_color != LXW_COLOR_UNSET) {
            format->pattern = LXW_PATTERN_SOLID;
        }

        if (key) {
            /* Look up the format in the hash table. */
            hash_element = lxw_hash_key_exists(fills, key, sizeof(lxw_fill));

            if (hash_element) {
                /* Fill has already been used. */
                format->fill_index = *(uint16_t *) hash_element->value;
                format->has_fill = LXW_FALSE;
                free(key);
            }
            else {
                /* This is a new fill. */
                uint16_t *fill_index = calloc(1, sizeof(uint16_t));
                *fill_index = index;
                format->fill_index = index;
                format->has_fill = 1;
                lxw_insert_hash_element(fills, key, fill_index,
                                        sizeof(lxw_fill));
                index++;
            }
        }
    }

    lxw_hash_free(fills);

    self->fill_count = index;

    return;

mem_error:
    free(fill_index2);
    free(fill_index1);
    free(default_fill_2);
    free(default_fill_1);
    lxw_hash_free(fills);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x80, %edi
movl $0x1, %edx
movl %edx, %esi
callq 0xc500
movq %rax, -0x10(%rbp)
movw $0x2, -0x22(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x1, %edi
movl $0xc, %esi
callq 0xc870
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x423ca
movq 0x3ac50(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x23d1e(%rip), %rsi     # 0x660d0
leaq 0x29297(%rip), %rdx     # 0x6b650
movl $0x1a5, %ecx            # imm = 0x1A5
movb $0x0, %al
callq 0xc8f0
jmp 0x427a2
jmp 0x423cc
movl $0x1, %edi
movl $0xc, %esi
callq 0xc870
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x4240f
movq 0x3ac0b(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x23cd9(%rip), %rsi     # 0x660d0
leaq 0x29252(%rip), %rdx     # 0x6b650
movl $0x1a8, %ecx            # imm = 0x1A8
movb $0x0, %al
callq 0xc8f0
jmp 0x427a2
jmp 0x42411
movl $0x1, %edi
movl $0x2, %esi
callq 0xc870
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x42454
movq 0x3abc6(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x23c94(%rip), %rsi     # 0x660d0
leaq 0x2920d(%rip), %rdx     # 0x6b650
movl $0x1ab, %ecx            # imm = 0x1AB
movb $0x0, %al
callq 0xc8f0
jmp 0x427a2
jmp 0x42456
movl $0x1, %edi
movl $0x2, %esi
callq 0xc870
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x42499
movq 0x3ab81(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x23c4f(%rip), %rsi     # 0x660d0
leaq 0x291c8(%rip), %rdx     # 0x6b650
movl $0x1ae, %ecx            # imm = 0x1AE
movb $0x0, %al
callq 0xc8f0
jmp 0x427a2
jmp 0x4249b
movq -0x30(%rbp), %rax
movb $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x40(%rbp), %rax
movw $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0xc, %ecx
callq 0xc040
movq -0x38(%rbp), %rax
movb $0x11, 0x8(%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x48(%rbp), %rax
movw $0x1, (%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl $0xc, %ecx
callq 0xc040
movq -0x8(%rbp), %rax
movq 0xe0(%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x425a9
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movzbl 0x1f4(%rax), %eax
cmpl $0x0, %eax
jne 0x42566
movq -0x50(%rbp), %rax
cmpl $0x0, 0x1e8(%rax)
jne 0x42566
movq -0x50(%rbp), %rax
cmpl $0x0, 0x1e4(%rax)
je 0x42599
movq -0x50(%rbp), %rax
movb $0x1, 0x1f6(%rax)
movq -0x50(%rbp), %rax
movl 0x1e8(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x1f0(%rax)
movq -0x50(%rbp), %rax
movl 0x1e4(%rax), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x1ec(%rax)
jmp 0x4259b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x42529
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x42788
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0xc7e0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movzbl 0x1f4(%rax), %eax
cmpl $0x1, %eax
jne 0x4263b
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e8(%rax)
je 0x4263b
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e4(%rax)
je 0x4263b
movq -0x58(%rbp), %rax
movl 0x1e4(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movl 0x1e8(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1e4(%rax)
movl -0x64(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1e8(%rax)
movq -0x58(%rbp), %rax
movzbl 0x1f4(%rax), %eax
cmpl $0x1, %eax
jg 0x42692
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e8(%rax)
je 0x42692
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e4(%rax)
jne 0x42692
movq -0x58(%rbp), %rax
movl 0x1e8(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1e4(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x1e8(%rax)
movq -0x58(%rbp), %rax
movb $0x1, 0x1f4(%rax)
movq -0x58(%rbp), %rax
movzbl 0x1f4(%rax), %eax
cmpl $0x1, %eax
jg 0x426c7
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e8(%rax)
jne 0x426c7
movq -0x58(%rbp), %rax
cmpl $0x0, 0x1e4(%rax)
je 0x426c7
movq -0x58(%rbp), %rax
movb $0x1, 0x1f4(%rax)
cmpq $0x0, -0x60(%rbp)
je 0x42775
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl $0xc, %edx
callq 0xc3b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x4271a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1f8(%rax)
movq -0x58(%rbp), %rax
movb $0x0, 0x1f5(%rax)
movq -0x60(%rbp), %rdi
callq 0xc0d0
jmp 0x42773
movl $0x1, %edi
movl $0x2, %esi
callq 0xc870
movq %rax, -0x70(%rbp)
movw -0x22(%rbp), %cx
movq -0x70(%rbp), %rax
movw %cx, (%rax)
movzwl -0x22(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x1f8(%rax)
movq -0x58(%rbp), %rax
movb $0x1, 0x1f5(%rax)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl $0xc, %ecx
callq 0xc040
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
jmp 0x42775
jmp 0x42777
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x425bf
movq -0x10(%rbp), %rdi
callq 0xd0e0
movw -0x22(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc8(%rax)
jmp 0x427cf
movq -0x48(%rbp), %rdi
callq 0xc0d0
movq -0x40(%rbp), %rdi
callq 0xc0d0
movq -0x38(%rbp), %rdi
callq 0xc0d0
movq -0x30(%rbp), %rdi
callq 0xc0d0
movq -0x10(%rbp), %rdi
callq 0xd0e0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)