// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: lxw_worksheet_prepare_vml_objects
uint32_t
lxw_worksheet_prepare_vml_objects(lxw_worksheet *self,
                                  uint32_t vml_data_id,
                                  uint32_t vml_shape_id,
                                  uint32_t vml_drawing_id,
                                  uint32_t comment_id)
{
    lxw_row *row;
    lxw_cell *cell;
    lxw_rel_tuple *relationship;
    char filename[LXW_FILENAME_LENGTH];
    uint32_t comment_count = 0;
    uint32_t i;
    uint32_t tmp_data_id;
    size_t data_str_len = 0;
    size_t used = 0;
    char *vml_data_id_str;

    RB_FOREACH(row, lxw_table_rows, self->comments) {

        RB_FOREACH(cell, lxw_table_cells, row->cells) {
            /* Calculate the worksheet position of the comment. */
            _worksheet_position_vml_object(self, cell->comment);

            /* Store comment in a simple list for use by packager. */
            STAILQ_INSERT_TAIL(self->comment_objs, cell->comment,
                               list_pointers);
            comment_count++;
        }
    }

    /* Set up the VML relationship for comments/buttons/header images. */
    relationship = calloc(1, sizeof(lxw_rel_tuple));
    GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

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

    lxw_snprintf(filename, 32, "../drawings/vmlDrawing%d.vml",
                 vml_drawing_id);

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

    self->external_vml_comment_link = relationship;

    if (self->has_comments) {
        /* Only need this relationship object for comment VMLs. */

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

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

        lxw_snprintf(filename, 32, "../comments%d.xml", comment_id);

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

        self->external_comment_link = relationship;
    }

    /* The vml.c <o:idmap> element data id contains a comma separated range
     * when there is more than one 1024 block of comments, like this:
     * data="1,2,3". Since this could potentially (but unlikely) exceed
     * LXW_MAX_ATTRIBUTE_LENGTH we need to allocate space dynamically. */

    /* Calculate the total space required for the ID for each 1024 block. */
    for (i = 0; i <= comment_count / 1024; i++) {
        tmp_data_id = vml_data_id + i;

        /* Calculate the space required for the digits in the id. */
        while (tmp_data_id) {
            data_str_len++;
            tmp_data_id /= 10;
        }

        /* Add an extra char for comma separator or '\O'. */
        data_str_len++;
    };

    /* If this allocation fails it will be dealt with in packager.c. */
    vml_data_id_str = calloc(1, data_str_len + 2);
    GOTO_LABEL_ON_MEM_ERROR(vml_data_id_str, mem_error);

    /* Create the CSV list in the allocated space. */
    for (i = 0; i <= comment_count / 1024; i++) {
        tmp_data_id = vml_data_id + i;
        lxw_snprintf(vml_data_id_str + used, data_str_len - used, "%d,",
                     tmp_data_id);

        used = strlen(vml_data_id_str);
    };

    self->vml_shape_id = vml_shape_id;
    self->vml_data_id_str = vml_data_id_str;

    return comment_count;

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

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r8d, 0x8(%rsp)
movl %ecx, (%rsp)
movl %edx, %r13d
movl %esi, %r15d
movq %rdi, %r14
movq 0x30(%rdi), %rax
xorl %ecx, %ecx
movq %rcx, %r12
movq (%rax), %rcx
leaq 0x28(%rcx), %rax
testq %rcx, %rcx
jne 0x2f29f
xorl %ebx, %ebx
testq %r12, %r12
je 0x2f324
movq 0x20(%r12), %rax
xorl %ecx, %ecx
movq %rcx, %rbp
movq (%rax), %rcx
leaq 0x48(%rcx), %rax
testq %rcx, %rcx
jne 0x2f2bc
jmp 0x2f312
movq 0x18(%rbp), %rsi
movq %r14, %rdi
callq 0xcc40
movq 0x18(%rbp), %rax
andq $0x0, 0xb8(%rax)
leaq 0xb8(%rax), %rcx
movq 0x80(%r14), %rdx
movq 0x8(%rdx), %rdx
movq %rax, (%rdx)
movq 0x80(%r14), %rax
movq %rcx, 0x8(%rax)
incl %ebx
movq %rbp, %rdi
callq 0x2f5d6
movq %rax, %rbp
testq %rbp, %rbp
jne 0x2f2cd
movq %r12, %rdi
callq 0x2c3f9
movq %rax, %r12
jmp 0x2f2b0
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2f497
movq %rax, %r12
leaq 0x14c5b(%rip), %rdi     # 0x43f9d
callq 0xcd50
movq %rax, (%r12)
testq %rax, %rax
je 0x2f4bb
movq %rax, %rbp
movl %r13d, 0xc(%rsp)
leaq 0x14c46(%rip), %rdx     # 0x43fa9
leaq 0x10(%rsp), %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
movl (%rsp), %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r13, %rdi
callq 0xcd50
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x2f4df
movq %r12, 0x2a8(%r14)
cmpb $0x0, 0x2a1(%r14)
je 0x2f40c
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x2f52f
movq %rax, %r12
leaq 0x14c09(%rip), %rdi     # 0x43fc6
callq 0xcd50
movq %rax, (%r12)
testq %rax, %rax
je 0x2f557
movq %rax, %rbp
leaq 0x14bf7(%rip), %rdx     # 0x43fd0
leaq 0x10(%rsp), %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r13, %rdi
callq 0xcd50
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x2f578
movq %r12, 0x2b0(%r14)
movq %r12, (%rsp)
movl %ebx, %ebp
shrl $0xa, %ebp
incl %ebp
xorl %ecx, %ecx
pushq $0xa
popq %rsi
xorl %r12d, %r12d
cmpl %ebp, %ecx
je 0x2f438
leal (%rcx,%r15), %eax
incq %r12
testl %eax, %eax
je 0x2f434
xorl %edx, %edx
divl %esi
jmp 0x2f427
incl %ecx
jmp 0x2f41f
leaq 0x2(%r12), %rsi
pushq $0x1
popq %rdi
callq 0xc850
testq %rax, %rax
je 0x2f501
movq %rax, %r13
xorl %eax, %eax
subl $0x1, %ebp
jb 0x2f480
leaq (%rax,%r13), %rdi
movq %r12, %rsi
subq %rax, %rsi
leaq 0x14b79(%rip), %rdx     # 0x43fe2
movl %r15d, %ecx
xorl %eax, %eax
callq 0xc5b0
movq %r13, %rdi
callq 0xc4c0
incl %r15d
jmp 0x2f453
movl 0xc(%rsp), %eax
movl %eax, 0x2e0(%r14)
movq %r13, 0x2d0(%r14)
jmp 0x2f5c2
movq 0x23b5a(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdc38(%rip), %rsi      # 0x3d0e0
leaq 0x14531(%rip), %rdx     # 0x439e0
xorl %ebx, %ebx
movl $0xe76, %ecx            # imm = 0xE76
jmp 0x2f54e
movq 0x23b36(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdc14(%rip), %rsi      # 0x3d0e0
leaq 0x1450d(%rip), %rdx     # 0x439e0
xorl %ebp, %ebp
movl $0xe79, %ecx            # imm = 0xE79
jmp 0x2f595
movq 0x23b12(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdbf0(%rip), %rsi      # 0x3d0e0
leaq 0x144e9(%rip), %rdx     # 0x439e0
movl $0xe7f, %ecx            # imm = 0xE7F
jmp 0x2f595
movq 0x23af0(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdbce(%rip), %rsi      # 0x3d0e0
leaq 0x144c7(%rip), %rdx     # 0x439e0
movl $0xea9, %ecx            # imm = 0xEA9
xorl %eax, %eax
callq 0xc8d0
movq (%rsp), %r12
movq (%r12), %rbp
jmp 0x2f59c
movq 0x23ac2(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdba0(%rip), %rsi      # 0x3d0e0
leaq 0x14499(%rip), %rdx     # 0x439e0
xorl %ebx, %ebx
movl $0xe87, %ecx            # imm = 0xE87
xorl %eax, %eax
callq 0xc8d0
jmp 0x2f5c2
movq 0x23a9a(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdb78(%rip), %rsi      # 0x3d0e0
leaq 0x14471(%rip), %rdx     # 0x439e0
xorl %ebp, %ebp
movl $0xe8a, %ecx            # imm = 0xE8A
jmp 0x2f595
movq 0x23a79(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xdb57(%rip), %rsi      # 0x3d0e0
leaq 0x14450(%rip), %rdx     # 0x439e0
movl $0xe8f, %ecx            # imm = 0xE8F
xorl %eax, %eax
callq 0xc8d0
movq %rbp, %rdi
callq 0xc0d0
movq 0x8(%r12), %rdi
callq 0xc0d0
movq 0x10(%r12), %rdi
callq 0xc0d0
movq %r12, %rdi
callq 0xc0d0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq