// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_write_url_opt
lxw_error
worksheet_write_url_opt(lxw_worksheet *self,
                        lxw_row_t row_num,
                        lxw_col_t col_num, const char *url,
                        lxw_format *user_format, const char *string,
                        const char *tooltip)
{
    lxw_cell *link;
    char *string_copy = NULL;
    char *url_copy = NULL;
    char *url_external = NULL;
    char *url_string = NULL;
    char *tooltip_copy = NULL;
    char *found_string;
    char *tmp_string = NULL;
    lxw_format *format = NULL;
    size_t string_size;
    size_t i;
    lxw_error err = LXW_ERROR_MEMORY_MALLOC_FAILED;
    enum cell_types link_type = HYPERLINK_URL;

    if (!url || !*url)
        return LXW_ERROR_NULL_PARAMETER_IGNORED;

    /* Check the Excel limit of URLS per worksheet. */
    if (self->hlink_count > LXW_MAX_NUMBER_URLS) {
        LXW_WARN("worksheet_write_url()/_opt(): URL ignored since it exceeds "
                 "the maximum number of allowed worksheet URLs (65530).");
        return LXW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED;
    }

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

    /* Reset default error condition. */
    err = LXW_ERROR_MEMORY_MALLOC_FAILED;

    /* Set the URI scheme from internal links. */
    found_string = strstr(url, "internal:");
    if (found_string)
        link_type = HYPERLINK_INTERNAL;

    /* Set the URI scheme from external links. */
    found_string = strstr(url, "external:");
    if (found_string)
        link_type = HYPERLINK_EXTERNAL;

    if (string) {
        string_copy = lxw_strdup(string);
        GOTO_LABEL_ON_MEM_ERROR(string_copy, mem_error);
    }
    else {
        if (link_type == HYPERLINK_URL) {
            /* Strip the mailto header. */
            found_string = strstr(url, "mailto:");
            if (found_string)
                string_copy = lxw_strdup(url + sizeof("mailto"));
            else
                string_copy = lxw_strdup(url);
        }
        else {
            string_copy = lxw_strdup(url + sizeof("__ternal"));
        }
        GOTO_LABEL_ON_MEM_ERROR(string_copy, mem_error);
    }

    if (url) {
        if (link_type == HYPERLINK_URL)
            url_copy = lxw_strdup(url);
        else
            url_copy = lxw_strdup(url + sizeof("__ternal"));

        GOTO_LABEL_ON_MEM_ERROR(url_copy, mem_error);
    }

    if (tooltip) {
        tooltip_copy = lxw_strdup(tooltip);
        GOTO_LABEL_ON_MEM_ERROR(tooltip_copy, mem_error);
    }

    if (link_type == HYPERLINK_INTERNAL) {
        url_string = lxw_strdup(string_copy);
        GOTO_LABEL_ON_MEM_ERROR(url_string, mem_error);
    }

    /* Split url into the link and optional anchor/location. */
    found_string = strchr(url_copy, '#');

    if (found_string) {
        free(url_string);
        url_string = lxw_strdup(found_string + 1);
        GOTO_LABEL_ON_MEM_ERROR(url_string, mem_error);

        *found_string = '\0';
    }

    /* Escape the URL. */
    if (link_type == HYPERLINK_URL || link_type == HYPERLINK_EXTERNAL) {
        tmp_string = lxw_escape_url_characters(url_copy, LXW_FALSE);
        GOTO_LABEL_ON_MEM_ERROR(tmp_string, mem_error);

        free(url_copy);
        url_copy = tmp_string;
    }

    if (link_type == HYPERLINK_EXTERNAL) {
        /* External Workbook links need to be modified into the right format.
         * The URL will look something like "c:\temp\file.xlsx#Sheet!A1". */

        /* For external links change the dir separator from Unix to DOS. */
        for (i = 0; i <= strlen(url_copy); i++)
            if (url_copy[i] == '/')
                url_copy[i] = '\\';

        for (i = 0; i <= strlen(string_copy); i++)
            if (string_copy[i] == '/')
                string_copy[i] = '\\';

        /* Look for Windows style "C:/" link or Windows share "\\" link. */
        found_string = strchr(url_copy, ':');
        if (!found_string)
            found_string = strstr(url_copy, "\\\\");

        if (found_string) {
            /* Add the file:/// URI to the url if non-local. */
            string_size = sizeof("file:///") + strlen(url_copy);
            url_external = calloc(1, string_size);
            GOTO_LABEL_ON_MEM_ERROR(url_external, mem_error);

            lxw_snprintf(url_external, string_size, "file:///%s", url_copy);

        }

        /* Convert a ./dir/file.xlsx link to dir/file.xlsx. */
        found_string = strstr(url_copy, ".\\");
        if (found_string == url_copy)
            memmove(url_copy, url_copy + 2, strlen(url_copy) - 1);

        if (url_external) {
            free(url_copy);
            url_copy = lxw_strdup(url_external);
            GOTO_LABEL_ON_MEM_ERROR(url_copy, mem_error);

            free(url_external);
            url_external = NULL;
        }

    }

    /* Check if URL exceeds Excel's length limit. */
    if (lxw_utf8_strlen(url_copy) > self->max_url_length) {
        LXW_WARN_FORMAT2("worksheet_write_url()/_opt(): URL exceeds "
                         "Excel's allowable length of %d characters: %s",
                         self->max_url_length, url_copy);
        err = LXW_ERROR_WORKSHEET_MAX_URL_LENGTH_EXCEEDED;
        goto mem_error;
    }

    /* Use the default URL format if none is specified. */
    if (!user_format)
        format = self->default_url_format;
    else
        format = user_format;

    err = worksheet_write_string(self, row_num, col_num, string_copy, format);
    if (err)
        goto mem_error;

    /* Reset default error condition. */
    err = LXW_ERROR_MEMORY_MALLOC_FAILED;

    link = _new_hyperlink_cell(row_num, col_num, link_type, url_copy,
                               url_string, tooltip_copy);
    GOTO_LABEL_ON_MEM_ERROR(link, mem_error);

    _insert_hyperlink(self, row_num, col_num, link);

    free(string_copy);
    self->hlink_count++;
    return LXW_NO_ERROR;

mem_error:
    free(string_copy);
    free(url_copy);
    free(url_external);
    free(url_string);
    free(tooltip_copy);
    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
pushq $0xc
popq %r15
testq %rcx, %rcx
je 0x37849
movq %rcx, %r14
cmpb $0x0, (%rcx)
je 0x37849
movq %rdi, %r12
cmpw $-0x5, 0x12e(%rdi)
jae 0x37648
movq %r9, %rbx
movq %r8, %rbp
movzwl %dx, %r13d
movq %r12, %rdi
movl %esi, 0x10(%rsp)
movl 0x10(%rsp), %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x36a6c
movl %eax, %r15d
testl %eax, %eax
jne 0x37849
movl %r13d, 0x14(%rsp)
leaq 0xcc1b(%rip), %rsi      # 0x43ede
movq %r14, %rdi
callq 0xd100
movq %rax, %r15
cmpq $0x1, %rax
pushq $0xc
popq %r13
sbbl $0x0, %r13d
leaq 0xcc07(%rip), %rsi      # 0x43ee8
movq %r14, %rdi
callq 0xd100
testq %rax, %rax
pushq $0xd
popq %rcx
cmovel %r13d, %ecx
movl %ecx, %r13d
testq %rbx, %rbx
movq %rax, 0x18(%rsp)
je 0x37387
movq %rbx, %rdi
callq 0xcd50
testq %rax, %rax
je 0x376c9
movq %rax, %rbx
orq 0x18(%rsp), %r15
je 0x37323
addq $0x9, %r14
movq %r14, %rdi
callq 0xcd50
testq %rax, %rax
je 0x37675
movq %rax, %r14
movq %rbp, 0x20(%rsp)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x373b2
callq 0xcd50
movq %rax, 0x8(%rsp)
testq %rax, %rax
movl %r13d, %ebp
jne 0x373be
movq 0x1bc99(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5d77(%rip), %rsi      # 0x3d0e0
leaq 0xc670(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x2056, %ecx           # imm = 0x2056
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
jmp 0x37796
orq %rax, %r15
sete %r15b
jne 0x37623
leaq 0xd29f(%rip), %rsi      # 0x4463a
movq %r14, %rdi
callq 0xd100
testq %rax, %rax
pushq $0x7
popq %rdi
cmoveq %rax, %rdi
jmp 0x37626
movq $0x0, 0x8(%rsp)
movl %r13d, %ebp
cmpl $0xc, %ebp
jne 0x373f8
movq %rbx, %rdi
callq 0xcd50
movq %rax, (%rsp)
testq %rax, %rax
jne 0x37400
movq 0x1bc1d(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5cfb(%rip), %rsi      # 0x3d0e0
leaq 0xc5f4(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x205b, %ecx           # imm = 0x205B
jmp 0x37730
movq $0x0, (%rsp)
pushq $0x23
popq %rsi
movq %r14, %rdi
callq 0xc500
testq %rax, %rax
je 0x37436
movq %rax, %r15
movq (%rsp), %rdi
callq 0xc0d0
leaq 0x1(%r15), %rdi
callq 0xcd50
movq %rax, (%rsp)
testq %rax, %rax
je 0x37711
movb $0x0, (%r15)
cmpl $0xd, %ebp
je 0x37440
cmpl $0xb, %ebp
jne 0x37461
movq %r14, %rdi
xorl %esi, %esi
callq 0xcfe0
testq %rax, %rax
je 0x376ed
movq %rax, %r15
movq %r14, %rdi
callq 0xc0d0
movq %r15, %r14
cmpq $0x0, 0x18(%rsp)
je 0x37565
xorl %r15d, %r15d
movq %r14, %rdi
callq 0xc4c0
cmpq %rax, %r15
ja 0x3748e
cmpb $0x2f, (%r14,%r15)
jne 0x37489
movb $0x5c, (%r14,%r15)
incq %r15
jmp 0x37470
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0xc4c0
cmpq %rax, %r15
ja 0x374af
cmpb $0x2f, (%rbx,%r15)
jne 0x374aa
movb $0x5c, (%rbx,%r15)
incq %r15
jmp 0x37491
pushq $0x3a
popq %rsi
movq %r14, %rdi
callq 0xc500
testq %rax, %rax
jne 0x374d7
leaq 0xca35(%rip), %rsi      # 0x43efb
movq %r14, %rdi
callq 0xd100
testq %rax, %rax
je 0x3766d
movq %r14, %rdi
callq 0xc4c0
movq %rax, %r15
addq $0x9, %r15
pushq $0x1
popq %rdi
movq %r15, %rsi
callq 0xc850
testq %rax, %rax
je 0x37743
movq %rax, %r13
leaq 0xd13e(%rip), %rdx      # 0x44642
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0xc5b0
cmpb $0x2e, (%r14)
jne 0x3753c
cmpb $0x5c, 0x1(%r14)
jne 0x3753c
leaq 0x2(%r14), %r15
movq %r14, %rdi
callq 0xc4c0
leaq -0x1(%rax), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0xcd40
testq %r13, %r13
je 0x37565
movq %r14, %rdi
callq 0xc0d0
movq %r13, %rdi
callq 0xcd50
testq %rax, %rax
je 0x377a4
movq %rax, %r14
movq %r13, %rdi
callq 0xc0d0
movq %r14, %rdi
callq 0xd150
movzwl 0x1f6(%r12), %edx
cmpq %rdx, %rax
ja 0x376a5
movq 0x20(%rsp), %r8
testq %r8, %r8
jne 0x37591
movq 0x298(%r12), %r8
movq %r12, %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq %rbx, %rcx
callq 0xc100
testl %eax, %eax
je 0x375b2
movl %eax, %r15d
xorl %ebp, %ebp
jmp 0x3781b
pushq $0x1
popq %rdi
pushq $0x68
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x377d4
movq %rax, %r15
movl 0x10(%rsp), %esi
movl %esi, (%rax)
movl 0x14(%rsp), %r13d
movw %r13w, 0x4(%rax)
movl %ebp, 0x8(%rax)
movq %r14, 0x20(%rax)
movq (%rsp), %rax
movq %rax, 0x30(%r15)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%r15)
movq 0x28(%r12), %rdi
callq 0x3c198
movq 0x20(%rax), %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x3bf07
movq %rbx, %rdi
callq 0xc0d0
incw 0x12e(%r12)
xorl %r15d, %r15d
jmp 0x37849
pushq $0x9
popq %rdi
addq %r14, %rdi
callq 0xcd50
testq %rax, %rax
je 0x37767
movq %rax, %rbx
testb %r15b, %r15b
je 0x3731f
jmp 0x37323
movq 0x1b9a9(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xcf64(%rip), %rdi      # 0x445bd
pushq $0x7c
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0x19
popq %r15
jmp 0x37849
xorl %r13d, %r13d
jmp 0x37514
movq 0x1b97c(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5a5a(%rip), %rsi      # 0x3d0e0
leaq 0xc353(%rip), %rdx      # 0x439e0
xorl %r14d, %r14d
movl $0x2051, %ecx           # imm = 0x2051
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
jmp 0x37794
movq 0x1b94c(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xcf97(%rip), %rsi      # 0x4464d
xorl %ebp, %ebp
movq %r14, %rcx
xorl %eax, %eax
callq 0xc8d0
pushq $0x18
jmp 0x37819
movq 0x1b928(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5a06(%rip), %rsi      # 0x3d0e0
leaq 0xc2ff(%rip), %rdx      # 0x439e0
xorl %ebx, %ebx
movl $0x203a, %ecx           # imm = 0x203A
jmp 0x37786
movq 0x1b904(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x59e2(%rip), %rsi      # 0x3d0e0
leaq 0xc2db(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x206c, %ecx           # imm = 0x206C
jmp 0x37810
movq 0x1b8e0(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x59be(%rip), %rsi      # 0x3d0e0
leaq 0xc2b7(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x2064, %ecx           # imm = 0x2064
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
xorl %r13d, %r13d
jmp 0x3781f
movq 0x1b8ae(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x598c(%rip), %rsi      # 0x3d0e0
leaq 0xc285(%rip), %rdx      # 0x439e0
xorl %ebp, %ebp
movl $0x2088, %ecx           # imm = 0x2088
jmp 0x37810
movq 0x1b88a(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x5968(%rip), %rsi      # 0x3d0e0
leaq 0xc261(%rip), %rdx      # 0x439e0
xorl %ebx, %ebx
movl $0x2048, %ecx           # imm = 0x2048
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r13d, %r13d
movq $0x0, 0x8(%rsp)
jmp 0x3781f
movq 0x1b84d(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x592b(%rip), %rsi      # 0x3d0e0
leaq 0xc224(%rip), %rdx      # 0x439e0
xorl %r14d, %r14d
movl $0x2096, %ecx           # imm = 0x2096
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
movq %r13, %rbp
jmp 0x3781b
movq 0x1b81d(%rip), %r13     # 0x52ff8
movq (%r13), %rdi
leaq 0x58fa(%rip), %r15      # 0x3d0e0
leaq 0xc1f3(%rip), %r12      # 0x439e0
xorl %ebp, %ebp
movq %r15, %rsi
movq %r12, %rdx
movl $0x3fc, %ecx            # imm = 0x3FC
xorl %eax, %eax
callq 0xc8d0
movq (%r13), %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x20b6, %ecx           # imm = 0x20B6
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %r15
movq (%rsp), %r13
movq %rbx, %rdi
callq 0xc0d0
movq %r14, %rdi
callq 0xc0d0
movq %rbp, %rdi
callq 0xc0d0
movq %r13, %rdi
callq 0xc0d0
movq 0x8(%rsp), %rdi
callq 0xc0d0
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq