// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_write_rich_string
lxw_error
worksheet_write_rich_string(lxw_worksheet *self,
                            lxw_row_t row_num,
                            lxw_col_t col_num,
                            lxw_rich_string_tuple *rich_strings[],
                            lxw_format *format)
{
    lxw_cell *cell;
    int32_t string_id;
    struct sst_element *sst_element;
    lxw_error err;
    uint8_t i;
    long file_size;
    char *rich_string = NULL;
    const char *string_copy = NULL;
    lxw_styles *styles = NULL;
    lxw_format *default_format = NULL;
    lxw_rich_string_tuple *rich_string_tuple = NULL;
    FILE *tmpfile;

    err = _check_dimensions(self, row_num, col_num, LXW_FALSE, LXW_FALSE);
    if (err)
        return err;

    /* Iterate through rich string fragments to check for input errors. */
    i = 0;
    err = LXW_NO_ERROR;
    while ((rich_string_tuple = rich_strings[i++]) != NULL) {

        /* Check for NULL or empty strings. */
        if (!rich_string_tuple->string || !*rich_string_tuple->string) {
            err = LXW_ERROR_PARAMETER_VALIDATION;
        }
    }

    /* If there are less than 2 fragments it isn't a rich string. */
    if (i <= 2)
        err = LXW_ERROR_PARAMETER_VALIDATION;

    if (err)
        return err;

    /* Create a tmp file for the styles object. */
    tmpfile = lxw_get_filehandle(&rich_string, NULL, self->tmpdir);
    if (!tmpfile)
        return LXW_ERROR_CREATING_TMPFILE;

    /* Create a temp styles object for writing the font data. */
    styles = lxw_styles_new();
    GOTO_LABEL_ON_MEM_ERROR(styles, mem_error);
    styles->file = tmpfile;

    /* Create a default format for non-formatted text. */
    default_format = lxw_format_new();
    GOTO_LABEL_ON_MEM_ERROR(default_format, mem_error);

    /* Iterate through the rich string fragments and write each one out. */
    i = 0;
    while ((rich_string_tuple = rich_strings[i++]) != NULL) {
        lxw_xml_start_tag(tmpfile, "r", NULL);

        if (rich_string_tuple->format) {
            /* Write the user defined font format. */
            lxw_styles_write_rich_font(styles, rich_string_tuple->format);
        }
        else {
            /* Write a default font format. Except for the first fragment. */
            if (i > 1)
                lxw_styles_write_rich_font(styles, default_format);
        }

        lxw_styles_write_string_fragment(styles, rich_string_tuple->string);
        lxw_xml_end_tag(tmpfile, "r");
    }

    /* Free the temp objects. */
    lxw_styles_free(styles);
    lxw_format_free(default_format);

    /* Flush the file. */
    fflush(tmpfile);

    if (!rich_string) {
        /* Read the size to calculate the required memory. */
        file_size = ftell(tmpfile);
        /* Allocate a buffer for the rich string xml data. */
        rich_string = calloc(file_size + 1, 1);
        GOTO_LABEL_ON_MEM_ERROR(rich_string, mem_error);

        /* Rewind the file and read the data into the memory buffer. */
        rewind(tmpfile);
        if (fread((void *) rich_string, file_size, 1, tmpfile) < 1) {
            fclose(tmpfile);
            free((void *) rich_string);
            return LXW_ERROR_READING_TMPFILE;
        }
    }

    /* Close the temp file. */
    fclose(tmpfile);

    if (lxw_utf8_strlen(rich_string) > LXW_STR_MAX) {
        free((void *) rich_string);
        return LXW_ERROR_MAX_STRING_LENGTH_EXCEEDED;
    }

    if (!self->optimize) {
        /* Get the SST element and string id. */
        sst_element = lxw_get_sst_index(self->sst, rich_string, LXW_TRUE);
        free((void *) rich_string);

        if (!sst_element)
            return LXW_ERROR_SHARED_STRING_INDEX_NOT_FOUND;

        string_id = sst_element->index;
        cell = _new_string_cell(row_num, col_num, string_id,
                                sst_element->string, format);
    }
    else {
        /* Look for and escape control chars in the string. */
        if (lxw_has_control_characters(rich_string)) {
            string_copy = lxw_escape_control_characters(rich_string);
            free((void *) rich_string);
        }
        else {
            string_copy = rich_string;
        }
        cell = _new_inline_rich_string_cell(row_num, col_num, string_copy,
                                            format);
    }

    _insert_cell(self, row_num, col_num, cell);

    return LXW_NO_ERROR;

mem_error:
    lxw_styles_free(styles);
    lxw_format_free(default_format);
    fclose(tmpfile);

    return LXW_ERROR_MEMORY_MALLOC_FAILED;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbp
movq %rcx, %r12
movl %edx, %r15d
movl %esi, %ebx
movq %rdi, %r14
movq $0x0, (%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x39aa6
testl %eax, %eax
jne 0x3a718
movq (%r12), %rdx
testq %rdx, %rdx
je 0x3a70f
xorl %eax, %eax
movb $0x1, %cl
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x3a6ef
cmpb $0x0, (%rdx)
jne 0x3a6f4
movl $0xd, %eax
movzbl %cl, %edx
incb %cl
movq (%r12,%rdx,8), %rdx
testq %rdx, %rdx
jne 0x3a6e1
cmpb $0x3, %cl
movl $0xd, %ecx
cmovbl %ecx, %eax
jmp 0x3a714
movl $0xd, %eax
testl %eax, %eax
je 0x3a727
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc8(%r14), %rdx
movq %rsp, %rdi
xorl %esi, %esi
callq 0xce00
testq %rax, %rax
je 0x3a881
movq %rax, %r13
movl %r15d, 0xc(%rsp)
movl %ebx, 0x8(%rsp)
callq 0xc6f0
movq %rax, %r15
testq %rax, %rax
je 0x3a979
movq %r13, (%r15)
callq 0xcd40
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x3a980
movq %rbp, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movq (%r12), %rbp
testq %rbp, %rbp
je 0x3a7e1
movb $0x1, %r14b
leaq 0x6af0(%rip), %rbx      # 0x41281
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xc350
movq (%rbp), %rsi
testq %rsi, %rsi
jne 0x3a7b2
movq 0x18(%rsp), %rsi
cmpb $0x2, %r14b
jb 0x3a7ba
movq %r15, %rdi
callq 0xc9d0
movq 0x8(%rbp), %rsi
movq %r15, %rdi
callq 0xc780
movq %r13, %rdi
movq %rbx, %rsi
callq 0xc060
movzbl %r14b, %eax
incb %r14b
movq (%r12,%rax,8), %rbp
testq %rbp, %rbp
jne 0x3a791
movq %r15, %rdi
callq 0xc5a0
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0xcfd0
movq %r13, %rdi
callq 0xca60
cmpq $0x0, (%rsp)
movq 0x20(%rsp), %r14
jne 0x3a855
movq %r13, %rdi
callq 0xc880
movq %rax, %rbx
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0xc7f0
movq %rax, (%rsp)
testq %rax, %rax
je 0x3a9aa
movq %r13, %rdi
callq 0xc500
movq (%rsp), %rdi
movl $0x1, %edx
movq %rbx, %rsi
movq %r13, %rcx
callq 0xc2f0
testq %rax, %rax
je 0x3a95e
movq %r13, %rdi
callq 0xc420
movq (%rsp), %rdi
callq 0xd0d0
cmpq $0x8000, %rax           # imm = 0x8000
jb 0x3a88b
movq (%rsp), %rdi
callq 0xc0c0
movl $0x15, %eax
jmp 0x3a718
movl $0x3, %eax
jmp 0x3a718
cmpb $0x0, 0x11c(%r14)
movzwl 0xc(%rsp), %ebx
je 0x3a906
movq (%rsp), %rdi
callq 0xc920
movq (%rsp), %r15
testb %al, %al
je 0x3a8bf
movq %r15, %rdi
callq 0xc9a0
movq %rax, %r15
movq (%rsp), %rdi
callq 0xc0c0
movl $0x1, %edi
movl $0x68, %esi
callq 0xc7f0
movq %rax, %r12
testq %rax, %rax
je 0x3a9b1
movl 0x8(%rsp), %ebp
movl %ebp, (%r12)
movl 0xc(%rsp), %eax
movw %ax, 0x4(%r12)
movl $0x4, 0x8(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r12)
movq %r15, 0x20(%r12)
jmp 0x3a948
movq 0xb0(%r14), %rdi
movq (%rsp), %rsi
movl $0x1, %edx
callq 0xc340
movq %rax, %r15
movq (%rsp), %rdi
callq 0xc0c0
testq %r15, %r15
je 0x3a9a0
movl (%r15), %edx
movq 0x8(%r15), %rcx
movl 0x8(%rsp), %ebp
movl %ebp, %edi
movl %ebx, %esi
movq 0x10(%rsp), %r8
callq 0x39c49
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
movq %r12, %rcx
callq 0x39b8a
xorl %eax, %eax
jmp 0x3a718
movq %r13, %rdi
callq 0xc420
movq (%rsp), %rdi
callq 0xc0c0
movl $0x4, %eax
jmp 0x3a718
movl $0x210c, %edi           # imm = 0x210C
jmp 0x3a985
movl $0x2111, %edi           # imm = 0x2111
xorl %r12d, %r12d
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xf187
movl $0x1, %eax
jmp 0x3a718
movl $0x16, %eax
jmp 0x3a718
movl $0x2132, %edi           # imm = 0x2132
jmp 0x3a988
callq 0xf15d
movl 0x8(%rsp), %ebp
jmp 0x3a948