// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_conditional_format_range
lxw_error
worksheet_conditional_format_range(lxw_worksheet *self, lxw_row_t first_row,
                                   lxw_col_t first_col,
                                   lxw_row_t last_row,
                                   lxw_col_t last_col,
                                   lxw_conditional_format *user_options)
{
    lxw_cond_format_obj *cond_format;
    lxw_row_t tmp_row;
    lxw_col_t tmp_col;
    lxw_error err = LXW_NO_ERROR;
    char *type_strings[] = {
        "none",
        "cellIs",
        "containsText",
        "timePeriod",
        "aboveAverage",
        "duplicateValues",
        "uniqueValues",
        "top10",
        "top10",
        "containsBlanks",
        "notContainsBlanks",
        "containsErrors",
        "notContainsErrors",
        "expression",
        "colorScale",
        "colorScale",
        "dataBar",
        "iconSet",
    };

    /* Swap last row/col with first row/col as necessary */
    if (first_row > last_row) {
        tmp_row = last_row;
        last_row = first_row;
        first_row = tmp_row;
    }
    if (first_col > last_col) {
        tmp_col = last_col;
        last_col = first_col;
        first_col = tmp_col;
    }

    /* Check that dimensions are valid but don't store them. */
    err = _check_dimensions(self, last_row, last_col, LXW_TRUE, LXW_TRUE);
    if (err)
        return err;

    /* Check the validation type is in correct enum range. */
    if (user_options->type <= LXW_CONDITIONAL_TYPE_NONE ||
        user_options->type >= LXW_CONDITIONAL_TYPE_LAST) {

        LXW_WARN_FORMAT1("worksheet_conditional_format_cell()/_range(): "
                         "invalid type value (%d).", user_options->type);

        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Create a copy of the parameters from the user data validation. */
    cond_format = calloc(1, sizeof(lxw_cond_format_obj));
    GOTO_LABEL_ON_MEM_ERROR(cond_format, error);

    /* Create the data validation range. */
    if (first_row == last_row && first_col == last_col)
        lxw_rowcol_to_cell(cond_format->sqref, first_row, first_col);
    else
        lxw_rowcol_to_range(cond_format->sqref, first_row, first_col,
                            last_row, last_col);

    /* Store the first cell string for text and date rules. */
    lxw_rowcol_to_cell(cond_format->first_cell, first_row, first_col);

    /* Overwrite the sqref range with a user supplied set of ranges. */
    if (user_options->multi_range) {

        if (strlen(user_options->multi_range) >= LXW_MAX_ATTRIBUTE_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_conditional_format_cell()/_range(): "
                             "multi_range >= limit = %d.",
                             LXW_MAX_ATTRIBUTE_LENGTH);
            err = LXW_ERROR_PARAMETER_VALIDATION;
            goto error;
        }

        LXW_ATTRIBUTE_COPY(cond_format->sqref, user_options->multi_range);
    }

    /* Get the conditional format dxf format index. */
    if (user_options->format)
        cond_format->dxf_index =
            lxw_format_get_dxf_index(user_options->format);
    else
        cond_format->dxf_index = LXW_PROPERTY_UNSET;

    /* Set some common option for all validation types. */
    cond_format->type = user_options->type;
    cond_format->criteria = user_options->criteria;
    cond_format->stop_if_true = user_options->stop_if_true;
    cond_format->type_string = lxw_strdup(type_strings[cond_format->type]);

    /* Validate the user input for various types of rules. */
    if (user_options->type == LXW_CONDITIONAL_TYPE_CELL
        || cond_format->type == LXW_CONDITIONAL_TYPE_DUPLICATE
        || cond_format->type == LXW_CONDITIONAL_TYPE_UNIQUE) {

        err = _validate_conditional_cell(cond_format, user_options);
        if (err)
            goto error;
    }
    else if (user_options->type == LXW_CONDITIONAL_TYPE_TEXT) {

        err = _validate_conditional_text(cond_format, user_options);
        if (err)
            goto error;
    }
    else if (user_options->type == LXW_CONDITIONAL_TYPE_TIME_PERIOD) {

        err = _validate_conditional_time_period(user_options);
        if (err)
            goto error;
    }
    else if (user_options->type == LXW_CONDITIONAL_TYPE_AVERAGE) {

        err = _validate_conditional_average(user_options);
        if (err)
            goto error;
    }
    else if (cond_format->type == LXW_CONDITIONAL_TYPE_TOP
             || cond_format->type == LXW_CONDITIONAL_TYPE_BOTTOM) {

        err = _validate_conditional_top(cond_format, user_options);
        if (err)
            goto error;
    }
    else if (user_options->type == LXW_CONDITIONAL_TYPE_FORMULA) {

        err = _validate_conditional_formula(cond_format, user_options);
        if (err)
            goto error;
    }
    else if (cond_format->type == LXW_CONDITIONAL_2_COLOR_SCALE
             || cond_format->type == LXW_CONDITIONAL_3_COLOR_SCALE) {

        err = _validate_conditional_scale(cond_format, user_options);
        if (err)
            goto error;
    }
    else if (cond_format->type == LXW_CONDITIONAL_DATA_BAR) {

        err = _validate_conditional_data_bar(self, cond_format, user_options);
        if (err)
            goto error;
    }
    else if (cond_format->type == LXW_CONDITIONAL_TYPE_ICON_SETS) {

        err = _validate_conditional_icons(user_options);
        if (err)
            goto error;

        cond_format->icon_style = user_options->icon_style;
        cond_format->reverse_icons = user_options->reverse_icons;
        cond_format->icons_only = user_options->icons_only;
    }

    /* Set the priority based on the order of adding. */
    cond_format->dxf_priority = ++self->dxf_priority;

    /* Store the conditional format object. */
    err = _store_conditional_format_object(self, cond_format);

    if (err)
        goto error;
    else
        return LXW_NO_ERROR;

error:
    _free_cond_format(cond_format);
    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r14d
movl %ecx, %r12d
movl %edx, %ebx
movl %esi, %r13d
cmpl %ecx, %esi
movl %ecx, %esi
cmoval %r13d, %esi
movl %ecx, %eax
cmovbl %r13d, %eax
movl %eax, (%rsp)
cmpw %r14w, %bx
movl %r8d, %ebp
cmoval %edx, %ebp
movl %r8d, %r15d
cmovbl %edx, %r15d
cmpl $0x100000, %esi         # imm = 0x100000
setae %al
cmpl $0x4000, %ebp           # imm = 0x4000
setae %cl
orb %al, %cl
movl $0x17, %eax
jne 0x3d6b4
movq %rdi, 0x8(%rsp)
movq %r9, 0x10(%rsp)
movzbl (%r9), %edx
leal -0x12(%rdx), %eax
cmpb $-0x12, %al
jbe 0x3d6e6
movl %esi, 0x4(%rsp)
movl $0x1, %edi
movl $0x8c8, %esi            # imm = 0x8C8
callq 0xc7f0
testq %rax, %rax
je 0x3d705
cmpl %r13d, %r12d
setne %dl
cmpw %bx, %r14w
setne %cl
leaq 0x9e(%rax), %r13
orb %dl, %cl
movzwl %r15w, %ebx
movq %rax, %r14
jne 0x3d5a5
movq %r13, %rdi
movl (%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
callq 0xca00
jmp 0x3d5bc
movzwl %bp, %r8d
movq %r13, %rdi
movl (%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
movl 0x4(%rsp), %ecx
callq 0xcd10
movq 0x10(%rsp), %r15
movq %r14, %rdi
addq $0x90, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0xca00
movq 0x90(%r15), %rbx
testq %rbx, %rbx
je 0x3d60c
movq %rbx, %rdi
callq 0xc480
cmpq $0x820, %rax            # imm = 0x820
jae 0x3d773
movl $0x81f, %edx            # imm = 0x81F
movq %r13, %rdi
movq %rbx, %rsi
callq 0xc170
movb $0x0, 0x8bd(%r14)
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x3d61c
callq 0xcb20
jmp 0x3d621
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x88(%r14)
movzbl (%r15), %eax
movb %al, (%r14)
movb 0x1(%r15), %cl
movb %cl, 0x1(%r14)
movb 0x98(%r15), %cl
movb %cl, 0x73(%r14)
leaq 0x9257(%rip), %rcx      # 0x468a0
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0xcce0
movq %rax, 0x78(%r14)
movzbl (%r15), %ecx
cmpl $0x1, %ecx
je 0x3d66e
movzbl (%r14), %eax
leal -0x5(%rax), %edx
cmpb $0x1, %dl
ja 0x3d6c3
movq %r14, %rdi
movq %r15, %rsi
callq 0xc690
movq 0x8(%rsp), %rdi
movl 0x2e8(%rdi), %eax
incl %eax
movl %eax, 0x2e8(%rdi)
movl %eax, 0x8c(%r14)
movq %r14, %rsi
callq 0xc0b0
movl $0x1, %ecx
testl %eax, %eax
je 0x3d6b2
movq %r14, %rdi
movl %ecx, %ebx
callq 0x2fc76
movl %ebx, %eax
jmp 0x3d6b4
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %ecx
je 0x3d734
cmpl $0x3, %ecx
je 0x3d711
cmpl $0x2, %ecx
jne 0x3d75e
movq %r14, %rdi
movq %r15, %rsi
callq 0xced0
jmp 0x3d792
movq 0x1990b(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0xad77(%rip), %rsi      # 0x4846e
xorl %eax, %eax
callq 0xc870
movl $0xd, %eax
jmp 0x3d6b4
movq %rax, %r14
callq 0xfbd8
xorl %ecx, %ecx
jmp 0x3d6a4
movzbl 0x1(%r15), %edx
leal -0x17(%rdx), %eax
cmpb $-0xb, %al
ja 0x3d679
movq 0x198d0(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x9bdd(%rip), %rsi      # 0x4730f
jmp 0x3d755
movzbl 0x1(%r15), %edx
leal -0x21(%rdx), %eax
cmpb $-0xb, %al
ja 0x3d679
movq 0x198ad(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x9b3a(%rip), %rsi      # 0x4728f
xorl %eax, %eax
callq 0xc870
jmp 0x3d778
leal -0x7(%rax), %edx
cmpb $0x1, %dl
ja 0x3d782
movq %r14, %rdi
movq %r15, %rsi
callq 0xcde0
jmp 0x3d792
callq 0xfbbb
movl $0xd, %ecx
jmp 0x3d6a4
cmpl $0xd, %ecx
jne 0x3d7a1
movq %r14, %rdi
movq %r15, %rsi
callq 0xc910
testl %eax, %eax
je 0x3d679
movl %eax, %ecx
jmp 0x3d6a4
leal -0xe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x3d7e3
cmpl $0x10, %eax
je 0x3d7f3
cmpl $0x11, %eax
jne 0x3d679
movzbl 0x88(%r15), %edx
cmpl $0x11, %edx
jae 0x3d808
movb %dl, 0x70(%r14)
movb 0x89(%r15), %al
movb %al, 0x71(%r14)
movb 0x8a(%r15), %al
movb %al, 0x72(%r14)
jmp 0x3d679
movq %r14, %rdi
movq %r15, %rsi
callq 0xcd30
jmp 0x3d679
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xc7c0
jmp 0x3d679
movq 0x197e9(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x98cd(%rip), %rsi      # 0x470e6
jmp 0x3d755