// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movl %ecx, %r13d
movl %edx, %r14d
movl %esi, %r12d
cmpl %ecx, %esi
movl %ecx, %r8d
cmoval %esi, %r8d
movl %ecx, %eax
cmovbl %esi, %eax
movl %eax, 0x8(%rsp)
cmpw %bx, %r14w
movl %ebx, %ebp
cmoval %edx, %ebp
movl %ebx, %r15d
cmovbl %edx, %r15d
cmpl $0x100000, %r8d         # imm = 0x100000
setb %sil
cmpl $0x4000, %ebp           # imm = 0x4000
setb %cl
xorl %edx, %edx
movl $0x17, %eax
testb %cl, %sil
cmovnel %edx, %eax
je 0x3d467
movq %r9, 0x10(%rsp)
movzbl (%r9), %edx
leal -0x12(%rdx), %eax
cmpb $-0x12, %al
jbe 0x3d49d
movl %r8d, 0xc(%rsp)
movq %rdi, (%rsp)
movl $0x1, %edi
movl $0x8c8, %esi            # imm = 0x8C8
callq 0xc7f0
testq %rax, %rax
je 0x3d4bc
cmpl %r12d, %r13d
setne %dl
cmpw %r14w, %bx
setne %cl
leaq 0x9e(%rax), %rbx
orb %dl, %cl
movzwl %r15w, %r14d
movq %rax, %r15
jne 0x3d350
movq %rbx, %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
movl %r14d, %edx
callq 0xca00
jmp 0x3d369
movzwl %bp, %r8d
movq %rbx, %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
movl %r14d, %edx
movl 0xc(%rsp), %ecx
callq 0xcd10
movq 0x10(%rsp), %r12
movq %r15, %rdi
addq $0x90, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0xca00
movq 0x90(%r12), %r14
testq %r14, %r14
je 0x3d3bb
movq %r14, %rdi
callq 0xc480
cmpq $0x820, %rax            # imm = 0x820
jae 0x3d53a
movl $0x81f, %edx            # imm = 0x81F
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc170
movb $0x0, 0x8bd(%r15)
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x3d3cc
callq 0xcb20
jmp 0x3d3d1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
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 0x93ac(%rip), %rcx      # 0x467a8
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0xcce0
movq %rax, 0x78(%r15)
movzbl (%r12), %ecx
cmpl $0x1, %ecx
je 0x3d422
movzbl (%r15), %eax
leal -0x5(%rax), %edx
cmpb $0x1, %dl
ja 0x3d476
movq %r15, %rdi
movq %r12, %rsi
callq 0xc690
movq (%rsp), %rdi
movl 0x2e8(%rdi), %eax
incl %eax
movl %eax, 0x2e8(%rdi)
movl %eax, 0x8c(%r15)
movq %r15, %rsi
callq 0xc0b0
movl $0x1, %ecx
testl %eax, %eax
je 0x3d465
movq %r15, %rdi
movl %ecx, %ebx
callq 0x2fb16
movl %ebx, %eax
jmp 0x3d467
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %ecx
je 0x3d4ee
cmpl $0x3, %ecx
movq (%rsp), %rdi
je 0x3d4c8
cmpl $0x2, %ecx
jne 0x3d514
movq %r15, %rdi
movq %r12, %rsi
callq 0xced0
jmp 0x3d527
movq 0x18b54(%rip), %rax     # 0x55ff8
movq (%rax), %rdi
leaq 0xaed7(%rip), %rsi      # 0x48385
xorl %eax, %eax
callq 0xc870
movl $0xd, %eax
jmp 0x3d467
movq %rax, %r15
callq 0xf7f5
xorl %ecx, %ecx
jmp 0x3d457
movzbl 0x1(%r12), %edx
leal -0xd(%rdx), %ebx
xorl %ecx, %ecx
cmpb $0xa, %bl
jb 0x3d506
movq 0x18b19(%rip), %rax     # 0x55ff8
movq (%rax), %rdi
leaq 0x9d3a(%rip), %rsi      # 0x47223
jmp 0x3d5eb
movzbl 0x1(%r12), %edx
leal -0x17(%rdx), %ebx
xorl %ecx, %ecx
cmpb $0xa, %bl
movq (%rsp), %rdi
jae 0x3d5da
cmpb $0xa, %bl
jb 0x3d431
jmp 0x3d457
leal -0x7(%rax), %edx
cmpb $0x1, %dl
ja 0x3d549
movq %r15, %rdi
movq %r12, %rsi
callq 0xcde0
movq (%rsp), %rdi
testl %eax, %eax
je 0x3d431
movl %eax, %ecx
jmp 0x3d457
callq 0xf7d8
movl $0xd, %ecx
jmp 0x3d457
cmpl $0xd, %ecx
jne 0x3d566
movq %r15, %rdi
movq %r12, %rsi
callq 0xc910
testl %eax, %eax
movq (%rsp), %rdi
jne 0x3d533
jmp 0x3d431
leal -0xe(%rax), %ecx
cmpl $0x2, %ecx
jb 0x3d5ca
cmpl $0x10, %eax
je 0x3d600
cmpl $0x11, %eax
movq (%rsp), %rdi
jne 0x3d431
movzbl 0x88(%r12), %ebx
xorl %ecx, %ecx
cmpl $0x11, %ebx
jae 0x3d61a
cmpb $0x10, %bl
ja 0x3d457
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 0x3d431
movq %r15, %rdi
movq %r12, %rsi
callq 0xcd30
jmp 0x3d42d
movq 0x18a17(%rip), %rax     # 0x55ff8
movq (%rax), %rdi
leaq 0x9bb8(%rip), %rsi      # 0x471a3
xorl %eax, %eax
callq 0xc870
movq (%rsp), %rdi
movl $0xd, %ecx
jmp 0x3d506
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xc7c0
movq %rbx, %rdi
jmp 0x3d431
movq 0x189d7(%rip), %rax     # 0x55ff8
movq (%rax), %rdi
leaq 0x99cf(%rip), %rsi      # 0x46ffa
movl %ebx, %edx
xorl %eax, %eax
callq 0xc870
movq (%rsp), %rdi
movl $0xd, %ecx
jmp 0x3d598