// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %esi, %ebp
movq %rdi, %rbx
cmpq $0x0, 0x290(%rdi)
jne 0x31eab
movl %r8d, %r15d
movl %edx, %r12d
callq 0xc930
movq %rax, 0x290(%rbx)
testq %rax, %rax
je 0x3203d
testb %r15b, %r15b
je 0x31e19
movb $0x0, 0x8(%rax)
movb 0x13d(%rbx), %cl
movb %cl, 0x9(%rax)
jmp 0x31e1d
movb $0x1, 0x8(%rax)
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x32044
movq %rax, %r15
leaq 0x14f99(%rip), %rdi     # 0x46dd8
callq 0xcce0
movq %rax, (%r15)
testq %rax, %rax
je 0x3204e
leaq 0x14f8a(%rip), %rdx     # 0x46de1
leaq 0x10(%rsp), %r13
movl $0x80, %esi
movq %r13, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0xc570
movq %r13, %rdi
callq 0xcce0
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x32055
movq %r15, %rax
addq $0x18, %rax
movq $0x0, 0x18(%r15)
movq 0x220(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r15, (%rcx)
movq 0x220(%rbx), %rcx
movq %rax, 0x8(%rcx)
movl $0x1, %edi
movl $0x80, %esi
callq 0xc7f0
testq %rax, %rax
je 0x32021
movq %rax, %r15
movb $0x1, 0x1(%rax)
movl 0x40(%r14), %eax
cmpb $0x1, %al
adcl $0x0, %eax
movb %al, 0x1(%r15)
movb $0x2, (%r15)
movq 0x28(%r14), %rdi
callq 0xcce0
movq %rax, 0x60(%r15)
movq $0x0, 0x68(%r15)
movl 0x20c(%rbx), %eax
incl %eax
movl %eax, 0x20c(%rbx)
movl %eax, 0x54(%r15)
movl $0x0, 0x58(%r15)
movb 0xb0(%r14), %al
movb %al, 0x70(%r15)
movsd 0x68(%r14), %xmm1
movsd 0x70(%r14), %xmm0
mulsd 0x8(%r14), %xmm1
movsd %xmm1, (%rsp)
mulsd 0x10(%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x68(%r14)
movsd %xmm0, 0x70(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x31510
movsd 0x1468e(%rip), %xmm0    # 0x465e8
movsd (%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0xe565(%rip), %xmm1     # 0x404d0
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %rax
movl %eax, 0x48(%r15)
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %rax
movl %eax, 0x4c(%r15)
movq 0x290(%rbx), %rdi
movq %r15, %rsi
callq 0xce40
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x32028
movq %rax, %r15
leaq 0x14eec(%rip), %rdi     # 0x46ea8
callq 0xcce0
movq %rax, (%r15)
testq %rax, %rax
je 0x3202f
leaq 0x14edf(%rip), %rdx     # 0x46eaf
leaq 0x10(%rsp), %r14
movl $0x20, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
movq %r14, %rdi
callq 0xcce0
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x32036
movq %r15, %rax
addq $0x18, %rax
movq $0x0, 0x18(%r15)
movq 0x228(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r15, (%rcx)
movq 0x228(%rbx), %rcx
movq %rax, 0x8(%rcx)
jmp 0x32062
callq 0xeb20
jmp 0x32062
movl $0xe3b, %esi            # imm = 0xE3B
jmp 0x32049
movl $0xe3e, %esi            # imm = 0xE3E
jmp 0x3205a
movl $0xe43, %esi            # imm = 0xE43
jmp 0x3205a
callq 0xeb98
jmp 0x32062
movl $0xe0d, %esi            # imm = 0xE0D
xorl %r15d, %r15d
jmp 0x3205a
movl $0xe10, %esi            # imm = 0xE10
jmp 0x3205a
movl $0xe16, %esi            # imm = 0xE16
movq %r15, %rdi
callq 0xeb4a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq