// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_tabview.c
// Function: lv_tabview_add_tab
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
{
    LV_ASSERT_OBJ(tabview, LV_OBJX_NAME);
    LV_ASSERT_STR(name);

    lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);

    /*Create the container page*/
    lv_obj_t * h = lv_page_create(ext->content, NULL);
    lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(ext->content));
    lv_page_set_sb_mode(h, LV_SB_MODE_AUTO);
    lv_page_set_style(h, LV_PAGE_STYLE_BG, &lv_style_transp_tight);
    lv_page_set_style(h, LV_PAGE_STYLE_SCRL, &lv_style_transp);//plain_color);

    if(page_signal == NULL) page_signal = lv_obj_get_signal_cb(h);
    if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_cb(lv_page_get_scrl(h));
    lv_obj_set_signal_cb(h, tabpage_signal);
    lv_obj_set_signal_cb(lv_page_get_scrl(h), tabpage_scrl_signal);

    /*Extend the button matrix map with the new name*/
    char * name_dm;
    name_dm = lv_mem_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */
    LV_ASSERT_MEM(name_dm);
    if(name_dm == NULL) return NULL;
    strcpy(name_dm, name);

    ext->tab_cnt++;

    switch(ext->btns_pos) {
        case LV_TABVIEW_BTNS_POS_TOP:
        case LV_TABVIEW_BTNS_POS_BOTTOM:
            ext->tab_name_ptr = lv_mem_realloc((void*)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
            break;
        case LV_TABVIEW_BTNS_POS_LEFT:
        case LV_TABVIEW_BTNS_POS_RIGHT:
            ext->tab_name_ptr = lv_mem_realloc((void*)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2));
            break;
    }

    LV_ASSERT_MEM(ext->tab_name_ptr);
    if(ext->tab_name_ptr == NULL) return NULL;

    /* FIXME: It is not possible yet to switch tab button position from/to top/bottom from/to left/right at runtime.
     * Method: clean extra \n when switch from LV_TABVIEW_BTNS_POS_LEFT or LV_TABVIEW_BTNS_POS_RIGHT
     * to LV_TABVIEW_BTNS_POS_TOP or LV_TABVIEW_BTNS_POS_BOTTOM.
     */
    switch(ext->btns_pos) {
        case LV_TABVIEW_BTNS_POS_TOP:
        case LV_TABVIEW_BTNS_POS_BOTTOM:
            ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm;
            ext->tab_name_ptr[ext->tab_cnt]     = "";
            break;
        case LV_TABVIEW_BTNS_POS_LEFT:
        case LV_TABVIEW_BTNS_POS_RIGHT:
            if(ext->tab_cnt == 1) {
                ext->tab_name_ptr[0] = name_dm;
                ext->tab_name_ptr[1] = "";
            } else {
                ext->tab_name_ptr[ext->tab_cnt * 2 - 3] = "\n";
                ext->tab_name_ptr[ext->tab_cnt * 2 - 2] = name_dm;
                ext->tab_name_ptr[ext->tab_cnt * 2 - 1] = "";
            }
            break;
    }

    /* The button matrix's map still points to the old `tab_name_ptr` which might be freed by
     * `lv_mem_realloc`. So make its current map invalid*/
    lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
    btnm_ext->map_p          = NULL;

    lv_btnm_set_map(ext->btns, ext->tab_name_ptr);
    lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_NO_REPEAT);

    /*Modify the indicator size*/
    const lv_style_t * style_tabs = lv_obj_get_style(ext->btns);
    lv_coord_t indic_size;
    lv_coord_t max_h, btn_h, act_y;

    switch(ext->btns_pos) {
        case LV_TABVIEW_BTNS_POS_TOP:
        case LV_TABVIEW_BTNS_POS_BOTTOM:
            indic_size = (lv_obj_get_width(tabview) - style_tabs->body.padding.inner * (ext->tab_cnt - 1) -
                          style_tabs->body.padding.left - style_tabs->body.padding.right) /
                         ext->tab_cnt;
            lv_obj_set_width(ext->indic, indic_size);
            lv_obj_set_x(ext->indic, indic_size * ext->tab_cur + style_tabs->body.padding.inner * ext->tab_cur +
                                         style_tabs->body.padding.left);
            break;
        case LV_TABVIEW_BTNS_POS_LEFT:
        case LV_TABVIEW_BTNS_POS_RIGHT:
            max_h = lv_obj_get_height(ext->btns) - style_tabs->body.padding.top - style_tabs->body.padding.bottom;
            btn_h = max_h - ((ext->tab_cnt - 1) * style_tabs->body.padding.inner);
            btn_h = btn_h / ext->tab_cnt;
            btn_h--; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/
            act_y = style_tabs->body.padding.top + ext->tab_cur * (btn_h + style_tabs->body.padding.inner);

            lv_obj_set_height(ext->indic, btn_h);
            lv_obj_set_y(ext->indic, act_y);
            break;
    }

    /*Set the first btn as active*/
    if(ext->tab_cnt == 1) {
        ext->tab_cur = 0;
    }

    tabview_realign(tabview); /*Set the size of the pages, tab buttons and indicator*/

    lv_tabview_set_tab_act(tabview, ext->tab_cur, false);

    return h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x1c86f
