// File: /workspace/github_c_makefile_star2_O1/OnionIoT[P]lv_example/lvgl/src/lv_core/lv_obj.c
// Function: lv_obj_align
void lv_obj_align(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);

    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 - lv_obj_get_width(obj) / 2;
            new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
            break;

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

        case LV_ALIGN_IN_TOP_RIGHT:
            new_x = lv_obj_get_width(base) - lv_obj_get_width(obj);
            new_y = 0;
            break;

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

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

        case LV_ALIGN_IN_LEFT_MID:
            new_x = 0;
            new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
            break;

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

        case LV_ALIGN_OUT_TOP_LEFT:
            new_x = 0;
            new_y = -lv_obj_get_height(obj);
            break;

        case LV_ALIGN_OUT_TOP_MID:
            new_x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
            new_y = -lv_obj_get_height(obj);
            break;

        case LV_ALIGN_OUT_TOP_RIGHT:
            new_x = lv_obj_get_width(base) - lv_obj_get_width(obj);
            new_y = -lv_obj_get_height(obj);
            break;

        case LV_ALIGN_OUT_BOTTOM_LEFT:
            new_x = 0;
            new_y = lv_obj_get_height(base);
            break;

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

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

        case LV_ALIGN_OUT_LEFT_TOP:
            new_x = -lv_obj_get_width(obj);
            new_y = 0;
            break;

        case LV_ALIGN_OUT_LEFT_MID:
            new_x = -lv_obj_get_width(obj);
            new_y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
            break;

        case LV_ALIGN_OUT_LEFT_BOTTOM:
            new_x = -lv_obj_get_width(obj);
            new_y = lv_obj_get_height(base) - lv_obj_get_height(obj);
            break;

        case LV_ALIGN_OUT_RIGHT_TOP:
            new_x = lv_obj_get_width(base);
            new_y = 0;
            break;

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

        case LV_ALIGN_OUT_RIGHT_BOTTOM:
            new_x = lv_obj_get_width(base);
            new_y = lv_obj_get_height(base) - lv_obj_get_height(obj);
            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 = 0;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %ebp
movl %ecx, %r14d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
callq 0x80d4
testb %al, %al
je 0x581c
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
callq 0x4bc6
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4bfe
movl %eax, %ebp
testq %r15, %r15
jne 0x57bd
movq %rbx, %rdi
callq 0x4abf
movq %rax, %r15
movq %r15, %rdi
callq 0x80d4
testb %al, %al
je 0x582d
cmpb $0x14, %r12b
movl %r12d, (%rsp)
ja 0x5aa6
movzbl %r12b, %eax
leaq 0x398aa(%rip), %rcx     # 0x3f08c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
movq %rbx, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
jmp 0x5a6a
leaq 0x39911(%rip), %rdi     # 0x3f134
movq %rbx, %rsi
callq 0x829e
jmp 0x582b
leaq 0x39900(%rip), %rdi     # 0x3f134
movq %r15, %rsi
callq 0x829e
jmp 0x583c
movq %rbx, %rdi
callq 0x5651
movl %eax, %r13d
negl %r13d
jmp 0x5a7a
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5651
jmp 0x59c9
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5651
jmp 0x5a46
movq %r15, %rdi
callq 0x567b
movl %eax, %ebp
movq %rbx, %rdi
callq 0x567b
jmp 0x593e
movq %r15, %rdi
callq 0x567b
movl %eax, %ebp
jmp 0x5944
movq %rbx, %rdi
callq 0x567b
movl %eax, %ebp
negl %ebp
jmp 0x5944
movq %r15, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
movq %rbx, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
jmp 0x590c
movq %rbx, %rdi
callq 0x5651
movl %eax, %r13d
negl %r13d
jmp 0x5a13
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5651
subl %eax, %r13d
jmp 0x5a13
movq %r15, %rdi
callq 0x567b
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ebp
sarl %ebp
movq %rbx, %rdi
callq 0x567b
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
subl %eax, %ebp
jmp 0x5944
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0x5aa6
movq %rbx, %rdi
callq 0x5651
movl %eax, %r13d
negl %r13d
jmp 0x59f1
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
jmp 0x59f1
movq %r15, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
movq %rbx, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
jmp 0x59ee
movq %r15, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
movq %rbx, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
subl %eax, %r13d
movq %r15, %rdi
callq 0x567b
movl %eax, %ebp
jmp 0x5aa6
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5651
subl %eax, %r13d
movq %r15, %rdi
callq 0x567b
movl %eax, %ebp
movq %rbx, %rdi
callq 0x567b
jmp 0x5aa4
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
xorl %ebp, %ebp
jmp 0x5aa6
movq %r15, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %r13d
sarl %r13d
movq %rbx, %rdi
callq 0x5651
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
subl %eax, %r13d
movq %rbx, %rdi
callq 0x567b
movl %eax, %ebp
negl %ebp
jmp 0x5aa6
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5651
subl %eax, %r13d
jmp 0x5a7a
movq %r15, %rdi
callq 0x5651
movl %eax, %r13d
movq %r15, %rdi
callq 0x567b
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %ebp
sarl %ebp
movq %rbx, %rdi
callq 0x567b
movzwl %ax, %ecx
shrl $0xf, %ecx
addl %eax, %ecx
movswl %cx, %eax
sarl %eax
subl %eax, %ebp
movq %rbx, %rdi
callq 0x4abf
addl %r14d, %r13d
addw 0x20(%r15), %r13w
subw 0x20(%rax), %r13w
movl %r14d, %r12d
movl 0x4(%rsp), %r14d
addl %r14d, %ebp
addw 0x22(%r15), %bp
subw 0x22(%rax), %bp
movswl %r13w, %esi
movswl %bp, %edx
movq %rbx, %rdi
callq 0x4ae2
movl (%rsp), %eax
movb %al, 0x6c(%rbx)
movw %r12w, 0x68(%rbx)
movw %r14w, 0x6a(%rbx)
movq %r15, 0x60(%rbx)
andb $-0x3, 0x6d(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq