// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_data_validation_range
lxw_error
worksheet_data_validation_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_data_validation *validation)
{
    lxw_data_val_obj *copy;
    uint8_t is_between = LXW_FALSE;
    uint8_t is_formula = LXW_FALSE;
    uint8_t has_criteria = LXW_TRUE;
    lxw_error err;
    lxw_row_t tmp_row;
    lxw_col_t tmp_col;
    size_t length;

    /* No action is required for validation type 'any' unless there are
     * input messages to display.*/
    if (validation->validate == LXW_VALIDATION_TYPE_ANY
        && !(validation->input_title || validation->input_message)) {

        return LXW_NO_ERROR;
    }

    /* Check for formula types. */
    switch (validation->validate) {
        case LXW_VALIDATION_TYPE_INTEGER_FORMULA:
        case LXW_VALIDATION_TYPE_DECIMAL_FORMULA:
        case LXW_VALIDATION_TYPE_LIST_FORMULA:
        case LXW_VALIDATION_TYPE_LENGTH_FORMULA:
        case LXW_VALIDATION_TYPE_DATE_FORMULA:
        case LXW_VALIDATION_TYPE_TIME_FORMULA:
        case LXW_VALIDATION_TYPE_CUSTOM_FORMULA:
            is_formula = LXW_TRUE;
            break;
    }

    /* Check for types without a criteria. */
    switch (validation->validate) {
        case LXW_VALIDATION_TYPE_LIST:
        case LXW_VALIDATION_TYPE_LIST_FORMULA:
        case LXW_VALIDATION_TYPE_ANY:
        case LXW_VALIDATION_TYPE_CUSTOM_FORMULA:
            has_criteria = LXW_FALSE;
            break;
    }

    /* Check that a validation parameter has been specified
     * except for 'list', 'any' and 'custom'. */
    if (has_criteria && validation->criteria == LXW_VALIDATION_CRITERIA_NONE) {

        LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                        "criteria parameter must be specified.");
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Check for "between" criteria so we can do additional checks. */
    if (has_criteria
        && (validation->criteria == LXW_VALIDATION_CRITERIA_BETWEEN
            || validation->criteria == LXW_VALIDATION_CRITERIA_NOT_BETWEEN)) {

        is_between = LXW_TRUE;
    }

    /* Check that formula values are non NULL. */
    if (is_formula) {
        if (is_between) {
            if (!validation->minimum_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "minimum_formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
            if (!validation->maximum_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "maximum_formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
        }
        else {
            if (!validation->value_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
        }
    }

    /* Check Excel limitations on input strings. */
    if (validation->input_title) {
        length = lxw_utf8_strlen(validation->input_title);
        if (length > LXW_VALIDATION_MAX_TITLE_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "input_title length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_TITLE_LENGTH);
            return LXW_ERROR_32_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->error_title) {
        length = lxw_utf8_strlen(validation->error_title);
        if (length > LXW_VALIDATION_MAX_TITLE_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "error_title length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_TITLE_LENGTH);
            return LXW_ERROR_32_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->input_message) {
        length = lxw_utf8_strlen(validation->input_message);
        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "input_message length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->error_message) {
        length = lxw_utf8_strlen(validation->error_message);
        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "error_message length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->validate == LXW_VALIDATION_TYPE_LIST) {
        length = _validation_list_length(validation->value_list);

        if (length == 0) {
            LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                            "list parameters cannot be zero.");
            return LXW_ERROR_PARAMETER_VALIDATION;
        }

        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "list length with commas > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    /* 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;

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

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

    /* Copy the parameters from the user data validation. */
    copy->validate = validation->validate;
    copy->value_number = validation->value_number;
    copy->error_type = validation->error_type;
    copy->dropdown = validation->dropdown;

    if (has_criteria)
        copy->criteria = validation->criteria;

    if (is_between) {
        copy->value_number = validation->minimum_number;
        copy->maximum_number = validation->maximum_number;
    }

    /* Copy the input/error titles and messages. */
    if (validation->input_title) {
        copy->input_title = lxw_strdup_formula(validation->input_title);
        GOTO_LABEL_ON_MEM_ERROR(copy->input_title, mem_error);
    }

    if (validation->input_message) {
        copy->input_message = lxw_strdup_formula(validation->input_message);
        GOTO_LABEL_ON_MEM_ERROR(copy->input_message, mem_error);
    }

    if (validation->error_title) {
        copy->error_title = lxw_strdup_formula(validation->error_title);
        GOTO_LABEL_ON_MEM_ERROR(copy->error_title, mem_error);
    }

    if (validation->error_message) {
        copy->error_message = lxw_strdup_formula(validation->error_message);
        GOTO_LABEL_ON_MEM_ERROR(copy->error_message, mem_error);
    }

    /* Copy the formula strings. */
    if (is_formula) {
        if (is_between) {
            copy->value_formula =
                lxw_strdup_formula(validation->minimum_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
            copy->maximum_formula =
                lxw_strdup_formula(validation->maximum_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->maximum_formula, mem_error);
        }
        else {
            copy->value_formula =
                lxw_strdup_formula(validation->value_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
        }
    }

    /* Copy the validation list as a csv string. */
    if (validation->validate == LXW_VALIDATION_TYPE_LIST) {
        copy->value_formula = _validation_list_to_csv(validation->value_list);
        GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
    }

    if (validation->validate == LXW_VALIDATION_TYPE_DATE
        || validation->validate == LXW_VALIDATION_TYPE_TIME) {
        if (is_between) {
            copy->value_number =
                lxw_datetime_to_excel_date_epoch
                (&validation->minimum_datetime, LXW_EPOCH_1900);
            copy->maximum_number =
                lxw_datetime_to_excel_date_epoch
                (&validation->maximum_datetime, LXW_EPOCH_1900);
        }
        else {
            copy->value_number =
                lxw_datetime_to_excel_date_epoch(&validation->value_datetime,
                                                 LXW_EPOCH_1900);
        }
    }

    /* These options are on by default so we can't take plain booleans. */
    copy->ignore_blank = validation->ignore_blank ^ 1;
    copy->show_input = validation->show_input ^ 1;
    copy->show_error = validation->show_error ^ 1;

    STAILQ_INSERT_TAIL(self->data_validations, copy, list_pointers);

    self->num_validations++;

    return LXW_NO_ERROR;

mem_error:
    _free_data_validation(copy);
    return LXW_ERROR_MEMORY_MALLOC_FAILED;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movl %r8d, 0x10(%rsp)
movl %ecx, %r13d
movl %edx, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, %r15
movzbl (%r9), %ecx
movb $0x1, %bpl
movb $0x1, %r12b
cmpl $0x10, %ecx
ja 0x3cdf1
movl $0xc954, %eax           # imm = 0xC954
btl %ecx, %eax
jae 0x3d0af
xorl %r12d, %r12d
cmpb $0x11, %cl
setb %al
movl $0x18060, %ebx          # imm = 0x18060
shrl %cl, %ebx
andb %al, %bl
jne 0x3ce17
movb 0x1(%r14), %al
testb %al, %al
je 0x3d1f7
cmpb $0x3, %al
setae %bpl
orb %bl, %bpl
testb $0x1, %r12b
jne 0x3ce49
testb %bpl, %bpl
je 0x3ce33
cmpq $0x0, 0x10(%r14)
jne 0x3ce49
callq 0xf6e5
jmp 0x3d227
cmpq $0x0, 0x48(%r14)
je 0x3d21b
cmpq $0x0, 0x78(%r14)
je 0x3d222
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3ce64
callq 0xd0d0
cmpq $0x21, %rax
jae 0x3d1d3
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3ce7f
callq 0xd0d0
cmpq $0x21, %rax
jae 0x3d1da
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3ce9c
callq 0xd0d0
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d1e9
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3ceb9
callq 0xd0d0
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d1f0
cmpb $0x5, (%r14)
jne 0x3cedd
movq 0x18(%r14), %rdi
callq 0xc650
testq %rax, %rax
je 0x3d1fe
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d20f
movl %r12d, 0x4(%rsp)
movb %bpl, 0x3(%rsp)
movq %r15, 0x20(%rsp)
movl 0x8(%rsp), %eax
cmpl %r13d, %eax
movl %r13d, %ebp
cmoval %eax, %ebp
movl %r13d, 0x1c(%rsp)
cmovbl %eax, %r13d
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %ecx
cmpw %r15w, %cx
movl %r15d, %eax
cmoval %ecx, %eax
cmovbl %ecx, %r15d
cmpl $0x100000, %ebp         # imm = 0x100000
setb %cl
movzwl %ax, %r12d
cmpl $0x4000, %r12d          # imm = 0x4000
setb %dl
xorl %esi, %esi
movl $0x17, %eax
testb %dl, %cl
cmovnel %esi, %eax
je 0x3d26a
movl $0x1, %edi
movl $0xc8, %esi
callq 0xc7f0
testq %rax, %rax
je 0x3d205
movl 0x8(%rsp), %ecx
cmpl %ecx, 0x1c(%rsp)
setne %dl
movl 0xc(%rsp), %ecx
cmpw %cx, 0x10(%rsp)
setne %cl
movq %rax, 0x10(%rsp)
leaq 0xa0(%rax), %rdi
orb %dl, %cl
jne 0x3cf8f
movzwl %r15w, %edx
movl %r13d, %esi
callq 0xca00
jmp 0x3cfa0
movzwl %r15w, %edx
movl %r13d, %esi
movl %ebp, %ecx
movl %r12d, %r8d
callq 0xcd10
movq 0x20(%rsp), %r15
movb 0x3(%rsp), %bpl
movl 0x4(%rsp), %r12d
movb (%r14), %al
movq 0x10(%rsp), %r13
movb %al, (%r13)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r13)
movb 0x5(%r14), %al
movb %al, 0x5(%r13)
movb 0x6(%r14), %al
movb %al, 0x6(%r13)
testb %bl, %bl
jne 0x3cfe3
movb 0x1(%r14), %al
movb %al, 0x1(%r13)
testb %bpl, %bpl
jne 0x3d000
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x8(%r13)
movsd 0x70(%r14), %xmm0
movsd %xmm0, 0x50(%r13)
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3d021
callq 0xc0e0
movq %rax, 0x80(%r13)
testq %rax, %rax
je 0x3d22e
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3d042
callq 0xc0e0
movq %rax, 0x88(%r13)
testq %rax, %rax
je 0x3d235
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3d063
callq 0xc0e0
movq %rax, 0x90(%r13)
testq %rax, %rax
je 0x3d23c
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3d084
callq 0xc0e0
movq %rax, 0x98(%r13)
testq %rax, %rax
je 0x3d243
testb $0x1, %r12b
jne 0x3d119
testb %bpl, %bpl
je 0x3d0ed
movq 0x10(%r14), %rdi
callq 0xc0e0
movq %rax, 0x10(%r13)
testq %rax, %rax
jne 0x3d119
movl $0x2a9e, %edi           # imm = 0x2A9E
jmp 0x3d25d
movb $0x1, %r12b
cmpl $0x10, %ecx
jne 0x3cdf1
cmpq $0x0, 0xa0(%r14)
jne 0x3d0d3
cmpq $0x0, 0xa8(%r14)
je 0x3d1cc
movb $0x1, %r12b
cmpb $0x10, %cl
jae 0x3cdf1
movl $0x36ab, %r12d          # imm = 0x36AB
shrl %cl, %r12d
jmp 0x3cdf1
movq 0x48(%r14), %rdi
callq 0xc0e0
movq %rax, 0x10(%r13)
testq %rax, %rax
je 0x3d251
movq 0x78(%r14), %rdi
callq 0xc0e0
movq %rax, 0x58(%r13)
testq %rax, %rax
je 0x3d258
cmpb $0x5, (%r14)
jne 0x3d135
movq 0x18(%r14), %rdi
callq 0xc6d0
movq %rax, 0x10(%r13)
testq %rax, %rax
je 0x3d24a
movzbl (%r14), %eax
cmpl $0xa, %eax
je 0x3d143
cmpl $0x7, %eax
jne 0x3d180
testb %bpl, %bpl
je 0x3d15b
leaq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
movsd %xmm0, 0x8(%r13)
jmp 0x3d180
leaq 0x50(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
movsd %xmm0, 0x8(%r13)
leaq 0x80(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
movsd %xmm0, 0x50(%r13)
movb 0x2(%r14), %al
xorb $0x1, %al
movb %al, 0x2(%r13)
movb 0x3(%r14), %al
xorb $0x1, %al
movb %al, 0x3(%r13)
movb 0x4(%r14), %al
xorb $0x1, %al
movb %al, 0x4(%r13)
movq %r13, %rax
addq $0xc0, %rax
movq $0x0, 0xc0(%r13)
movq 0x50(%r15), %rcx
movq 0x8(%rcx), %rcx
movq %r13, (%rcx)
movq 0x50(%r15), %rcx
movq %rax, 0x8(%rcx)
incb 0x150(%r15)
xorl %eax, %eax
jmp 0x3d26a
callq 0xf701
jmp 0x3d1df
callq 0xf71c
movl $0x12, %eax
jmp 0x3d26a
callq 0xf737
jmp 0x3d214
callq 0xf754
jmp 0x3d214
callq 0xf691
jmp 0x3d227
callq 0xf7bc
jmp 0x3d227
movl $0x2a65, %edi           # imm = 0x2A65
movq %rax, %r13
jmp 0x3d25d
callq 0xf79f
movl $0x14, %eax
jmp 0x3d26a
callq 0xf6c9
jmp 0x3d227
callq 0xf6ad
movl $0xd, %eax
jmp 0x3d26a
movl $0x2a7f, %edi           # imm = 0x2A7F
jmp 0x3d25d
movl $0x2a84, %edi           # imm = 0x2A84
jmp 0x3d25d
movl $0x2a89, %edi           # imm = 0x2A89
jmp 0x3d25d
movl $0x2a8e, %edi           # imm = 0x2A8E
jmp 0x3d25d
movl $0x2aa5, %edi           # imm = 0x2AA5
jmp 0x3d25d
movl $0x2a96, %edi           # imm = 0x2A96
jmp 0x3d25d
movl $0x2a99, %edi           # imm = 0x2A99
movq %r13, %rsi
callq 0xf771
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq