// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_chart.c
// Function: lv_chart_set_point_count
void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
{
    LV_ASSERT_OBJ(chart, LV_OBJX_NAME);

    lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
    if(ext->point_cnt == point_cnt) return;

    lv_chart_series_t * ser;
    uint16_t point_cnt_old = ext->point_cnt;
    uint16_t i;
    lv_coord_t def = LV_CHART_POINT_DEF;

    if(point_cnt < 1) point_cnt = 1;

    LV_LL_READ_BACK(ext->series_ll, ser)
    {
        if(ser->start_point != 0) {
            lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt);
            LV_ASSERT_MEM(new_points);
            if(new_points == NULL) return;

            if(point_cnt >= point_cnt_old) {
                for(i = 0; i < point_cnt_old; i++) {
                    new_points[i] =
                        ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
                }
                for(i = point_cnt_old; i < point_cnt; i++) {
                    new_points[i] = def; /*Fill up the rest with default value*/
                }
            } else {
                for(i = 0; i < point_cnt; i++) {
                    new_points[i] =
                        ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
                }
            }

            /*Switch over pointer from old to new*/
            lv_mem_free(ser->points);
            ser->points = new_points;
        } else {
            ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt);
            LV_ASSERT_MEM(ser->points);
            if(ser->points == NULL) return;
            /*Initialize the new points*/
            if(point_cnt > point_cnt_old) {
                for(i = point_cnt_old - 1; i < point_cnt; i++) {
                    ser->points[i] = def;
                }
            }
        }

        ser->start_point = 0;
    }

    ext->point_cnt = point_cnt;

    lv_chart_refresh(chart);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0x7994
testb %al, %al
je 0x1518a
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x6747
movq %rax, 0x10(%rsp)
movzwl 0x1e(%rax), %ebx
cmpw %bp, %bx
jne 0x1519b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25fb3(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x15199
cmpw $0x2, %bp
pushq $0x1
popq %r14
cmovael %ebp, %r14d
movq 0x10(%rsp), %rdi
callq 0x27ea3
movq %rax, %r15
movl $0xffff, %eax           # imm = 0xFFFF
movl %r14d, 0xc(%rsp)
movl %r14d, %ebp
andl %eax, %ebp
movl %ebp, %r12d
addl %r12d, %r12d
leal -0x1(%rbx), %ecx
movl %ebx, %r14d
andl %eax, %ecx
movq %rcx, 0x20(%rsp)
testq %r15, %r15
je 0x152df
cmpw $0x0, 0xa(%r15)
je 0x1523a
movq %r12, %rdi
callq 0x279f9
movq %rax, %r13
movq %rax, %rdi
callq 0x7994
testb %al, %al
je 0x15304
testq %r13, %r13
je 0x1517b
cmpw %bx, 0xc(%rsp)
jae 0x15280
movq (%r15), %rdi
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x152bc
movzwl 0xa(%r15), %eax
addl %ecx, %eax
xorl %edx, %edx
divl %ebx
movzwl (%rdi,%rdx,2), %eax
movw %ax, (%r13,%rcx,2)
incq %rcx
jmp 0x15217
movq (%r15), %rdi
movq %r12, %rsi
callq 0x27ad9
movq %rax, (%r15)
movq %rax, %rdi
callq 0x7994
movq (%r15), %rsi
testb %al, %al
je 0x15315
testq %rsi, %rsi
je 0x1517b
cmpw %bx, 0xc(%rsp)
jbe 0x152c4
movq 0x20(%rsp), %rax
cmpq %rbp, %rax
jae 0x152c4
movw $0x83e8, (%rsi,%rax,2)  # imm = 0x83E8
incq %rax
jmp 0x15270
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x152a4
movq (%r15), %rsi
movzwl 0xa(%r15), %eax
addl %ecx, %eax
xorl %edx, %edx
divl %ebx
movzwl (%rsi,%rdx,2), %eax
movw %ax, (%r13,%rcx,2)
incq %rcx
jmp 0x15282
movq %r14, %rax
cmpq %rax, %rbp
je 0x152b9
movw $0x83e8, (%r13,%rax,2)  # imm = 0x83E8
incq %rax
jmp 0x152a7
movq (%r15), %rdi
callq 0x27a7a
movq %r13, (%r15)
andw $0x0, 0xa(%r15)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x27dc6
movq %rax, %r15
jmp 0x151d6
movq 0x10(%rsp), %rax
movl 0xc(%rsp), %ecx
movw %cx, 0x1e(%rax)
movq 0x18(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x150d4
leaq 0x25d35(%rip), %rdi     # 0x3b040
movq %r13, %rsi
callq 0x7b01
jmp 0x15313
leaq 0x25d24(%rip), %rdi     # 0x3b040
callq 0x7b01
jmp 0x15321