// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_btnm.c
// Function: lv_btnm_set_map
void lv_btnm_set_map(const lv_obj_t * btnm, const char * map[])
{
    LV_ASSERT_OBJ(btnm, LV_OBJX_NAME);
    LV_ASSERT_NULL(map);

    /*
     * lv_btnm_set_map is called on receipt of signals such as
     * LV_SIGNAL_CORD_CHG regardless of whether the map has changed (e.g.
     * calling lv_obj_align on the map will trigger this).
     *
     * We check if the map has changed here to avoid overwriting changes made
     * to hidden/longpress/disabled states after the map was originally set.
     *
     * TODO: separate all map set/allocation from layout code below and skip
     * set/allocation when map hasn't changed.
     */
    lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
    if(!maps_are_identical(ext->map_p, map)) {

        /*Analyze the map and create the required number of buttons*/
        allocate_btn_areas_and_controls(btnm, map);
    }
    ext->map_p = map;

    /*Set size and positions of the buttons*/
    const lv_style_t * style_bg = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG);
    lv_coord_t max_w            = lv_obj_get_width(btnm) - style_bg->body.padding.left - style_bg->body.padding.right;
    lv_coord_t max_h            = lv_obj_get_height(btnm) - style_bg->body.padding.top - style_bg->body.padding.bottom;
    lv_coord_t act_y            = style_bg->body.padding.top;

    /*Count the lines to calculate button height*/
    uint8_t line_cnt = 1;
    uint8_t li;
    for(li = 0; strlen(map[li]) != 0; li++) {
        if(strcmp(map[li], "\n") == 0) line_cnt++;
    }

    lv_coord_t btn_h = max_h - ((line_cnt - 1) * style_bg->body.padding.inner);
    btn_h            = btn_h / line_cnt;
    btn_h--; /*-1 because e.g. height = 100 means 101 pixels (0..100)*/

    /* Count the units and the buttons in a line
     * (A button can be 1,2,3... unit wide)*/
    uint16_t unit_cnt;           /*Number of units in a row*/
    uint16_t unit_act_cnt;       /*Number of units currently put in a row*/
    uint16_t btn_cnt;            /*Number of buttons in a row*/
    uint16_t i_tot          = 0; /*Act. index in the str map*/
    uint16_t btn_i          = 0; /*Act. index of button areas*/
    const char ** map_p_tmp = map;

    /*Count the units and the buttons in a line*/
    while(1) {
        unit_cnt = 0;
        btn_cnt  = 0;
        /*Count the buttons in a line*/
        while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 && strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/
            unit_cnt += get_button_width(ext->ctrl_bits[btn_i + btn_cnt]);
            btn_cnt++;
        }

        /*Make sure the last row is at the bottom of 'btnm'*/
        if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/
            btn_h = lv_obj_get_height(btnm)- act_y - style_bg->body.padding.bottom - 1;
        }

        lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm);

        /*Only deal with the non empty lines*/
        if(btn_cnt != 0) {
            /*Calculate the width of all units*/
            lv_coord_t all_unit_w = max_w - ((btn_cnt - 1) * style_bg->body.padding.inner);

            /*Set the button size and positions and set the texts*/
            uint16_t i;
            lv_coord_t act_x;

            lv_coord_t act_unit_w;
            unit_act_cnt = 0;
            for(i = 0; i < btn_cnt; i++) {
                /* one_unit_w = all_unit_w / unit_cnt
                 * act_unit_w = one_unit_w * button_width
                 * do this two operations but the multiply first to divide a greater number */
                act_unit_w = (all_unit_w * get_button_width(ext->ctrl_bits[btn_i])) / unit_cnt;
                act_unit_w--; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/

                /*Always recalculate act_x because of rounding errors */
                if(base_dir == LV_BIDI_DIR_RTL)  {
                    act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner;
                    act_x = lv_obj_get_width(btnm) - style_bg->body.padding.right - act_x - act_unit_w - 1;
                } else {
                    act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * style_bg->body.padding.inner +
                            style_bg->body.padding.left;
                }
                /* Set the button's area.
                 * If inner padding is zero then use the prev. button x2 as x1 to avoid rounding
                 * errors*/
                if(style_bg->body.padding.inner == 0 && act_x != style_bg->body.padding.left) {
                    lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, act_x + act_unit_w,
                                act_y + btn_h);
                } else {
                    lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h);
                }

                unit_act_cnt += get_button_width(ext->ctrl_bits[btn_i]);

                i_tot++;
                btn_i++;
            }
        }
        act_y += btn_h + style_bg->body.padding.inner + 1;

        if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
        map_p_tmp = &map_p_tmp[btn_cnt + 1];       /*Set the map to the next line*/
        i_tot++;                                   /*Skip the '\n'*/
    }

    lv_obj_invalidate(btnm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
callq 0x7994
testb %al, %al
je 0x1fed0
movq %r14, %rdi
callq 0x7994
testb %al, %al
je 0x1fee1
movq %r15, %rdi
callq 0x6747
movq %rax, %r12
movq (%rax), %rbx
cmpq %r14, %rbx
movq %rax, 0x20(%rsp)
je 0x1ffd3
testq %rbx, %rbx
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x1fefa
xorl %ebp, %ebp
movzwl %bp, %eax
shll $0x3, %eax
movq (%rbx,%rax), %rdi
cmpb $0x0, (%rdi)
movq (%r14,%rax), %rsi
movb (%rsi), %al
je 0x1fef2
testb %al, %al
je 0x1fefa
callq 0x20e0
incl %ebp
testl %eax, %eax
je 0x1feaa
jmp 0x1fefa
leaq 0x1b26d(%rip), %rdi     # 0x3b144
movq %r15, %rsi
callq 0x7b01
jmp 0x1fedf
leaq 0x1b25c(%rip), %rdi     # 0x3b144
movq %r14, %rsi
callq 0x7b01
jmp 0x1fef0
testb %al, %al
je 0x1ffd3
xorl %eax, %eax
xorl %ebx, %ebx
movzwl %ax, %ecx
movq (%r14,%rcx,8), %rdx
movzbl (%rdx), %esi
cmpl $0xa, %esi
je 0x1ff17
movw $0x1, %cx
testl %esi, %esi
jne 0x1ff20
jmp 0x1ff2b
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rdx)
setne %cl
movzwl %cx, %ecx
addl %ebx, %ecx
incl %eax
movl %ecx, %ebx
jmp 0x1fefe
movq %r15, %rdi
callq 0x6747
movq %rax, %r12
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x1ff4a
callq 0x27a7a
andq $0x0, 0x8(%r12)
movq 0x10(%r12), %rdi
testq %rdi, %rdi
je 0x1ff5f
callq 0x27a7a
andq $0x0, 0x10(%r12)
movzwl %bx, %r13d
leal (,%r13,8), %edi
callq 0x279f9
movq %rax, 0x8(%r12)
movq %rax, %rdi
callq 0x7994
testb %al, %al
je 0x20293
addl %r13d, %r13d
movq %r13, %rdi
callq 0x279f9
movq %rax, 0x10(%r12)
movq %rax, %rdi
callq 0x7994
testb %al, %al
je 0x202a6
movq 0x10(%r12), %rdi
xorl %eax, %eax
testq %rdi, %rdi
cmovel %eax, %ebx
cmpq $0x0, 0x8(%r12)
cmovel %eax, %ebx
movzwl %bx, %ebx
leal (%rbx,%rbx), %edx
xorl %esi, %esi
callq 0x20a0
movw %bx, 0x40(%r12)
movq 0x20(%rsp), %r12
movq %r12, %rax
movq %r14, %r12
movq %r14, (%rax)
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
callq 0x20368
movq %rax, %r13
movq %r15, %rdi
callq 0x5308
movl %eax, 0x10(%rsp)
movzwl 0x1a(%r13), %ebx
movzwl 0x1c(%r13), %ebp
movq %r15, %rdi
callq 0x5332
movq %r13, %r10
movzwl 0x16(%r13), %ecx
movq %rcx, 0x8(%rsp)
movzwl 0x18(%r13), %ecx
movb $0x1, %dl
movzbl %r14b, %esi
movq (%r12,%rsi,8), %rsi
movzbl (%rsi), %edi
cmpl $0xa, %edi
je 0x20036
testl %edi, %edi
je 0x20046
xorl %esi, %esi
jmp 0x2003e
cmpb $0x0, 0x1(%rsi)
sete %sil
addb %sil, %dl
incb %r14b
jmp 0x2001e
movzbl %dl, %esi
pushq $0x1
popq %rdx
subl %esi, %edx
imulw 0x1e(%r10), %dx
addl 0x8(%rsp), %ecx
subl %ecx, %eax
addl %edx, %eax
cwtd
idivw %si
decl %eax
movq %rax, 0x18(%rsp)
addl %ebp, %ebx
subl %ebx, 0x10(%rsp)
xorl %esi, %esi
movq %r12, %r14
movq 0x20(%rsp), %r12
movq %r10, 0x48(%rsp)
movq %r15, 0x38(%rsp)
movl %esi, 0x14(%rsp)
movzwl %si, %edx
xorl %ebp, %ebp
xorl %eax, %eax
movq %rdx, 0x40(%rsp)
movzwl %ax, %ebx
movq (%r14,%rbx,8), %rax
movzbl (%rax), %ecx
cmpl $0xa, %ecx
je 0x200a7
testl %ecx, %ecx
jne 0x200ad
jmp 0x200c8
cmpb $0x0, 0x1(%rax)
je 0x200e8
leaq (%rdx,%rdx), %rax
addq 0x10(%r12), %rax
movzwl (%rax,%rbx,2), %eax
andl $0x7, %eax
cmpw $0x1, %ax
adcl %eax, %ebp
leal 0x1(%rbx), %eax
jmp 0x20092
movq %r15, %rdi
movq %r10, %r13
callq 0x5332
movzwl 0x18(%r13), %ecx
addw 0x8(%rsp), %cx
notl %ecx
addl %eax, %ecx
movq %rcx, 0x18(%rsp)
jmp 0x200eb
movq %r10, %r13
movq %r15, %rdi
callq 0x47b9
movb %al, 0x7(%rsp)
movzwl 0x1e(%r13), %eax
testq %rbx, %rbx
movq %r13, %r10
je 0x2024f
movq %r14, 0x50(%rsp)
pushq $0x1
popq %rcx
subl %ebx, %ecx
imull %ecx, %eax
addl 0x10(%rsp), %eax
cwtl
movl %eax, 0x34(%rsp)
movzwl %bp, %eax
movl %eax, 0x30(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
addl %ecx, %eax
movl %eax, 0x2c(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x40(%rsp), %rax
cmpl %r15d, %ebx
je 0x20237
addl %r15d, %eax
movq 0x10(%r12), %rcx
movzwl %ax, %ebp
movzwl (%rcx,%rbp,2), %eax
andl $0x7, %eax
cmpw $0x1, %ax
adcl $0x0, %eax
movzbl %al, %eax
movl 0x34(%rsp), %ecx
imull %ecx, %eax
cltd
movl 0x30(%rsp), %esi
idivl %esi
movl %eax, %r13d
decl %r13d
movzwl %r14w, %eax
imull %ecx, %eax
cltd
idivl %esi
movzwl 0x1e(%r10), %ecx
movl %r15d, %r12d
imull %ecx, %r12d
addl %eax, %r12d
cmpb $0x1, 0x7(%rsp)
jne 0x201c1
movq 0x38(%rsp), %rdi
callq 0x5308
movq 0x48(%rsp), %r10
movzwl 0x1c(%r10), %r9d
addw %r13w, %r9w
addl %r12d, %r9d
notl %r9d
addl %eax, %r9d
movzwl 0x1e(%r10), %ecx
jmp 0x201c9
addw 0x1a(%r10), %r12w
movl %r12d, %r9d
movswl 0x8(%rsp), %edx
movswl 0x2c(%rsp), %r8d
testw %cx, %cx
movq 0x20(%rsp), %r12
jne 0x201e5
cmpw 0x1a(%r10), %r9w
jne 0x20221
leal (,%rbp,8), %edi
addq 0x8(%r12), %rdi
addl %r9d, %r13d
movswl %r13w, %ecx
movswl %r9w, %esi
callq 0x26818
movq 0x10(%r12), %rax
movzwl (%rax,%rbp,2), %eax
andl $0x7, %eax
cmpw $0x1, %ax
adcl %eax, %r14d
incl %r15d
movq 0x48(%rsp), %r10
jmp 0x2013b
movq 0x8(%r12), %rax
leaq (%rax,%rbp,8), %rdi
movswl -0x4(%rdi), %esi
addl %r13d, %r9d
movswl %r9w, %ecx
jmp 0x201fc
movzwl 0x1e(%r10), %eax
movl 0x14(%rsp), %esi
addl %r15d, %esi
movq 0x38(%rsp), %r15
movq 0x50(%rsp), %r14
jmp 0x20253
movl 0x14(%rsp), %esi
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rdx
addl %edx, %ecx
leal 0x1(%rax,%rcx), %eax
movq %rax, 0x8(%rsp)
leaq (%r14,%rbx,8), %r14
addq $0x8, %r14
movq -0x8(%r14), %rax
cmpb $0x0, (%rax)
jne 0x20082
movq %r15, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x493a
movq 0x8(%r12), %rsi
leaq 0x1ada1(%rip), %rdi     # 0x3b040
callq 0x7b01
jmp 0x202a4
movq 0x10(%r12), %rsi
leaq 0x1ad8e(%rip), %rdi     # 0x3b040
callq 0x7b01
jmp 0x202b7