// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: lxw_worksheet_prepare_image
void
lxw_worksheet_prepare_image(lxw_worksheet *self,
                            uint32_t image_ref_id, uint32_t drawing_id,
                            lxw_object_properties *object_props)
{
    lxw_drawing_object *drawing_object;
    lxw_rel_tuple *relationship;
    double width;
    double height;
    char *url;
    char *found_string;
    size_t i;
    char filename[LXW_FILENAME_LENGTH];
    enum cell_types link_type = HYPERLINK_URL;

    if (!self->drawing) {
        self->drawing = lxw_drawing_new();
        self->drawing->embedded = LXW_TRUE;
        RETURN_VOID_ON_MEM_ERROR(self->drawing);

        relationship = calloc(1, sizeof(lxw_rel_tuple));
        GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

        relationship->type = lxw_strdup("/drawing");
        GOTO_LABEL_ON_MEM_ERROR(relationship->type, mem_error);

        lxw_snprintf(filename, LXW_FILENAME_LENGTH,
                     "../drawings/drawing%d.xml", drawing_id);

        relationship->target = lxw_strdup(filename);
        GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

        STAILQ_INSERT_TAIL(self->external_drawing_links, relationship,
                           list_pointers);
    }

    drawing_object = calloc(1, sizeof(lxw_drawing_object));
    RETURN_VOID_ON_MEM_ERROR(drawing_object);

    drawing_object->anchor = LXW_OBJECT_MOVE_DONT_SIZE;
    if (object_props->object_position)
        drawing_object->anchor = object_props->object_position;

    drawing_object->type = LXW_DRAWING_IMAGE;
    drawing_object->description = lxw_strdup(object_props->description);
    drawing_object->tip = lxw_strdup(object_props->tip);
    drawing_object->rel_index = 0;
    drawing_object->url_rel_index = 0;
    drawing_object->decorative = object_props->decorative;

    /* Scale to user scale. */
    width = object_props->width * object_props->x_scale;
    height = object_props->height * object_props->y_scale;

    /* Scale by non 96dpi resolutions. */
    width *= 96.0 / object_props->x_dpi;
    height *= 96.0 / object_props->y_dpi;

    object_props->width = width;
    object_props->height = height;

    _worksheet_position_object_emus(self, object_props, drawing_object);

    /* Convert from pixels to emus. */
    drawing_object->width = (uint32_t) (0.5 + width * 9525);
    drawing_object->height = (uint32_t) (0.5 + height * 9525);

    lxw_add_drawing_object(self->drawing, drawing_object);

    if (object_props->url) {
        url = object_props->url;

        relationship = calloc(1, sizeof(lxw_rel_tuple));
        GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

        relationship->type = lxw_strdup("/hyperlink");
        GOTO_LABEL_ON_MEM_ERROR(relationship->type, mem_error);

        /* Check the link type. Default to external hyperlinks. */
        if (strstr(url, "internal:"))
            link_type = HYPERLINK_INTERNAL;
        else if (strstr(url, "external:"))
            link_type = HYPERLINK_EXTERNAL;
        else
            link_type = HYPERLINK_URL;

        /* Set the relationship object for each type of link. */
        if (link_type == HYPERLINK_INTERNAL) {
            relationship->target_mode = NULL;
            relationship->target = lxw_strdup(url + sizeof("internal") - 1);
            GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

            /* We need to prefix the internal link/range with #. */
            relationship->target[0] = '#';
        }
        else if (link_type == HYPERLINK_EXTERNAL) {
            relationship->target_mode = lxw_strdup("External");
            GOTO_LABEL_ON_MEM_ERROR(relationship->target_mode, mem_error);

            /* Look for Windows style "C:/" link or Windows share "\\" link. */
            found_string = strchr(url + sizeof("external:") - 1, ':');
            if (!found_string)
                found_string = strstr(url, "\\\\");

            if (found_string) {
                /* Copy the url with some space at the start to overwrite
                 * "external:" with "file:///". */
                relationship->target = lxw_escape_url_characters(url + 1,
                                                                 LXW_TRUE);
                GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

                /* Add the file:/// URI to the url if absolute path. */
                memcpy(relationship->target, "file:///",
                       sizeof("file:///") - 1);
            }
            else {
                /* Copy the relative url without "external:". */
                relationship->target =
                    lxw_escape_url_characters(url + sizeof("external:") - 1,
                                              LXW_TRUE);
                GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

                /* Switch backslash to forward slash. */
                for (i = 0; i <= strlen(relationship->target); i++)
                    if (relationship->target[i] == '\\')
                        relationship->target[i] = '/';
            }

        }
        else {
            relationship->target_mode = lxw_strdup("External");
            GOTO_LABEL_ON_MEM_ERROR(relationship->target_mode, mem_error);

            relationship->target =
                lxw_escape_url_characters(object_props->url, LXW_FALSE);
            GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);
        }

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

        if (!_find_drawing_rel_index(self, url)) {
            STAILQ_INSERT_TAIL(self->drawing_links, relationship,
                               list_pointers);
        }
        else {
            free(relationship->type);
            free(relationship->target);
            free(relationship->target_mode);
            free(relationship);
        }

        drawing_object->url_rel_index = _get_drawing_rel_index(self, url);

    }

    if (!_find_drawing_rel_index(self, object_props->md5)) {
        relationship = calloc(1, sizeof(lxw_rel_tuple));
        GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

        relationship->type = lxw_strdup("/image");
        GOTO_LABEL_ON_MEM_ERROR(relationship->type, mem_error);

        lxw_snprintf(filename, 32, "../media/image%d.%s", image_ref_id,
                     object_props->extension);

        relationship->target = lxw_strdup(filename);
        GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

        STAILQ_INSERT_TAIL(self->drawing_links, relationship, list_pointers);
    }

    drawing_object->rel_index =
        _get_drawing_rel_index(self, object_props->md5);

    return;

