// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: workbook_add_worksheet
lxw_worksheet *
workbook_add_worksheet(lxw_workbook *self, const char *sheetname)
{
    lxw_sheet *sheet = NULL;
    lxw_worksheet *worksheet = NULL;
    lxw_worksheet_name *worksheet_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, "Sheet%d",
                     self->num_worksheets + 1);
        init_data.name = new_name;
        init_data.quoted_name = lxw_strdup(new_name);
    }

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

    /* Create a struct to find/store the worksheet name/pointer. */
    worksheet_name = calloc(1, sizeof(struct lxw_worksheet_name));
    GOTO_LABEL_ON_MEM_ERROR(worksheet_name, mem_error);

    /* Initialize the metadata to pass to the worksheet. */
    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;
    init_data.default_url_format = self->default_url_format;
    init_data.max_url_length = self->max_url_length;

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

    /* Add it to the worksheet list. */
    self->num_worksheets++;
    STAILQ_INSERT_TAIL(self->worksheets, worksheet, list_pointers);

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

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

    /* Store the worksheet so we can look it up by name. */
    worksheet_name->name = init_data.name;
    worksheet_name->worksheet = worksheet;
    RB_INSERT(lxw_worksheet_names, self->worksheet_names, worksheet_name);

    return worksheet;

mem_error:
    free((void *) init_data.name);
    free((void *) init_data.quoted_name);
    free(worksheet_name);
    free(worksheet);
    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 0x3d47c
movq -0x18(%rbp), %rdi
callq 0xcd80
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0xc3c0
movq %rax, -0x58(%rbp)
jmp 0x3d505
movl $0x7f, %edi
callq 0xcaf0
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0x3d4c0
movq 0x3fb5a(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x28c28(%rip), %rsi     # 0x660d0
leaq 0x2e1a1(%rip), %rdx     # 0x6b650
movl $0x77f, %ecx            # imm = 0x77F
movb $0x0, %al
callq 0xc8f0
jmp 0x3d777
jmp 0x3d4c2
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0xb2(%rax), %ecx
addl $0x1, %ecx
movl $0x7f, %esi
leaq 0x2e178(%rip), %rdx     # 0x6b65b
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 0x3d563
movq 0x3fad6(%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 0x2e10c(%rip), %rsi     # 0x6b663
movb $0x0, %al
callq 0xc8f0
jmp 0x3d777
movl $0x1, %edi
movl $0x30, %esi
callq 0xc870
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3d5a6
movq 0x3fa74(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x28b42(%rip), %rsi     # 0x660d0
leaq 0x2e0bb(%rip), %rdx     # 0x6b650
movl $0x791, %ecx            # imm = 0x791
movb $0x0, %al
callq 0xc8f0
jmp 0x3d777
jmp 0x3d5a8
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)
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movw 0xcc(%rax), %ax
movw %ax, -0x40(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xca70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3d65a
movq 0x3f9c0(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x28a8e(%rip), %rsi     # 0x660d0
leaq 0x2e007(%rip), %rdx     # 0x6b650
movl $0x7a0, %ecx            # imm = 0x7A0
movb $0x0, %al
callq 0xc8f0
jmp 0x3d777
jmp 0x3d65c
movq -0x10(%rbp), %rax
movw 0xb2(%rax), %cx
addw $0x1, %cx
movw %cx, 0xb2(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x3c0(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
addq $0x3c0, %rcx            # imm = 0x3C0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movl $0x1, %edi
movl $0x18, %esi
callq 0xc870
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3d6ee
movq 0x3f92c(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x289fa(%rip), %rsi     # 0x660d0
leaq 0x2df73(%rip), %rdx     # 0x6b650
movl $0x7a8, %ecx            # imm = 0x7A8
movb $0x0, %al
callq 0xc8f0
jmp 0x3d777
jmp 0x3d6f0
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 0x20(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x3d880
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d7a3
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