// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x36caf
movq -0x8(%rbp), %rsi
leaq 0x31454(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x36cad
movq -0x10(%rbp), %rdi
callq 0xd120
testb $0x1, %al
jne 0x36cce
movq -0x10(%rbp), %rsi
leaq 0x31435(%rip), %rdi     # 0x680fc
callq 0xd410
jmp 0x36ccc
movq -0x8(%rbp), %rdi
callq 0xa8f0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x372a0
testb $0x1, %al
jne 0x36cfc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x373a0
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x37530
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
cwtl
movq -0x20(%rbp), %rcx
movswl 0x1a(%rcx), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movswl 0x1c(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x22(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8350
cwtl
movq -0x20(%rbp), %rcx
movswl 0x16(%rcx), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movswl 0x18(%rcx), %ecx
subl %ecx, %eax
movw %ax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movw 0x16(%rax), %ax
movw %ax, -0x26(%rbp)
movb $0x1, -0x27(%rbp)
movb $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzbl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2060
cmpq $0x0, %rax
je 0x36db6
movq -0x10(%rbp), %rax
movzbl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x3537c(%rip), %rsi     # 0x6c114
callq 0x20d0
cmpl $0x0, %eax
jne 0x36daa
movb -0x27(%rbp), %al
addb $0x1, %al
movb %al, -0x27(%rbp)
jmp 0x36dac
movb -0x28(%rbp), %al
addb $0x1, %al
movb %al, -0x28(%rbp)
jmp 0x36d6e
movswl -0x24(%rbp), %eax
movzbl -0x27(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rdx
movswl 0x1e(%rdx), %edx
imull %edx, %ecx
subl %ecx, %eax
movw %ax, -0x2a(%rbp)
movswl -0x2a(%rbp), %eax
movzbl -0x27(%rbp), %ecx
cltd
idivl %ecx
movw %ax, -0x2a(%rbp)
movw -0x2a(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x2a(%rbp)
movw $0x0, -0x32(%rbp)
movw $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movw $0x0, -0x2c(%rbp)
movw $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rax
movzwl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x352f4(%rip), %rsi     # 0x6c114
callq 0x20d0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x4b(%rbp)
je 0x36e4c
movq -0x40(%rbp), %rax
movzwl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2060
cmpq $0x0, %rax
setne %al
movb %al, -0x4b(%rbp)
movb -0x4b(%rbp), %al
testb $0x1, %al
jne 0x36e55
jmp 0x36e91
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl -0x34(%rbp), %ecx
movzwl -0x30(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edi
callq 0x37600
movzbl %al, %ecx
movzwl -0x2c(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x2c(%rbp)
movw -0x30(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x30(%rbp)
jmp 0x36e0d
movq -0x40(%rbp), %rax
movzwl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x36ec6
movq -0x8(%rbp), %rdi
callq 0x8350
cwtl
movswl -0x26(%rbp), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movswl 0x18(%rcx), %ecx
subl %ecx, %eax
subl $0x1, %eax
movw %ax, -0x2a(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7180
movb %al, -0x41(%rbp)
movzwl -0x30(%rbp), %eax
cmpl $0x0, %eax
je 0x370ea
movswl -0x22(%rbp), %eax
movzwl -0x30(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rdx
movswl 0x1e(%rdx), %edx
imull %edx, %ecx
subl %ecx, %eax
movw %ax, -0x44(%rbp)
movw $0x0, -0x2e(%rbp)
movw $0x0, -0x46(%rbp)
movzwl -0x46(%rbp), %eax
movzwl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jge 0x370e8
movswl -0x44(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl -0x34(%rbp), %ecx
movzwl (%rax,%rcx,2), %edi
callq 0x37600
movb %al, %cl
movl -0x50(%rbp), %eax
movzbl %cl, %ecx
imull %ecx, %eax
movzwl -0x2c(%rbp), %ecx
cltd
idivl %ecx
movw %ax, -0x4a(%rbp)
movw -0x4a(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x4a(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x1, %eax
jne 0x36fae
movzwl -0x2e(%rbp), %eax
movswl -0x44(%rbp), %ecx
imull %ecx, %eax
movzwl -0x2c(%rbp), %ecx
cltd
idivl %ecx
movzwl -0x46(%rbp), %ecx
movq -0x20(%rbp), %rdx
movswl 0x1e(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movw %ax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8310
cwtl
movq -0x20(%rbp), %rcx
movswl 0x1c(%rcx), %ecx
subl %ecx, %eax
movswl -0x48(%rbp), %ecx
subl %ecx, %eax
movswl -0x4a(%rbp), %ecx
subl %ecx, %eax
subl $0x1, %eax
movw %ax, -0x48(%rbp)
jmp 0x36fdf
movzwl -0x2e(%rbp), %eax
movswl -0x44(%rbp), %ecx
imull %ecx, %eax
movzwl -0x2c(%rbp), %ecx
cltd
idivl %ecx
movzwl -0x46(%rbp), %ecx
movq -0x20(%rbp), %rdx
movswl 0x1e(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movq -0x20(%rbp), %rcx
movswl 0x1a(%rcx), %ecx
addl %ecx, %eax
movw %ax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movswl 0x1e(%rax), %eax
cmpl $0x0, %eax
jne 0x37057
movswl -0x48(%rbp), %eax
movq -0x20(%rbp), %rcx
movswl 0x1a(%rcx), %ecx
cmpl %ecx, %eax
je 0x37057
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movw 0x4(%rax,%rcx,8), %si
movw -0x26(%rbp), %dx
movswl -0x48(%rbp), %eax
movswl -0x4a(%rbp), %ecx
addl %ecx, %eax
movw %ax, %cx
movswl -0x26(%rbp), %eax
movswl -0x2a(%rbp), %r8d
addl %r8d, %eax
movswl %si, %esi
movswl %dx, %edx
movswl %cx, %ecx
movswl %ax, %r8d
callq 0x42630
jmp 0x3709d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movzwl -0x34(%rbp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movw -0x48(%rbp), %si
movw -0x26(%rbp), %dx
movswl -0x48(%rbp), %eax
movswl -0x4a(%rbp), %ecx
addl %ecx, %eax
movw %ax, %cx
movswl -0x26(%rbp), %eax
movswl -0x2a(%rbp), %r8d
addl %r8d, %eax
movswl %si, %esi
movswl %dx, %edx
movswl %cx, %ecx
movswl %ax, %r8d
callq 0x42630
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movzwl -0x34(%rbp), %ecx
movzwl (%rax,%rcx,2), %edi
callq 0x37600
movzbl %al, %ecx
movzwl -0x2e(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x2e(%rbp)
movw -0x32(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x32(%rbp)
movw -0x34(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x34(%rbp)
movw -0x46(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x46(%rbp)
jmp 0x36f07
jmp 0x370ea
movswl -0x2a(%rbp), %ecx
movq -0x20(%rbp), %rax
movswl 0x1e(%rax), %eax
addl %eax, %ecx
addl $0x1, %ecx
movswl -0x26(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x26(%rbp)
movq -0x40(%rbp), %rax
movzwl -0x30(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2060
cmpq $0x0, %rax
jne 0x3711e
jmp 0x37148
movq -0x40(%rbp), %rax
movzwl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movw -0x32(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x32(%rbp)
jmp 0x36e01
movq -0x8(%rbp), %rdi
callq 0x7430
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)