// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %ecx, %r12d
movl %edx, %r14d
movl %esi, %ebx
cmpl %ecx, %esi
movl %ecx, %esi
cmoval %ebx, %esi
movl %ecx, %eax
cmovbl %ebx, %eax
movl %eax, (%rsp)
cmpw %bp, %r14w
movl %r8d, %r13d
cmoval %edx, %r13d
movl %r8d, %r15d
cmovbl %edx, %r15d
cmpl $0x100000, %esi         # imm = 0x100000
setae %al
cmpw $0x4000, %r13w          # imm = 0x4000
setae %cl
orb %al, %cl
je 0x3a6ea
pushq $0x17
popq %rbp
jmp 0x3a932
movq %r9, 0x10(%rsp)
movzbl (%r9), %edx
leal -0x12(%rdx), %eax
cmpb $-0x12, %al
jbe 0x3a879
movl %esi, 0x4(%rsp)
movq %rdi, 0x8(%rsp)
pushq $0x1
popq %rdi
movl $0x8c8, %esi            # imm = 0x8C8
callq 0xc850
testq %rax, %rax
je 0x3a898
cmpl %ebx, %r12d
setne %dl
cmpw %r14w, %bp
setne %cl
leaq 0x9e(%rax), %r14
orb %dl, %cl
movzwl %r15w, %ebx
movq %rax, %r15
jne 0x3a74d
movq %r14, %rdi
movl (%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
callq 0xca60
jmp 0x3a764
movzwl %r13w, %r8d
movq %r14, %rdi
movl (%rsp), %ebp
movl %ebp, %esi
movl %ebx, %edx
movl 0x4(%rsp), %ecx
callq 0xcd90
movq 0x10(%rsp), %r12
movq %r15, %rdi
addq $0x90, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0xca60
movq 0x90(%r12), %rbx
testq %rbx, %rbx
je 0x3a7b5
movq %rbx, %rdi
callq 0xc4c0
cmpq $0x820, %rax            # imm = 0x820
jae 0x3a8ec
movl $0x81f, %edx            # imm = 0x81F
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc190
movb $0x0, 0x8bd(%r15)
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x3a7c6
callq 0xcb90
jmp 0x3a7c9
pushq $-0x1
popq %rax
movl %eax, 0x88(%r15)
movzbl (%r12), %eax
movb %al, (%r15)
movb 0x1(%r12), %cl
movb %cl, 0x1(%r15)
movb 0x98(%r12), %cl
movb %cl, 0x73(%r15)
leaq 0x908c(%rip), %rcx      # 0x43880
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0xcd50
movq %rax, 0x78(%r15)
movzbl (%r12), %ecx
cmpl $0x1, %ecx
je 0x3a81a
movzbl (%r15), %eax
leal -0x5(%rax), %edx
cmpb $0x1, %dl
ja 0x3a85a
movq %r15, %rdi
movq %r12, %rsi
callq 0xc6f0
movq 0x8(%rsp), %rdi
movl 0x2e8(%rdi), %eax
incl %eax
movl %eax, 0x2e8(%rdi)
movl %eax, 0x8c(%r15)
movq %r15, %rsi
callq 0xc0c0
testl %eax, %eax
je 0x3a853
pushq $0x1
popq %rbp
jmp 0x3a92a
xorl %ebp, %ebp
jmp 0x3a932
cmpl $0x4, %ecx
je 0x3a8cd
cmpl $0x3, %ecx
je 0x3a8c3
cmpl $0x2, %ecx
jne 0x3a8d7
movq %r15, %rdi
movq %r12, %rsi
callq 0xcf50
jmp 0x3a920
movq 0x18778(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xabd0(%rip), %rsi      # 0x4545a
xorl %eax, %eax
callq 0xc8d0
pushq $0xd
jmp 0x3a6e4
movq 0x18759(%rip), %rcx     # 0x52ff8
movq (%rcx), %rdi
leaq 0x2837(%rip), %rsi      # 0x3d0e0
movq %rax, %r15
leaq 0x912d(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x2b14, %ecx           # imm = 0x2B14
xorl %eax, %eax
callq 0xc8d0
jmp 0x3a92a
movq %r12, %rdi
callq 0xc650
jmp 0x3a920
movq %r12, %rdi
callq 0xd190
jmp 0x3a920
leal -0x7(%rax), %edx
cmpb $0x1, %dl
ja 0x3a910
movq %r15, %rdi
movq %r12, %rsi
callq 0xce60
jmp 0x3a920
movq 0x18705(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xabb0(%rip), %rsi      # 0x454ad
movl $0x820, %edx            # imm = 0x820
xorl %eax, %eax
callq 0xc8d0
pushq $0xd
jmp 0x3a84d
cmpl $0xd, %ecx
jne 0x3a943
movq %r15, %rdi
movq %r12, %rsi
callq 0xc970
testl %eax, %eax
je 0x3a825
movl %eax, %ebp
movq %r15, %rdi
callq 0x2ca65
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal -0xe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x3a98e
cmpl $0x10, %eax
je 0x3a99e
cmpl $0x11, %eax
jne 0x3a825
movq %r12, %rdi
callq 0xc360
testl %eax, %eax
jne 0x3a928
movb 0x88(%r12), %al
movb %al, 0x70(%r15)
movb 0x89(%r12), %al
movb %al, 0x71(%r15)
movb 0x8a(%r12), %al
movb %al, 0x72(%r15)
jmp 0x3a825
movq %r15, %rdi
movq %r12, %rsi
callq 0xcdb0
jmp 0x3a825
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc820
jmp 0x3a825