// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_core/lv_obj.c
// Function: lv_obj_align_origo
void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod)
{
    LV_ASSERT_OBJ(obj, LV_OBJX_NAME);

    lv_coord_t new_x = lv_obj_get_x(obj);
    lv_coord_t new_y = lv_obj_get_y(obj);

    lv_coord_t obj_w_half = lv_obj_get_width(obj) / 2;
    lv_coord_t obj_h_half = lv_obj_get_height(obj) / 2;

    if(base == NULL) {
        base = lv_obj_get_parent(obj);
    }

    LV_ASSERT_OBJ(base, LV_OBJX_NAME);


    switch(align) {
        case LV_ALIGN_CENTER:
            new_x = lv_obj_get_width(base) / 2 - obj_w_half;
            new_y = lv_obj_get_height(base) / 2 - obj_h_half;
            break;

        case LV_ALIGN_IN_TOP_LEFT:
            new_x = -obj_w_half;
            new_y = -obj_h_half;
            break;
        case LV_ALIGN_IN_TOP_MID:
            new_x = lv_obj_get_width(base) / 2 - obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_IN_TOP_RIGHT:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_IN_BOTTOM_LEFT:
            new_x = -obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;
        case LV_ALIGN_IN_BOTTOM_MID:
            new_x = lv_obj_get_width(base) / 2 - obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_IN_BOTTOM_RIGHT:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_IN_LEFT_MID:
            new_x = -obj_w_half;
            new_y = lv_obj_get_height(base) / 2 - obj_h_half;
            break;

        case LV_ALIGN_IN_RIGHT_MID:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = lv_obj_get_height(base) / 2 - obj_h_half;
            break;

        case LV_ALIGN_OUT_TOP_LEFT:
            new_x = -obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_OUT_TOP_MID:
            new_x = lv_obj_get_width(base) / 2 - obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_OUT_TOP_RIGHT:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_OUT_BOTTOM_LEFT:
            new_x = -obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_OUT_BOTTOM_MID:
            new_x = lv_obj_get_width(base) / 2 - obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_OUT_BOTTOM_RIGHT:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_OUT_LEFT_TOP:
            new_x = -obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_OUT_LEFT_MID:
            new_x = -obj_w_half;
            new_y = lv_obj_get_height(base) / 2 - obj_h_half;
            break;

        case LV_ALIGN_OUT_LEFT_BOTTOM:
            new_x = -obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;

        case LV_ALIGN_OUT_RIGHT_TOP:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = -obj_h_half;
            break;

        case LV_ALIGN_OUT_RIGHT_MID:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = lv_obj_get_height(base) / 2 - obj_h_half;
            break;

        case LV_ALIGN_OUT_RIGHT_BOTTOM:
            new_x = lv_obj_get_width(base) - obj_w_half;
            new_y = lv_obj_get_height(base) - obj_h_half;
            break;
    }

    /*Bring together the coordination system of base and obj*/
    lv_obj_t * par        = lv_obj_get_parent(obj);
    lv_coord_t base_abs_x = base->coords.x1;
    lv_coord_t base_abs_y = base->coords.y1;
    lv_coord_t par_abs_x  = par->coords.x1;
    lv_coord_t par_abs_y  = par->coords.y1;
    new_x += x_mod + base_abs_x;
    new_y += y_mod + base_abs_y;
    new_x -= par_abs_x;
    new_y -= par_abs_y;

    lv_obj_set_pos(obj, new_x, new_y);

#if LV_USE_OBJ_REALIGN
    /*Save the last align parameters to use them in `lv_obj_realign`*/
    obj->realign.align       = align;
    obj->realign.xofs        = x_mod;
    obj->realign.yofs        = y_mod;
    obj->realign.base        = base;
    obj->realign.origo_align = 1;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
callq 0x7994
testb %al, %al
je 0x5880
movl %r14d, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
movq %rbx, %rdi
callq 0x48ca
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4902
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5308
movw $0x2, %bp
cwtd
idivw %bp
movl %eax, 0x8(%rsp)
movq %rbx, %rdi
callq 0x5332
cwtd
idivw %bp
movl %eax, %ebp
testq %r15, %r15
jne 0x583f
movq %rbx, %rdi
callq 0x47bc
movq %rax, %r15
movq %r15, %rdi
callq 0x7994
testb %al, %al
je 0x5891
cmpb $0x14, %r12b
movl %r12d, 0xc(%rsp)
ja 0x5953
movzbl %r12b, %eax
leaq 0x3588b(%rip), %rcx     # 0x3b0f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x8(%rsp), %r13d
negl %r13d
negl %ebp
movl %ebp, %r14d
jmp 0x5907
leaq 0x358bd(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x588f
leaq 0x358ac(%rip), %rdi     # 0x3b144
movq %r15, %rsi
callq 0x7b01
jmp 0x58a0
movq %r15, %rdi
callq 0x5308
jmp 0x58d9
movl 0x8(%rsp), %r13d
negl %r13d
movq %r15, %rdi
callq 0x5332
jmp 0x5901
movq %r15, %rdi
callq 0x5308
jmp 0x591a
movq %r15, %rdi
callq 0x5308
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %r13d
subl 0x8(%rsp), %r13d
negl %ebp
movl %ebp, %r14d
jmp 0x5953
movl 0x8(%rsp), %r13d
negl %r13d
movq %r15, %rdi
callq 0x5332
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %r14d
subl %ebp, %r14d
jmp 0x5953
movq %r15, %rdi
callq 0x5308
cwtd
movw $0x2, %cx
idivw %cx
movl %eax, %r13d
subl 0x8(%rsp), %r13d
movq %r15, %rdi
callq 0x5332
jmp 0x594d
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
subl 0x8(%rsp), %r13d
movq %r15, %rdi
callq 0x5332
cwtd
movw $0x2, %cx
idivw %cx
movl %eax, %r14d
subl %ebp, %r14d
movq %rbx, %rdi
callq 0x47bc
movl 0x10(%rsp), %r12d
addl %r12d, %r13d
addw 0x20(%r15), %r13w
subw 0x20(%rax), %r13w
movl 0x14(%rsp), %ebp
addl %ebp, %r14d
addw 0x22(%r15), %r14w
subw 0x22(%rax), %r14w
movswl %r13w, %esi
movswl %r14w, %edx
movq %rbx, %rdi
callq 0x47df
movl 0xc(%rsp), %eax
movb %al, 0x6c(%rbx)
movw %r12w, 0x68(%rbx)
movw %bp, 0x6a(%rbx)
movq %r15, 0x60(%rbx)
orb $0x2, 0x6d(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x5308
cwtd
movl %ebp, %r12d
movw $0x2, %bp
idivw %bp
movl %eax, %r13d
subl 0x8(%rsp), %r13d
movq %r15, %rdi
callq 0x5332
cwtd
idivw %bp
movl %eax, %r14d
subl %r12d, %r14d
jmp 0x5953