mem_error:
    if (relationship) {
        free(relationship->type);
        free(relationship->target);
        free(relationship->target_mode);
        free(relationship);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %r15
movl %esi, %r13d
movq %rdi, %r14
cmpq $0x0, 0x290(%rdi)
jne 0x2df1f
movl %edx, %ebp
callq 0xc990
movq %rax, 0x290(%r14)
movb $0x1, 0x8(%rax)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2e317
movq %rax, %rbx
leaq 0x15ff9(%rip), %rdi     # 0x43eb0
callq 0xcd50
movq %rax, (%rbx)
testq %rax, %rax
je 0x2e34c
leaq 0x15fea(%rip), %rdx     # 0x43eb9
leaq 0x30(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r12, %rdi
callq 0xcd50
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e36e
movq %rbx, %rax
addq $0x18, %rax
andq $0x0, 0x18(%rbx)
movq 0x220(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %rbx, (%rcx)
movq 0x220(%r14), %rcx
movq %rax, 0x8(%rcx)
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0xc850
testq %rax, %rax
je 0x2e291
movq %rax, %r12
movl %r13d, 0x4(%rsp)
movl 0x40(%r15), %eax
testb %al, %al
pushq $0x2
popq %rcx
cmovnel %eax, %ecx
movb %cl, 0x1(%r12)
movb $0x1, (%r12)
movq 0x28(%r15), %rdi
callq 0xcd50
movq %rax, 0x60(%r12)
movq 0x38(%r15), %rdi
callq 0xcd50
movq %rax, 0x68(%r12)
andq $0x0, 0x54(%r12)
movb 0xb0(%r15), %al
movb %al, 0x70(%r12)
movupd 0x8(%r15), %xmm0
movupd 0x68(%r15), %xmm1
mulpd %xmm0, %xmm1
movupd 0x80(%r15), %xmm0
movapd 0x156be(%rip), %xmm2    # 0x43660
divpd %xmm0, %xmm2
mulpd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp)
movupd %xmm2, 0x68(%r15)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2e530
movapd 0x10(%rsp), %xmm2
mulpd 0x1569e(%rip), %xmm2    # 0x43670
addpd 0x15666(%rip), %xmm2    # 0x43640
cvttpd2dq %xmm2, %xmm0
movapd %xmm0, %xmm1
psrad $0x1f, %xmm1
addpd 0x15661(%rip), %xmm2    # 0x43650
cvttpd2dq %xmm2, %xmm2
andpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movlpd %xmm2, 0x48(%r12)
movq 0x290(%r14), %rdi
movq %r12, %rsi
callq 0xcec0
movq 0x30(%r15), %r13
testq %r13, %r13
je 0x2e1c4
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2e2b3
movq %rax, %rbx
leaq 0x15e97(%rip), %rdi     # 0x43ed3
callq 0xcd50
movq %rax, (%rbx)
testq %rax, %rax
je 0x2e2d5
movq %rax, 0x10(%rsp)
leaq 0x15e85(%rip), %rsi     # 0x43ede
movq %r13, %rdi
callq 0xd100
testq %rax, %rax
je 0x2e090
leaq 0x8(%r13), %rdi
callq 0xcd50
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e390
movq %rax, %rbp
movb $0x23, (%rax)
movq $0x0, 0x8(%rsp)
jmp 0x2e141
leaq 0x15e51(%rip), %rsi     # 0x43ee8
movq %r13, %rdi
callq 0xd100
movq %rax, %rbp
leaq 0x15e49(%rip), %rdi     # 0x43ef2
callq 0xcd50
movq %rax, 0x10(%rbx)
testq %rbp, %rbp
movq %rax, 0x8(%rsp)
je 0x2e11d
testq %rax, %rax
je 0x2e469
leaq 0x9(%r13), %rbp
pushq $0x3a
popq %rsi
movq %rbp, %rdi
callq 0xc500
testq %rax, %rax
jne 0x2e0f1
leaq 0x15e1b(%rip), %rsi     # 0x43efb
movq %r13, %rdi
callq 0xd100
testq %rax, %rax
je 0x2e3fd
leaq 0x1(%r13), %rdi
pushq $0x1
popq %rsi
callq 0xcfe0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e488
movq %rax, %rbp
movabsq $0x2f2f2f3a656c6966, %rax # imm = 0x2F2F2F3A656C6966
movq %rax, (%rbp)
jmp 0x2e141
testq %rax, %rax
je 0x2e4a7
movq 0x30(%r15), %rdi
xorl %esi, %esi
callq 0xcfe0
movq %rax, %rbp
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e4c6
movq %r13, %rdi
callq 0xd150
movzwl 0x1f6(%r14), %edx
cmpq %rdx, %rax
ja 0x2e2f7
movq %r14, %rdi
movq %r13, %rsi
callq 0x2e57f
testl %eax, %eax
je 0x2e18f
movq 0x10(%rsp), %rdi
callq 0xc0d0
movq %rbp, %rdi
callq 0xc0d0
movq 0x8(%rsp), %rdi
callq 0xc0d0
movq %rbx, %rdi
callq 0xc0d0
jmp 0x2e1b4
movq %rbx, %rax
addq $0x18, %rax
andq $0x0, 0x18(%rbx)
movq 0x228(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %rbx, (%rcx)
movq 0x228(%r14), %rcx
movq %rax, 0x8(%rcx)
movq %r14, %rdi
movq %r13, %rsi
callq 0x2e5ad
movl %eax, 0x58(%r12)
movq 0xa0(%r15), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e57f
testl %eax, %eax
jne 0x2e26f
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2e3b2
movq %rax, %rbx
leaq 0x15d69(%rip), %rdi     # 0x43f65
callq 0xcd50
movq %rax, (%rbx)
testq %rax, %rax
je 0x2e3db
movq 0x78(%r15), %r8
leaq 0x15d54(%rip), %rdx     # 0x43f6c
leaq 0x30(%rsp), %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
movl 0x4(%rsp), %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r13, %rdi
callq 0xcd50
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e43d
andq $0x0, 0x18(%rbx)
movq %rbx, %rax
addq $0x18, %rax
movq 0x228(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %rbx, (%rcx)
movq 0x228(%r14), %rcx
movq %rax, 0x8(%rcx)
movq 0xa0(%r15), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e5ad
movl %eax, 0x54(%r12)
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x24d60(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xee3e(%rip), %rsi      # 0x3d0e0
leaq 0x15737(%rip), %rdx     # 0x439e0
movl $0xced, %ecx            # imm = 0xCED
jmp 0x2e3cf
movq 0x24d3e(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xee1c(%rip), %rsi      # 0x3d0e0
leaq 0x15715(%rip), %rdx     # 0x439e0
movl $0xd11, %ecx            # imm = 0xD11
jmp 0x2e3cf
movq 0x24d1c(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xedfa(%rip), %rsi      # 0x3d0e0
leaq 0x156f3(%rip), %rdx     # 0x439e0
movl $0xd14, %ecx            # imm = 0xD14
jmp 0x2e4e3
movq 0x24cfa(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x15bf6(%rip), %rsi     # 0x43efe
movq %r13, %rcx
xorl %eax, %eax
callq 0xc8d0
jmp 0x2e4ea
movq 0x24cda(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xedb8(%rip), %rsi      # 0x3d0e0
leaq 0x156b1(%rip), %rdx     # 0x439e0
movl $0xcdd, %ecx            # imm = 0xCDD
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8d0
movq 0x24ca5(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xed83(%rip), %rsi      # 0x3d0e0
leaq 0x1567c(%rip), %rdx     # 0x439e0
movl $0xce0, %ecx            # imm = 0xCE0
jmp 0x2e4e3
movq 0x24c83(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xed61(%rip), %rsi      # 0x3d0e0
leaq 0x1565a(%rip), %rdx     # 0x439e0
movl $0xce6, %ecx            # imm = 0xCE6
jmp 0x2e4e3
movq 0x24c61(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xed3f(%rip), %rsi      # 0x3d0e0
leaq 0x15638(%rip), %rdx     # 0x439e0
movl $0xd22, %ecx            # imm = 0xD22
jmp 0x2e4e3
movq 0x24c3f(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xed1d(%rip), %rsi      # 0x3d0e0
leaq 0x15616(%rip), %rdx     # 0x439e0
movl $0xd6b, %ecx            # imm = 0xD6B
xorl %eax, %eax
callq 0xc8d0
jmp 0x2e27f
movq 0x24c16(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xecf4(%rip), %rsi      # 0x3d0e0
leaq 0x155ed(%rip), %rdx     # 0x439e0
movl $0xd6e, %ecx            # imm = 0xD6E
jmp 0x2e4e3
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0xcfe0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2e511
movq %rax, %rbp
movq %rbx, 0x28(%rsp)
xorl %ebx, %ebx
movq %rbp, %rdi
callq 0xc4c0
cmpq %rax, %rbx
ja 0x2e45f
cmpb $0x5c, (%rbp,%rbx)
jne 0x2e438
movb $0x2f, (%rbp,%rbx)
incq %rbx
jmp 0x2e41f
movq 0x24bb4(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xec92(%rip), %rsi      # 0x3d0e0
leaq 0x1558b(%rip), %rdx     # 0x439e0
movl $0xd74, %ecx            # imm = 0xD74
jmp 0x2e4e3
movq 0x28(%rsp), %rbx
jmp 0x2e141
movq 0x24b88(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xec66(%rip), %rsi      # 0x3d0e0
leaq 0x1555f(%rip), %rdx     # 0x439e0
movl $0xd29, %ecx            # imm = 0xD29
jmp 0x2e4e3
movq 0x24b69(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xec47(%rip), %rsi      # 0x3d0e0
leaq 0x15540(%rip), %rdx     # 0x439e0
movl $0xd35, %ecx            # imm = 0xD35
jmp 0x2e4e3
movq 0x24b4a(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xec28(%rip), %rsi      # 0x3d0e0
leaq 0x15521(%rip), %rdx     # 0x439e0
movl $0xd4b, %ecx            # imm = 0xD4B
jmp 0x2e4e3
movq 0x24b2b(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xec09(%rip), %rsi      # 0x3d0e0
leaq 0x15502(%rip), %rdx     # 0x439e0
movl $0xd4f, %ecx            # imm = 0xD4F
xorl %eax, %eax
callq 0xc8d0
movq (%rbx), %rdi
callq 0xc0d0
movq 0x8(%rbx), %rdi
callq 0xc0d0
movq 0x10(%rbx), %rdi
callq 0xc0d0
movq %rbx, %rdi
callq 0xc0d0
jmp 0x2e27f
movq 0x24ae0(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xebbe(%rip), %rsi      # 0x3d0e0
leaq 0x154b7(%rip), %rdx     # 0x439e0
movl $0xd40, %ecx            # imm = 0xD40
jmp 0x2e4e3