// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rcx, %r13
movl %edx, %r12d
movl %esi, %ebp
movq %rdi, %r14
andq $0x0, (%rsp)
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x36a6c
testl %eax, %eax
jne 0x37af8
pushq $0xd
popq %rax
xorl %edx, %edx
movl %edx, %ecx
movzbl %dl, %edx
movq (%r13,%rdx,8), %rdx
testq %rdx, %rdx
je 0x378cd
movq 0x8(%rdx), %rsi
testq %rsi, %rsi
je 0x378c5
leal 0x1(%rcx), %edx
cmpb $0x0, (%rsi)
jne 0x378a5
incb %cl
movl %eax, %ebx
movl %ecx, %edx
jmp 0x378a5
incb %cl
cmpb $0x3, %cl
pushq $0xd
popq %rax
cmovbl %eax, %ebx
movl %ebx, %eax
testl %ebx, %ebx
jne 0x37af8
movl %r12d, 0xc(%rsp)
movq 0xc8(%r14), %rdx
movq %rsp, %rdi
xorl %esi, %esi
callq 0xce80
testq %rax, %rax
je 0x37a25
movq %rax, %r12
movq %r15, 0x10(%rsp)
callq 0xc750
movq %rax, %r15
testq %rax, %rax
je 0x37b1f
movq %r12, (%r15)
callq 0xcdc0
testq %rax, %rax
je 0x37b26
movq %rax, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movl %ebp, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x6937(%rip), %r14      # 0x3e279
movzbl %bpl, %eax
movq (%r13,%rax,8), %rbx
testq %rbx, %rbx
je 0x37994
incb %bpl
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xc380
movq (%rbx), %rsi
testq %rsi, %rsi
jne 0x37973
movq 0x20(%rsp), %rsi
cmpb $0x2, %bpl
jb 0x3797b
movq %r15, %rdi
callq 0xca30
movq 0x8(%rbx), %rsi
movq %r15, %rdi
callq 0xc7e0
movq %r12, %rdi
movq %r14, %rsi
callq 0xc060
jmp 0x37942
movq %r15, %rdi
callq 0xc5e0
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xd050
movq %r12, %rdi
callq 0xcac0
cmpq $0x0, (%rsp)
jne 0x379ff
movq %r12, %rdi
callq 0xc8e0
movq %rax, %r14
leaq 0x1(%rax), %rdi
pushq $0x1
popq %rsi
callq 0xc850
movq %rax, (%rsp)
testq %rax, %rax
je 0x37b72
movq %r12, %rdi
callq 0xc540
movq (%rsp), %rdi
pushq $0x1
popq %rdx
movq %r14, %rsi
movq %r12, %rcx
callq 0xc310
testq %rax, %rax
je 0x37b07
movq %r12, %rdi
callq 0xc450
movq (%rsp), %rdi
callq 0xd150
cmpq $0x8000, %rax           # imm = 0x8000
jb 0x37a2d
movq (%rsp), %rdi
callq 0xc0d0
pushq $0x15
jmp 0x37a27
pushq $0x3
popq %rax
jmp 0x37af8
movq 0x18(%rsp), %rax
cmpb $0x0, 0x11c(%rax)
movl 0xc(%rsp), %r12d
movzwl %r12w, %ebx
je 0x37aa1
movq (%rsp), %rdi
callq 0xc980
movq (%rsp), %r14
testb %al, %al
je 0x37a69
movq %r14, %rdi
callq 0xca00
movq %rax, %r14
movq (%rsp), %rdi
callq 0xc0d0
pushq $0x1
popq %rdi
pushq $0x68
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x37b79
movq %rax, %r15
movl 0x8(%rsp), %ebp
movl %ebp, (%rax)
movw %r12w, 0x4(%rax)
movl $0x4, 0x8(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r15)
movq %r14, 0x20(%r15)
jmp 0x37ae5
movq 0xb0(%rax), %rdi
movq (%rsp), %rsi
pushq $0x1
popq %rdx
callq 0xc370
movq %rax, %r14
movq (%rsp), %rdi
callq 0xc0d0
testq %r14, %r14
movq 0x10(%rsp), %r8
je 0x37b6b
movl (%r14), %edx
movq 0x8(%r14), %rcx
movl 0x8(%rsp), %ebp
movl %ebp, %edi
movl %ebx, %esi
callq 0x36c24
movq %rax, %r15
movq 0x18(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
movq %r15, %rcx
callq 0x36b65
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0xc450
movq (%rsp), %rdi
callq 0xc0d0
pushq $0x4
jmp 0x37a27
movl $0x210c, %ecx           # imm = 0x210C
jmp 0x37b2b
movl $0x2111, %ecx           # imm = 0x2111
xorl %ebx, %ebx
movq 0x1b4c4(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x55a2(%rip), %rsi      # 0x3d0e0
leaq 0xbe9b(%rip), %rdx      # 0x439e0
xorl %eax, %eax
callq 0xc8d0
movq %r15, %rdi
callq 0xc5e0
movq %rbx, %rdi
callq 0xd050
movq %r12, %rdi
callq 0xc450
pushq $0x1
jmp 0x37a27
pushq $0x16
jmp 0x37a27
movl $0x2132, %ecx           # imm = 0x2132
jmp 0x37b2d
movq 0x1b478(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5556(%rip), %rsi      # 0x3d0e0
leaq 0xbe4f(%rip), %rdx      # 0x439e0
xorl %r15d, %r15d
movl $0x387, %ecx            # imm = 0x387
xorl %eax, %eax
callq 0xc8d0
movl 0x8(%rsp), %ebp
jmp 0x37ae5