// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_lmeter.c
// Function: lv_lmeter_design
static bool lv_lmeter_design(lv_obj_t * lmeter, const lv_area_t * mask, lv_design_mode_t mode)
{
    /*Return false if the object is not covers the mask_p area*/
    if(mode == LV_DESIGN_COVER_CHK) {
        return false;
    }
    /*Draw the object*/
    else if(mode == LV_DESIGN_DRAW_MAIN) {
        lv_lmeter_ext_t * ext    = lv_obj_get_ext_attr(lmeter);
        const lv_style_t * style = lv_obj_get_style(lmeter);
        lv_opa_t opa_scale       = lv_obj_get_opa_scale(lmeter);
        lv_style_t style_tmp;
        lv_style_copy(&style_tmp, style);

#if LV_USE_GROUP
        lv_group_t * g = lv_obj_get_group(lmeter);
        if(lv_group_get_focused(g) == lmeter) {
            style_tmp.line.width += 1;
        }
#endif

        lv_coord_t r_out = lv_obj_get_width(lmeter) / 2;
        lv_coord_t r_in  = r_out - style->body.padding.left;
        if(r_in < 1) r_in = 1;

        lv_coord_t x_ofs  = lv_obj_get_width(lmeter) / 2 + lmeter->coords.x1;
        lv_coord_t y_ofs  = lv_obj_get_height(lmeter) / 2 + lmeter->coords.y1;
        int16_t angle_ofs = ext->angle_ofs + 90 + (360 - ext->scale_angle) / 2;
        int16_t level =
            (int32_t)((int32_t)(ext->cur_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value);
        uint8_t i;

        style_tmp.line.color = style->body.main_color;

        /*Calculate every coordinate in a bigger size to make rounding later*/
        r_out = r_out << LV_LMETER_LINE_UPSCALE;
        r_in  = r_in << LV_LMETER_LINE_UPSCALE;

        for(i = 0; i < ext->line_cnt; i++) {
            /*Calculate the position a scale label*/
            int16_t angle = (i * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs;

            lv_coord_t y_out = (int32_t)((int32_t)lv_trigo_sin(angle) * r_out) >> LV_TRIGO_SHIFT;
            lv_coord_t x_out = (int32_t)((int32_t)lv_trigo_sin(angle + 90) * r_out) >> LV_TRIGO_SHIFT;
            lv_coord_t y_in  = (int32_t)((int32_t)lv_trigo_sin(angle) * r_in) >> LV_TRIGO_SHIFT;
            lv_coord_t x_in  = (int32_t)((int32_t)lv_trigo_sin(angle + 90) * r_in) >> LV_TRIGO_SHIFT;

            /*Rounding*/
            x_out = lv_lmeter_coord_round(x_out);
            x_in  = lv_lmeter_coord_round(x_in);
            y_out = lv_lmeter_coord_round(y_out);
            y_in  = lv_lmeter_coord_round(y_in);

            lv_point_t p1;
            lv_point_t p2;

            p2.x = x_in + x_ofs;
            p2.y = y_in + y_ofs;

            p1.x = x_out + x_ofs;
            p1.y = y_out + y_ofs;

            if(i >= level)
                style_tmp.line.color = style->line.color;
            else {
                style_tmp.line.color =
                    lv_color_mix(style->body.grad_color, style->body.main_color, (255 * i) / ext->line_cnt);
            }

            lv_draw_line(&p1, &p2, mask, &style_tmp, opa_scale);
        }

    }
    /*Post draw when the children are drawn*/
    else if(mode == LV_DESIGN_DRAW_POST) {
    }

    return true;
}

// Assembly:
testl %edx, %edx
jne 0x22e25
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl %edx, 0x24(%rsp)
callq 0x6747
movq %rax, %r13
movq %rbx, %rdi
callq 0x6316
movq %rax, %rbp
movq %rbx, %rdi
callq 0x6649
movb %al, 0xc(%rsp)
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x74d4
movq %rbx, %rdi
callq 0x4b8e
movq %rax, %rdi
callq 0x29b8
cmpq %rbx, %rax
jne 0x22b74
incw 0x9e(%rsp)
movq %rbx, %rdi
callq 0x5308
movw $0x2, %r14w
cwtd
idivw %r14w
movl %eax, %r15d
movl %eax, %ecx
subw 0x1a(%rbp), %cx
cmpw %r14w, %cx
movq %rbp, 0x18(%rsp)
pushq $0x1
popq %rbp
cmovgel %ecx, %ebp
movq %rbx, %rdi
callq 0x5308
cwtd
idivw %r14w
addw 0x20(%rbx), %ax
movl %eax, 0x3c(%rsp)
movq %rbx, %rdi
callq 0x5332
cwtd
idivw %r14w
addw 0x22(%rbx), %ax
movl %eax, 0x38(%rsp)
movzwl 0x2(%r13), %ecx
movzwl (%r13), %edx
movl $0x168, %eax            # imm = 0x168
subl %edx, %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
addl %ecx, %eax
addl $0x5a, %eax
movq %rax, 0x58(%rsp)
movswl 0x6(%r13), %eax
movswl 0x8(%r13), %edx
subl %edx, %eax
movzwl 0x4(%r13), %ecx
imull %ecx, %eax
movswl 0xa(%r13), %esi
subl %edx, %esi
cltd
idivl %esi
movq 0x18(%rsp), %rdx
movzwl 0x2(%rdx), %edx
leaq 0x60(%rsp), %rsi
movw %dx, 0x3c(%rsi)
shll $0x5, %r15d
shll $0x5, %ebp
movswl %r15w, %edx
movswl %bp, %esi
addl %edx, %edx
movl %edx, 0x34(%rsp)
addl %esi, %esi
movl %esi, 0x30(%rsp)
cwtl
movl %eax, 0x2c(%rsp)
movzbl 0xc(%rsp), %eax
movl %eax, 0x28(%rsp)
xorl %eax, %eax
movq %r12, 0x50(%rsp)
movq %r13, 0x48(%rsp)
movl 0x34(%rsp), %r15d
movzbl %al, %edx
movzwl %cx, %ecx
cmpl %ecx, %edx
jae 0x22e10
movl %eax, 0xc(%rsp)
movzwl (%r13), %eax
imull %edx, %eax
decl %ecx
movl %edx, 0x44(%rsp)
xorl %edx, %edx
divl %ecx
movl %eax, %ebx
movq 0x58(%rsp), %rbp
leal (%rbx,%rbp), %eax
movswl %ax, %r12d
movl %r12d, %edi
callq 0x28d8c
movswl %ax, %r14d
leal (%rbx,%rbp), %eax
addl $0x5a, %eax
movswl %ax, %ebx
movl %ebx, %edi
callq 0x28d8c
movswl %ax, %ebp
movl %r12d, %edi
callq 0x28d8c
movswl %ax, %r12d
movl %ebx, %edi
callq 0x28d8c
movswl %ax, %r13d
imull %r15d, %ebp
sarl $0x10, %ebp
movl %ebp, %edi
callq 0x2308d
movl %eax, 0x40(%rsp)
movl 0x30(%rsp), %ebx
imull %ebx, %r13d
sarl $0x10, %r13d
movl %r13d, %edi
callq 0x2308d
movl %eax, %ebp
imull %r15d, %r14d
sarl $0x10, %r14d
movl %r14d, %edi
callq 0x2308d
movl %eax, %r14d
imull %ebx, %r12d
sarl $0x10, %r12d
movl %r12d, %edi
callq 0x2308d
movl 0x3c(%rsp), %ecx
addl %ecx, %ebp
movw %bp, 0x10(%rsp)
movl 0x38(%rsp), %edx
addl %edx, %eax
movw %ax, 0x12(%rsp)
movl 0x40(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x14(%rsp)
addl %edx, %r14d
movl 0x44(%rsp), %eax
movw %r14w, 0x16(%rsp)
cmpl %eax, 0x2c(%rsp)
jle 0x22dc9
imull $0xff, %eax, %eax
xorl %edx, %edx
movq 0x48(%rsp), %r13
divw 0x4(%r13)
movq 0x18(%rsp), %rcx
movzwl 0x4(%rcx), %edx
movzwl 0x2(%rcx), %ecx
movl %edx, %edi
shrl $0xb, %edi
movl $0xff, %r9d
andl %r9d, %eax
imull %eax, %edi
movl %ecx, %esi
shrl $0xb, %esi
movl %edx, %r8d
shrl $0x5, %r8d
andl $0x3f, %r8d
imull %eax, %r8d
andl $0x1f, %edx
imull %eax, %edx
xorl %r9d, %eax
imull %eax, %esi
addl %edi, %esi
andl $0xffff3f00, %esi       # imm = 0xFFFF3F00
movl %ecx, %edi
shrl $0x5, %edi
andl $0x3f, %edi
imull %eax, %edi
addl %r8d, %edi
shrl $0x3, %edi
andl $0x7e0, %edi            # imm = 0x7E0
andl $0x1f, %ecx
imull %eax, %ecx
addl %edx, %ecx
shrl $0x8, %ecx
andl $0x1f, %ecx
leal (%rcx,%rsi,8), %eax
orl %edi, %eax
movq 0x50(%rsp), %r12
jmp 0x22ddc
movq 0x18(%rsp), %rax
movzwl 0x3c(%rax), %eax
movq 0x50(%rsp), %r12
movq 0x48(%rsp), %r13
movw %ax, 0x9c(%rsp)
leaq 0x14(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
movl 0x28(%rsp), %r8d
callq 0x37138
movl 0xc(%rsp), %eax
incb %al
movzwl 0x4(%r13), %ecx
jmp 0x22c55
movl 0x24(%rsp), %edx
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
cmpb $0x2, %dl
setne %al
retq