// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: lxw_worksheet_prepare_chart
void
lxw_worksheet_prepare_chart(lxw_worksheet *self,
                            uint32_t chart_ref_id,
                            uint32_t drawing_id,
                            lxw_object_properties *object_props,
                            uint8_t is_chartsheet)
{
    lxw_drawing_object *drawing_object;
    lxw_rel_tuple *relationship;
    double width;
    double height;
    char filename[LXW_FILENAME_LENGTH];

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

        if (is_chartsheet) {
            self->drawing->embedded = LXW_FALSE;
            self->drawing->orientation = self->orientation;
        }
        else {
            self->drawing->embedded = LXW_TRUE;
        }

        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_AND_SIZE;
    if (object_props->object_position)
        drawing_object->anchor = object_props->object_position;

    drawing_object->type = LXW_DRAWING_CHART;
    drawing_object->description = lxw_strdup(object_props->description);
    drawing_object->tip = NULL;
    drawing_object->rel_index = _get_drawing_rel_index(self, NULL);
    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;

    /* Convert to the nearest pixel. */
    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);

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

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

    lxw_snprintf(filename, 32, "../charts/chart%d.xml", chart_ref_id);

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

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

    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 $0x98, %rsp
movq %rcx, %r15
movl %esi, %ebp
movq %rdi, %rbx
cmpq $0x0, 0x290(%rdi)
jne 0x2efd2
movl %r8d, %r14d
movl %edx, %r13d
callq 0xc990
movq %rax, 0x290(%rbx)
testq %rax, %rax
je 0x2f1b6
testb %r14b, %r14b
je 0x2ef42
movb 0x13d(%rbx), %cl
movb %cl, 0x9(%rax)
xorl %ecx, %ecx
jmp 0x2ef44
movb $0x1, %cl
movb %cl, 0x8(%rax)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2f1d5
movq %rax, %r14
leaq 0x14f4b(%rip), %rdi     # 0x43eb0
callq 0xcd50
movq %rax, (%r14)
testq %rax, %rax
je 0x2f20a
movq %rax, %r12
movl %ebp, (%rsp)
leaq 0x14f36(%rip), %rdx     # 0x43eb9
leaq 0x10(%rsp), %rbp
movl $0x80, %esi
movq %rbp, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc5b0
movq %rbp, %rdi
callq 0xcd50
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x2f22c
movq %r14, %rax
addq $0x18, %rax
movq 0x220(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r14, (%rcx)
movq 0x220(%rbx), %rcx
movq %rax, 0x8(%rcx)
movl (%rsp), %ebp
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0xc850
testq %rax, %rax
je 0x2f12a
movq %rax, %r14
movl 0x40(%r15), %eax
cmpb $0x1, %al
adcl $0x0, %eax
movb %al, 0x1(%r14)
movb $0x2, (%r14)
movq 0x28(%r15), %rdi
callq 0xcd50
movq %rax, 0x60(%r14)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2e5ad
movl %eax, 0x54(%r14)
movb 0xb0(%r15), %al
movb %al, 0x70(%r14)
movupd 0x8(%r15), %xmm0
movupd 0x68(%r15), %xmm1
mulpd %xmm0, %xmm1
movapd %xmm1, (%rsp)
movupd %xmm1, 0x68(%r15)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2e530
movapd (%rsp), %xmm2
mulpd 0x14618(%rip), %xmm2    # 0x43670
addpd 0x145e0(%rip), %xmm2    # 0x43640
cvttpd2dq %xmm2, %xmm0
movapd %xmm0, %xmm1
psrad $0x1f, %xmm1
addpd 0x145db(%rip), %xmm2    # 0x43650
cvttpd2dq %xmm2, %xmm2
andpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movlpd %xmm2, 0x48(%r14)
movq 0x290(%rbx), %rdi
movq %r14, %rsi
callq 0xcec0
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2f149
movq %rax, %r14
leaq 0x14ecc(%rip), %rdi     # 0x43f80
callq 0xcd50
movq %rax, (%r14)
testq %rax, %rax
je 0x2f16f
movq %rax, %r12
leaq 0x14eb8(%rip), %rdx     # 0x43f87
leaq 0x10(%rsp), %r15
pushq $0x20
popq %rsi
movq %r15, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r15, %rdi
callq 0xcd50
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x2f194
movq %r14, %rax
addq $0x18, %rax
movq 0x228(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r14, (%rcx)
movq 0x228(%rbx), %rcx
movq %rax, 0x8(%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x23ec7(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdfa5(%rip), %rsi      # 0x3d0e0
leaq 0x1489e(%rip), %rdx     # 0x439e0
movl $0xe1d, %ecx            # imm = 0xE1D
jmp 0x2f166
movq 0x23ea8(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdf86(%rip), %rsi      # 0x3d0e0
leaq 0x1487f(%rip), %rdx     # 0x439e0
movl $0xe3b, %ecx            # imm = 0xE3B
xorl %eax, %eax
callq 0xc8d0
jmp 0x2f118
movq 0x23e82(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdf60(%rip), %rsi      # 0x3d0e0
leaq 0x14859(%rip), %rdx     # 0x439e0
xorl %r12d, %r12d
movl $0xe3e, %ecx            # imm = 0xE3E
jmp 0x2f249
movq 0x23e5d(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdf3b(%rip), %rsi      # 0x3d0e0
leaq 0x14834(%rip), %rdx     # 0x439e0
movl $0xe43, %ecx            # imm = 0xE43
jmp 0x2f249
movq 0x23e3b(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdf19(%rip), %rsi      # 0x3d0e0
leaq 0x14812(%rip), %rdx     # 0x439e0
movl $0xe02, %ecx            # imm = 0xE02
jmp 0x2f1f2
movq 0x23e1c(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdefa(%rip), %rsi      # 0x3d0e0
leaq 0x147f3(%rip), %rdx     # 0x439e0
movl $0xe0d, %ecx            # imm = 0xE0D
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8d0
movq 0x23de7(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdec5(%rip), %rsi      # 0x3d0e0
leaq 0x147be(%rip), %rdx     # 0x439e0
xorl %r12d, %r12d
movl $0xe10, %ecx            # imm = 0xE10
jmp 0x2f249
movq 0x23dc5(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdea3(%rip), %rsi      # 0x3d0e0
leaq 0x1479c(%rip), %rdx     # 0x439e0
movl $0xe16, %ecx            # imm = 0xE16
xorl %eax, %eax
callq 0xc8d0
movq %r12, %rdi
callq 0xc0d0
movq 0x8(%r14), %rdi
callq 0xc0d0
movq 0x10(%r14), %rdi
callq 0xc0d0
movq %r14, %rdi
callq 0xc0d0
jmp 0x2f118