// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %r8, %r15
movq %rcx, %r13
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movq $0x0, (%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x39d04
testl %eax, %eax
je 0x3a9d9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rsi
movl $0xd, %eax
testq %rsi, %rsi
je 0x3a9ca
xorl %ecx, %ecx
movb $0x1, %dl
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x3a9f9
cmpb $0x0, (%rsi)
jne 0x3a9fe
movl $0xd, %ecx
movzbl %dl, %esi
incb %dl
movq (%r13,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x3a9eb
cmpb $0x3, %dl
jb 0x3a9ca
movl %ecx, %eax
testl %ecx, %ecx
jne 0x3a9ca
movq 0xc8(%r14), %rdx
movq %rsp, %rdi
xorl %esi, %esi
callq 0xce00
testq %rax, %rax
je 0x3ab87
movq %rax, %r12
movq %r15, 0x20(%rsp)
callq 0xc6f0
testq %rax, %rax
movq %rax, 0x10(%rsp)
je 0x3ac6f
movq %r12, (%rax)
callq 0xcd40
testq %rax, %rax
je 0x3ac76
movl %ebp, 0x1c(%rsp)
movq %rax, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movl %ebx, 0xc(%rsp)
movq (%r13), %rbx
testq %rbx, %rbx
je 0x3aae1
movb $0x1, %r14b
leaq 0x67f6(%rip), %rsi      # 0x41279
movq %r12, %r15
movq %r12, %rdi
movq %rsi, %rbp
xorl %edx, %edx
callq 0xc350
movq (%rbx), %rsi
testq %rsi, %rsi
movq 0x10(%rsp), %r12
jne 0x3aaab
movq 0x28(%rsp), %rsi
cmpb $0x2, %r14b
jb 0x3aab3
movq %r12, %rdi
callq 0xc9d0
movq 0x8(%rbx), %rsi
movq %r12, %rdi
callq 0xc780
movq %r15, %r12
movq %r15, %rdi
movq %rbp, %rsi
callq 0xc060
movq %rbp, %rsi
movzbl %r14b, %eax
incb %r14b
movq (%r13,%rax,8), %rbx
testq %rbx, %rbx
jne 0x3aa83
movq 0x10(%rsp), %rdi
callq 0xc5a0
movq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0xcfd0
movq %r12, %rdi
callq 0xca60
cmpq $0x0, (%rsp)
movq 0x30(%rsp), %r14
movl 0x1c(%rsp), %ebp
jne 0x3ab5b
movq %r12, %rdi
callq 0xc880
movq %rax, %rbx
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0xc7f0
movq %rax, (%rsp)
testq %rax, %rax
je 0x3aca2
movq %r12, %rdi
callq 0xc500
movq (%rsp), %rdi
movl $0x1, %edx
movq %rbx, %rsi
movq %r12, %rcx
callq 0xc2f0
testq %rax, %rax
je 0x3ac54
movq %r12, %rdi
callq 0xc420
movq (%rsp), %rdi
callq 0xd0d0
cmpq $0x8000, %rax           # imm = 0x8000
jb 0x3ab91
movq (%rsp), %rdi
callq 0xc0c0
movl $0x15, %eax
jmp 0x3a9ca
movl $0x3, %eax
jmp 0x3a9ca
cmpb $0x0, 0x11c(%r14)
movzwl %bp, %r15d
je 0x3abfe
movq (%rsp), %rdi
callq 0xc920
movq (%rsp), %rbx
testb %al, %al
je 0x3abc4
movq %rbx, %rdi
callq 0xc9a0
movq %rax, %rbx
movq (%rsp), %rdi
callq 0xc0c0
movl $0x1, %edi
movl $0x68, %esi
callq 0xc7f0
testq %rax, %rax
je 0x3aca9
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movw %bp, 0x4(%rax)
movl $0x4, 0x8(%rax)
movq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rax)
movq %rbx, 0x20(%rax)
movl %ecx, %ebx
jmp 0x3ac3d
movq 0xb0(%r14), %rdi
movq (%rsp), %rsi
movl $0x1, %edx
callq 0xc340
movq %rax, %rbx
movq (%rsp), %rdi
callq 0xc0c0
testq %rbx, %rbx
je 0x3ac98
movl (%rbx), %edx
movq 0x8(%rbx), %rcx
movl 0xc(%rsp), %ebx
movl %ebx, %edi
movl %r15d, %esi
movq 0x20(%rsp), %r8
callq 0x39ea7
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
movq %rax, %rcx
callq 0x39de8
xorl %eax, %eax
jmp 0x3a9ca
movq %r12, %rdi
callq 0xc420
movq (%rsp), %rdi
callq 0xc0c0
movl $0x4, %eax
jmp 0x3a9ca
movl $0x210c, %edi           # imm = 0x210C
jmp 0x3ac7b
movl $0x2111, %edi           # imm = 0x2111
xorl %r15d, %r15d
movq 0x10(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf53c
movl $0x1, %eax
jmp 0x3a9ca
movl $0x16, %eax
jmp 0x3a9ca
movl $0x2132, %edi           # imm = 0x2132
jmp 0x3ac7e
callq 0xf512
xorl %eax, %eax
movl 0xc(%rsp), %ebx
jmp 0x3ac3d