// File: /workspace/github_c_makefile_star2_O3/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 0x80e4
testb %al, %al
je 0x5bf4
movl %r12d, 0xc(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
movq %rbx, %rdi
callq 0x4bdd
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4c15
movl %eax, %ebp
movq %rbx, %rdi
callq 0x566d
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5697
movl %eax, %r12d
testq %r15, %r15
jne 0x5b94
movq %rbx, %rdi
callq 0x4ab5
movq %rax, %r15
movq %r15, %rdi
callq 0x80e4
testb %al, %al
je 0x5c05
movl 0xc(%rsp), %esi
cmpb $0x14, %sil
ja 0x5ce9
movzwl %r14w, %eax
movzwl %r12w, %ecx
movl %eax, %edx
shrl $0xf, %edx
addl %eax, %edx
movl %ecx, %eax
shrl $0xf, %eax
addl %ecx, %eax
movswl %dx, %r12d
movswl %ax, %r14d
shrl %r12d
shrl %r14d
movzbl %sil, %eax
leaq 0x395b3(%rip), %rcx     # 0x3f190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
negl %r12d
negl %r14d
movl %r14d, %ebp
jmp 0x5c7f
leaq 0x395e9(%rip), %rdi     # 0x3f1e4
movq %rbx, %rsi
callq 0x8294
jmp 0x5c03
leaq 0x395d8(%rip), %rdi     # 0x3f1e4
movq %r15, %rsi
callq 0x8294
jmp 0x5c14
movq %r15, %rdi
callq 0x566d
movl %eax, %r13d
jmp 0x5c56
negl %r12d
movq %r15, %rdi
callq 0x5697
movl %eax, %ebp
jmp 0x5c7c
movq %r15, %rdi
callq 0x566d
movl %eax, %r13d
jmp 0x5c9b
movq %r15, %rdi
callq 0x566d
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
subl %r12d, %r13d
negl %r14d
movl %r14d, %ebp
jmp 0x5ce9
negl %r12d
movq %r15, %rdi
callq 0x5697
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ebp
sarl %ebp
subl %r14d, %ebp
movl %r12d, %r13d
jmp 0x5ce9
movq %r15, %rdi
callq 0x566d
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
subl %r12d, %r13d
movq %r15, %rdi
callq 0x5697
movl %eax, %ebp
jmp 0x5ce6
movq %r15, %rdi
callq 0x566d
movl %eax, %r13d
jmp 0x5cce
movq %r15, %rdi
callq 0x566d
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
subl %r12d, %r13d
movq %r15, %rdi
callq 0x5697
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ebp
sarl %ebp
subl %r14d, %ebp
movq %rbx, %rdi
callq 0x4ab5
movl 0x10(%rsp), %r12d
addl %r12d, %r13d
addw 0x20(%r15), %r13w
subw 0x20(%rax), %r13w
movl 0x14(%rsp), %r14d
addl %r14d, %ebp
addw 0x22(%r15), %bp
subw 0x22(%rax), %bp
movswl %r13w, %esi
movswl %bp, %edx
movq %rbx, %rdi
callq 0x4ad8
movl 0xc(%rsp), %eax
movb %al, 0x6c(%rbx)
movw %r12w, 0x68(%rbx)
movw %r14w, 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