// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: workbook_add_chartsheet
lxw_chartsheet *
workbook_add_chartsheet(lxw_workbook *self, const char *sheetname)
{
    lxw_sheet *sheet = NULL;
    lxw_chartsheet *chartsheet = NULL;
    lxw_chartsheet_name *chartsheet_name = NULL;
    lxw_error error;
    lxw_worksheet_init_data init_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    char *new_name = NULL;

    if (sheetname) {
        /* Use the user supplied name. */
        init_data.name = lxw_strdup(sheetname);
        init_data.quoted_name = lxw_quote_sheetname(sheetname);
    }
    else {
        /* Use the default SheetN name. */
        new_name = malloc(LXW_MAX_SHEETNAME_LENGTH);
        GOTO_LABEL_ON_MEM_ERROR(new_name, mem_error);

        lxw_snprintf(new_name, LXW_MAX_SHEETNAME_LENGTH, "Chart%d",
                     self->num_chartsheets + 1);
        init_data.name = new_name;
        init_data.quoted_name = lxw_strdup(new_name);
    }

    /* Check that the chartsheet name is valid. */
    error = workbook_validate_sheet_name(self, init_data.name);
    if (error) {
        LXW_WARN_FORMAT2
            ("workbook_add_chartsheet(): chartsheet name '%s' has "
             "error: %s", init_data.name, lxw_strerror(error));
        goto mem_error;
    }

    /* Create a struct to find/store the chartsheet name/pointer. */
    chartsheet_name = calloc(1, sizeof(struct lxw_chartsheet_name));
    GOTO_LABEL_ON_MEM_ERROR(chartsheet_name, mem_error);

    /* Initialize the metadata to pass to the chartsheet. */
    init_data.hidden = 0;
    init_data.index = self->num_sheets;
    init_data.sst = self->sst;
    init_data.optimize = self->options.constant_memory;
    init_data.active_sheet = &self->active_sheet;
    init_data.first_sheet = &self->first_sheet;
    init_data.tmpdir = self->options.tmpdir;

    /* Create a new chartsheet object. */
    chartsheet = lxw_chartsheet_new(&init_data);
    GOTO_LABEL_ON_MEM_ERROR(chartsheet, mem_error);

    /* Add it to the chartsheet list. */
    self->num_chartsheets++;
    STAILQ_INSERT_TAIL(self->chartsheets, chartsheet, list_pointers);

    /* Create a new sheet object. */
    sheet = calloc(1, sizeof(lxw_sheet));
    GOTO_LABEL_ON_MEM_ERROR(sheet, mem_error);
    sheet->is_chartsheet = LXW_TRUE;
    sheet->u.chartsheet = chartsheet;

    /* Add it to the chartsheet list. */
    self->num_sheets++;
    STAILQ_INSERT_TAIL(self->sheets, sheet, list_pointers);

    /* Store the chartsheet so we can look it up by name. */
    chartsheet_name->name = init_data.name;
    chartsheet_name->chartsheet = chartsheet;
    RB_INSERT(lxw_chartsheet_names, self->chartsheet_names, chartsheet_name);

    return chartsheet;

mem_error:
    free((void *) init_data.name);
    free((void *) init_data.quoted_name);
    free(chartsheet_name);
    free(chartsheet);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0xc6a0
movq $0x0, -0x88(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x3d9fc
movq -0x18(%rbp), %rdi
callq 0xcd80
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0xc3c0
movq %rax, -0x58(%rbp)
jmp 0x3da85
movl $0x7f, %edi
callq 0xcaf0
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0x3da40
movq 0x3f5da(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x286a8(%rip), %rsi     # 0x660d0
leaq 0x2dc21(%rip), %rdx     # 0x6b650
movl $0x7d3, %ecx            # imm = 0x7D3
movb $0x0, %al
callq 0xc8f0
jmp 0x3dcda
jmp 0x3da42
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0xb4(%rax), %ecx
addl $0x1, %ecx
movl $0x7f, %esi
leaq 0x2dc48(%rip), %rdx     # 0x6b6ab
movb $0x0, %al
callq 0xc5d0
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x88(%rbp), %rdi
callq 0xcd80
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0xd050
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3dae3
movq 0x3f556(%rip), %rax     # 0x7cff8
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x34(%rbp), %edi
callq 0xc400
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq %rax, %rcx
leaq 0x2dbdc(%rip), %rsi     # 0x6b6b3
movb $0x0, %al
callq 0xc8f0
jmp 0x3dcda
movl $0x1, %edi
movl $0x30, %esi
callq 0xc870
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3db26
movq 0x3f4f4(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x285c2(%rip), %rsi     # 0x660d0
leaq 0x2db3b(%rip), %rdx     # 0x6b650
movl $0x7e6, %ecx            # imm = 0x7E6
movb $0x0, %al
callq 0xc8f0
jmp 0x3dcda
jmp 0x3db28
movb $0x0, -0x7e(%rbp)
movq -0x10(%rbp), %rax
movw 0xb0(%rax), %ax
movw %ax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movb 0x88(%rax), %al
movb %al, -0x7d(%rbp)
movq -0x10(%rbp), %rax
addq $0xb8, %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
addq $0xb6, %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xcb80
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3dbbc
movq 0x3f45e(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x2852c(%rip), %rsi     # 0x660d0
leaq 0x2daa5(%rip), %rdx     # 0x6b650
movl $0x7f3, %ecx            # imm = 0x7F3
movb $0x0, %al
callq 0xc8f0
jmp 0x3dcda
jmp 0x3dbbe
movq -0x10(%rbp), %rax
movw 0xb4(%rax), %cx
addw $0x1, %cx
movw %cx, 0xb4(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x70(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
addq $0x70, %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x8(%rax)
movl $0x1, %edi
movl $0x18, %esi
callq 0xc870
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3dc4a
movq 0x3f3d0(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x2849e(%rip), %rsi     # 0x660d0
leaq 0x2da17(%rip), %rdx     # 0x6b650
movl $0x7fb, %ecx            # imm = 0x7FB
movb $0x0, %al
callq 0xc8f0
jmp 0x3dcda
jmp 0x3dc4c
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movw 0xb0(%rax), %cx
addw $0x1, %cx
movw %cx, 0xb0(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
addq $0x10, %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x3dd20
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3dd06
movq -0x60(%rbp), %rdi
callq 0xc0d0
movq -0x58(%rbp), %rdi
callq 0xc0d0
movq -0x30(%rbp), %rdi
callq 0xc0d0
movq -0x28(%rbp), %rdi
callq 0xc0d0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)