movq -0x10(%rbp), %rsi
leaq 0x4b894(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x1c86d
movq -0x18(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x1c88e
movq -0x18(%rbp), %rsi
leaq 0x4b875(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x1c88c
movq -0x10(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3c400
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8310
movw %ax, -0x4a(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x8350
movq -0x58(%rbp), %rdi
movw -0x4a(%rbp), %cx
movswl %cx, %esi
movswl %ax, %edx
callq 0x8180
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x3dec0
movq -0x28(%rbp), %rdi
xorl %esi, %esi
leaq 0x6c898(%rip), %rdx     # 0x89198
callq 0x3dff0
movq -0x28(%rbp), %rdi
movl $0x1, %esi
leaq 0x6c7f3(%rip), %rdx     # 0x89108
callq 0x3dff0
cmpq $0x0, 0x6cae6(%rip)     # 0x89408
jne 0x1c934
movq -0x28(%rbp), %rdi
callq 0xa830
movq %rax, 0x6cad4(%rip)     # 0x89408
cmpq $0x0, 0x6cad4(%rip)     # 0x89410
jne 0x1c956
movq -0x28(%rbp), %rdi
callq 0x3e970
movq %rax, %rdi
callq 0xa830
movq %rax, 0x6caba(%rip)     # 0x89410
movq -0x28(%rbp), %rdi
leaq 0x56f(%rip), %rsi       # 0x1ced0
callq 0x9cc0
movq -0x28(%rbp), %rdi
callq 0x3e970
movq %rax, %rdi
leaq 0x657(%rip), %rsi       # 0x1cfd0
callq 0x9cc0
movq -0x18(%rbp), %rdi
callq 0x2060
movq %rax, %rdi
addq $0x1, %rdi
callq 0x44d20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x1c9b6
movq -0x30(%rbp), %rsi
leaq 0x4b695(%rip), %rdi     # 0x68044
callq 0xd410
jmp 0x1c9b4
cmpq $0x0, -0x30(%rbp)
jne 0x1c9ca
movq $0x0, -0x8(%rbp)
jmp 0x1cd9b
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2040
movq -0x20(%rbp), %rax
movw 0x26(%rax), %cx
incw %cx
movw %cx, 0x26(%rax)
movq -0x20(%rbp), %rax
movb 0x2a(%rax), %al
shrb $0x5, %al
andb $0x3, %al
movzbl %al, %ecx
movl %ecx, -0x5c(%rbp)
subb $0x2, %al
jb 0x1ca0b
jmp 0x1c9fe
movl -0x5c(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x1ca37
jmp 0x1ca60
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x44f70
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x1ca60
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %eax
shll %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x44f70
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0xd120
testb $0x1, %al
jne 0x1ca87
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
leaq 0x4b5c4(%rip), %rdi     # 0x68044
callq 0xd410
jmp 0x1ca85
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x1ca9f
movq $0x0, -0x8(%rbp)
jmp 0x1cd9b
movq -0x20(%rbp), %rax
movb 0x2a(%rax), %al
shrb $0x5, %al
andb $0x3, %al
movzbl %al, %ecx
movl %ecx, -0x60(%rbp)
subb $0x2, %al
jb 0x1cac7
jmp 0x1cab7
movl -0x60(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x1cb05
jmp 0x1cb9e
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
leaq 0x4f619(%rip), %rdx     # 0x6c115
movq %rdx, (%rax,%rcx,8)
jmp 0x1cb9e
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %eax
cmpl $0x1, %eax
jne 0x1cb36
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
leaq 0x4f5e5(%rip), %rcx     # 0x6c115
movq %rcx, 0x8(%rax)
jmp 0x1cb9c
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
shll %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
leaq 0x4f5bf(%rip), %rdx     # 0x6c114
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
shll %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
leaq 0x4f57d(%rip), %rdx     # 0x6c115
movq %rdx, (%rax,%rcx,8)
jmp 0x1cb9e
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xa8f0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rsi
callq 0x36c80
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movzwl 0x24(%rax), %esi
movl $0x10, %edx
callq 0x377b0
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0xa080
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movb 0x2a(%rax), %al
shrb $0x5, %al
andb $0x3, %al
movzbl %al, %ecx
movl %ecx, -0x64(%rbp)
subb $0x2, %al
jb 0x1cc1a
jmp 0x1cc06
movl -0x64(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x1ccb3
jmp 0x1cd60
movq -0x10(%rbp), %rdi
callq 0x8310
cwtl
movq -0x40(%rbp), %rcx
movswl 0x1e(%rcx), %ecx
movq -0x20(%rbp), %rdx
movzwl 0x26(%rdx), %edx
subl $0x1, %edx
imull %edx, %ecx
subl %ecx, %eax
movq -0x40(%rbp), %rcx
movswl 0x1a(%rcx), %ecx
subl %ecx, %eax
movq -0x40(%rbp), %rcx
movswl 0x1c(%rcx), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
cltd
idivl %ecx
movw %ax, -0x42(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movswl -0x42(%rbp), %esi
callq 0x8430
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movswl -0x42(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x24(%rcx), %ecx
imull %ecx, %eax
movq -0x40(%rbp), %rcx
movswl 0x1e(%rcx), %ecx
movq -0x20(%rbp), %rdx
movzwl 0x24(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movq -0x40(%rbp), %rcx
movswl 0x1a(%rcx), %ecx
addl %ecx, %eax
movswl %ax, %esi
callq 0x80b0
jmp 0x1cd60
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x8350
cwtl
movq -0x40(%rbp), %rcx
movswl 0x16(%rcx), %ecx
subl %ecx, %eax
movq -0x40(%rbp), %rcx
movswl 0x18(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x44(%rbp)
movswl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
subl $0x1, %ecx
movq -0x40(%rbp), %rdx
movswl 0x1e(%rdx), %edx
imull %edx, %ecx
subl %ecx, %eax
movw %ax, -0x46(%rbp)
movswl -0x46(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x26(%rcx), %ecx
cltd
idivl %ecx
movw %ax, -0x46(%rbp)
movw -0x46(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x46(%rbp)
movq -0x40(%rbp), %rax
movswl 0x16(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x24(%rcx), %ecx
movswl -0x46(%rbp), %edx
movq -0x40(%rbp), %rsi
movswl 0x1e(%rsi), %esi
addl %esi, %edx
imull %edx, %ecx
addl %ecx, %eax
movw %ax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movswl -0x46(%rbp), %esi
callq 0x84a0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movswl -0x48(%rbp), %esi
callq 0x8120
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %eax
cmpl $0x1, %eax
jne 0x1cd77
movq -0x20(%rbp), %rax
movw $0x0, 0x24(%rax)
movq -0x10(%rbp), %rdi
callq 0x1d0e0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
xorl %edx, %edx
movzwl 0x24(%rax), %esi
callq 0x1da50
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)