// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movw %dx, %ax
movq 0x10(%rbp), %rdx
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movw %ax, -0x16(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x1, -0x8c(%rbp)
movl $0xb, -0x90(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x50fa5
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x50fb1
movl $0xc, -0x4(%rbp)
jmp 0x516c0
movq -0x10(%rbp), %rax
movzwl 0x12e(%rax), %eax
cmpl $0xfffa, %eax           # imm = 0xFFFA
jle 0x50fe7
movq 0x2c02e(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x1c006(%rip), %rsi     # 0x6cfda
movb $0x0, %al
callq 0xc8f0
movl $0x19, -0x4(%rbp)
jmp 0x516c0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
xorl %r8d, %r8d
movzwl -0x16(%rbp), %edx
movl %r8d, %ecx
callq 0x4ff90
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x5101a
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x516c0
movl $0x1, -0x8c(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1b8c3(%rip), %rsi     # 0x6c8f2
callq 0xd130
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x51049
movl $0xc, -0x90(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1b8a8(%rip), %rsi     # 0x6c8fc
callq 0xd130
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x5106e
movl $0xd, -0x90(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x510b9
movq -0x30(%rbp), %rdi
callq 0xcd80
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x510b2
movq 0x2bf68(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x15036(%rip), %rsi     # 0x660d0
leaq 0x1b353(%rip), %rdx     # 0x6c3f4
movl $0x203a, %ecx           # imm = 0x203A
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x510b4
jmp 0x51146
cmpl $0xb, -0x90(%rbp)
jne 0x510ff
movq -0x20(%rbp), %rdi
leaq 0x1bf8a(%rip), %rsi     # 0x6d057
callq 0xd130
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x510f0
movq -0x20(%rbp), %rdi
addq $0x7, %rdi
callq 0xcd80
movq %rax, -0x40(%rbp)
jmp 0x510fd
movq -0x20(%rbp), %rdi
callq 0xcd80
movq %rax, -0x40(%rbp)
jmp 0x51110
movq -0x20(%rbp), %rdi
addq $0x9, %rdi
callq 0xcd80
movq %rax, -0x40(%rbp)
jmp 0x51112
cmpq $0x0, -0x40(%rbp)
jne 0x51142
movq 0x2bed8(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14fa6(%rip), %rsi     # 0x660d0
leaq 0x1b2c3(%rip), %rdx     # 0x6c3f4
movl $0x2048, %ecx           # imm = 0x2048
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x51144
jmp 0x51146
cmpq $0x0, -0x20(%rbp)
je 0x511ac
cmpl $0xb, -0x90(%rbp)
jne 0x51165
movq -0x20(%rbp), %rdi
callq 0xcd80
movq %rax, -0x48(%rbp)
jmp 0x51176
movq -0x20(%rbp), %rdi
addq $0x9, %rdi
callq 0xcd80
movq %rax, -0x48(%rbp)
jmp 0x51178
cmpq $0x0, -0x48(%rbp)
jne 0x511a8
movq 0x2be72(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14f40(%rip), %rsi     # 0x660d0
leaq 0x1b25d(%rip), %rdx     # 0x6c3f4
movl $0x2051, %ecx           # imm = 0x2051
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x511aa
jmp 0x511ac
cmpq $0x0, 0x10(%rbp)
je 0x511f4
movq 0x10(%rbp), %rdi
callq 0xcd80
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x511f0
movq 0x2be2a(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14ef8(%rip), %rsi     # 0x660d0
leaq 0x1b215(%rip), %rdx     # 0x6c3f4
movl $0x2056, %ecx           # imm = 0x2056
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x511f2
jmp 0x511f4
cmpl $0xc, -0x90(%rbp)
jne 0x5123e
movq -0x40(%rbp), %rdi
callq 0xcd80
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5123a
movq 0x2bde0(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14eae(%rip), %rsi     # 0x660d0
leaq 0x1b1cb(%rip), %rdx     # 0x6c3f4
movl $0x205b, %ecx           # imm = 0x205B
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x5123c
jmp 0x5123e
movq -0x48(%rbp), %rdi
movl $0x23, %esi
callq 0xc520
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x512aa
movq -0x58(%rbp), %rdi
callq 0xc0d0
movq -0x68(%rbp), %rdi
addq $0x1, %rdi
callq 0xcd80
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x512a1
movq 0x2bd79(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14e47(%rip), %rsi     # 0x660d0
leaq 0x1b164(%rip), %rdx     # 0x6c3f4
movl $0x2064, %ecx           # imm = 0x2064
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x512a3
movq -0x68(%rbp), %rax
movb $0x0, (%rax)
cmpl $0xb, -0x90(%rbp)
je 0x512bc
cmpl $0xd, -0x90(%rbp)
jne 0x5130e
movq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0xd010
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x512fb
movq 0x2bd1f(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14ded(%rip), %rsi     # 0x660d0
leaq 0x1b10a(%rip), %rdx     # 0x6c3f4
movl $0x206c, %ecx           # imm = 0x206C
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x512fd
movq -0x48(%rbp), %rdi
callq 0xc0d0
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0xd, -0x90(%rbp)
jne 0x5154f
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rdi
callq 0xc4e0
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
ja 0x51385
movq -0x48(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x5136f
movq -0x48(%rbp), %rax
movq -0x88(%rbp), %rcx
movb $0x5c, (%rax,%rcx)
jmp 0x51371
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x51326
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rdi
callq 0xc4e0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
ja 0x513ef
movq -0x40(%rbp), %rax
movq -0x88(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x513d9
movq -0x40(%rbp), %rax
movq -0x88(%rbp), %rcx
movb $0x5c, (%rax,%rcx)
jmp 0x513db
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x51390
movq -0x48(%rbp), %rdi
movl $0x3a, %esi
callq 0xc520
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x5141c
movq -0x48(%rbp), %rdi
leaq 0x1b4fc(%rip), %rsi     # 0x6c90f
callq 0xd130
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x51492
movq -0x48(%rbp), %rdi
callq 0xc4e0
addq $0x9, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rsi
movl $0x1, %edi
callq 0xc870
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x51476
movq 0x2bba4(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14c72(%rip), %rsi     # 0x660d0
leaq 0x1af8f(%rip), %rdx     # 0x6c3f4
movl $0x2088, %ecx           # imm = 0x2088
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x51478
movq -0x50(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x48(%rbp), %rcx
leaq 0x1bbd4(%rip), %rdx     # 0x6d05f
movb $0x0, %al
callq 0xc5d0
movq -0x48(%rbp), %rdi
leaq 0x1bbcd(%rip), %rsi     # 0x6d06a
callq 0xd130
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x514ed
movq -0x48(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rdi
callq 0xc4e0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
subq $0x1, %rdx
callq 0xcd70
cmpq $0x0, -0x50(%rbp)
je 0x5154d
movq -0x48(%rbp), %rdi
callq 0xc0d0
movq -0x50(%rbp), %rdi
callq 0xcd80
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5153a
movq 0x2bae0(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14bae(%rip), %rsi     # 0x660d0
leaq 0x1aecb(%rip), %rdx     # 0x6c3f4
movl $0x2096, %ecx           # imm = 0x2096
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x5153c
movq -0x50(%rbp), %rdi
callq 0xc0d0
movq $0x0, -0x50(%rbp)
jmp 0x5154f
movq -0x48(%rbp), %rdi
callq 0xd180
movq -0x10(%rbp), %rcx
movzwl 0x1f6(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x5159e
movq 0x2ba89(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzwl 0x1f6(%rax), %edx
movq -0x48(%rbp), %rcx
leaq 0x1bae5(%rip), %rsi     # 0x6d06d
movb $0x0, %al
callq 0xc8f0
movl $0x18, -0x8c(%rbp)
jmp 0x5168a
cmpq $0x0, -0x28(%rbp)
jne 0x515b6
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x515be
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movw -0x16(%rbp), %ax
movq -0x40(%rbp), %rcx
movq -0x78(%rbp), %r8
movzwl %ax, %edx
callq 0xc110
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x515ed
jmp 0x5168a
movl $0x1, -0x8c(%rbp)
movl -0x14(%rbp), %edi
movw -0x16(%rbp), %ax
movl -0x90(%rbp), %edx
movq -0x48(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x60(%rbp), %r9
movzwl %ax, %esi
callq 0x516d0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x51649
movq 0x2b9ce(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x14a9c(%rip), %rsi     # 0x660d0
leaq 0x1adb9(%rip), %rdx     # 0x6c3f4
movl $0x20b6, %ecx           # imm = 0x20B6
movb $0x0, %al
callq 0xc8f0
jmp 0x5168a
jmp 0x5164b
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movw -0x16(%rbp), %ax
movq -0x38(%rbp), %rcx
movzwl %ax, %edx
callq 0x51790
movq -0x40(%rbp), %rdi
callq 0xc0d0
movq -0x10(%rbp), %rax
movw 0x12e(%rax), %cx
addw $0x1, %cx
movw %cx, 0x12e(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x516c0
movq -0x40(%rbp), %rdi
callq 0xc0d0
movq -0x48(%rbp), %rdi
callq 0xc0d0
movq -0x50(%rbp), %rdi
callq 0xc0d0
movq -0x58(%rbp), %rdi
callq 0xc0d0
movq -0x60(%rbp), %rdi
callq 0xc0d0
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)