// File: /workspace/github_c_makefile_star2_O3/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 0x32123
movl %r8d, %r14d
movl %edx, %r13d
callq 0xc930
movq %rax, 0x290(%rbx)
testq %rax, %rax
je 0x3229b
testb %r14b, %r14b
je 0x3208f
movb 0x13d(%rbx), %cl
movb %cl, 0x9(%rax)
xorl %ecx, %ecx
jmp 0x32091
movb $0x1, %cl
movb %cl, 0x8(%rax)
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x322a2
movq %rax, %r14
leaq 0x14e0e(%rip), %rdi     # 0x46ec4
callq 0xcce0
movq %rax, (%r14)
testq %rax, %rax
je 0x322a9
movq %rax, %r12
movl %ebp, (%rsp)
leaq 0x14df9(%rip), %rdx     # 0x46ecd
leaq 0x10(%rsp), %rbp
movl $0x80, %esi
movq %rbp, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0xc570
movq %rbp, %rdi
callq 0xcce0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x322b3
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
movl $0x1, %edi
movl $0x80, %esi
callq 0xc7f0
testq %rax, %rax
je 0x3227f
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 0xcce0
movq %rax, 0x60(%r14)
movl 0x20c(%rbx), %eax
incl %eax
movl %eax, 0x20c(%rbx)
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 0x3176b
movapd (%rsp), %xmm2
mulpd 0x144e1(%rip), %xmm2    # 0x46690
addpd 0x144a9(%rip), %xmm2    # 0x46660
cvttpd2dq %xmm2, %xmm0
movapd %xmm0, %xmm1
psrad $0x1f, %xmm1
addpd 0x144a4(%rip), %xmm2    # 0x46670
cvttpd2dq %xmm2, %xmm2
andpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movlpd %xmm2, 0x48(%r14)
movq 0x290(%rbx), %rdi
movq %r14, %rsi
callq 0xce40
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x32286
movq %rax, %r14
leaq 0x14d85(%rip), %rdi     # 0x46f94
callq 0xcce0
movq %rax, (%r14)
testq %rax, %rax
je 0x3228d
movq %rax, %r12
leaq 0x14d75(%rip), %rdx     # 0x46f9b
leaq 0x10(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
movq %r15, %rdi
callq 0xcce0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x32294
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
callq 0xee69
jmp 0x3226d
callq 0xee3f
jmp 0x3226d
callq 0xee15
jmp 0x322ae
callq 0xedeb
jmp 0x322b8
callq 0xef05
jmp 0x3226d
callq 0xeee1
jmp 0x3226d
callq 0xeebd
xorl %r12d, %r12d
jmp 0x322b8
callq 0xee93
movq %r12, %rdi
callq 0xc0c0
movq 0x8(%r14), %rdi
callq 0xc0c0
movq 0x10(%r14), %rdi
callq 0xc0c0
movq %r14, %rdi
callq 0xc0c0
jmp 0x3226d