// File: /workspace/github_c_makefile_star2_O2/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 0x7994
testb %al, %al
je 0x54e1
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
callq 0x48ca
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4902
movl %eax, %ebp
testq %r15, %r15
jne 0x5474
movq %rbx, %rdi
callq 0x47bc
movq %rax, %r15
movq %r15, %rdi
callq 0x7994
testb %al, %al
je 0x54f2
cmpb $0x14, %r12b
movl %r12d, (%rsp)
ja 0x5763
movzbl %r12b, %eax
leaq 0x35c03(%rip), %rcx     # 0x3b09c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x5308
movw $0x2, %r12w
cwtd
idivw %r12w
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5308
cwtd
movw $0xfffe, %cx            # imm = 0xFFFE
idivw %cx
movl %eax, %r13d
addl %ebp, %r13d
movq %r15, %rdi
callq 0x5332
cwtd
idivw %r12w
jmp 0x574a
leaq 0x35c5c(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x54f0
leaq 0x35c4b(%rip), %rdi     # 0x3b144
movq %r15, %rsi
callq 0x7b01
jmp 0x5501
movq %rbx, %rdi
callq 0x5308
movl %eax, %r13d
negl %r13d
jmp 0x5739
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5308
subl %eax, %r13d
jmp 0x568e
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5308
subl %eax, %r13d
jmp 0x5708
movq %r15, %rdi
callq 0x5332
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5332
subl %eax, %ebp
jmp 0x5610
movq %r15, %rdi
callq 0x5332
movl %eax, %ebp
jmp 0x5610
movq %rbx, %rdi
callq 0x5332
movl %eax, %ebp
negl %ebp
jmp 0x5610
movq %r15, %rdi
callq 0x5308
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5308
movw $0xfffe, %cx            # imm = 0xFFFE
cwtd
idivw %cx
movl %eax, %r13d
addl %ebp, %r13d
jmp 0x56d7
movq %rbx, %rdi
callq 0x5308
movl %eax, %r13d
negl %r13d
jmp 0x56d7
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5308
subl %eax, %r13d
jmp 0x56d7
movq %r15, %rdi
callq 0x5332
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5332
movw $0xfffe, %cx            # imm = 0xFFFE
cwtd
idivw %cx
movl %eax, %ebp
addl %r13d, %ebp
jmp 0x5610
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0x5763
movq %rbx, %rdi
callq 0x5308
movl %eax, %r13d
negl %r13d
jmp 0x56b3
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
jmp 0x56b3
movq %r15, %rdi
callq 0x5308
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5308
cwtd
movw $0xfffe, %cx            # imm = 0xFFFE
idivw %cx
movl %eax, %r13d
addl %ebp, %r13d
jmp 0x56b3
movq %r15, %rdi
callq 0x5308
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5308
cwtd
movw $0xfffe, %cx            # imm = 0xFFFE
idivw %cx
movl %eax, %r13d
addl %ebp, %r13d
movq %r15, %rdi
callq 0x5332
movl %eax, %ebp
jmp 0x5763
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5308
subl %eax, %r13d
movq %r15, %rdi
callq 0x5332
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5332
subl %eax, %ebp
jmp 0x5763
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
xorl %ebp, %ebp
jmp 0x5763
movq %r15, %rdi
callq 0x5308
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5308
cwtd
movw $0xfffe, %cx            # imm = 0xFFFE
idivw %cx
movl %eax, %r13d
addl %ebp, %r13d
movq %rbx, %rdi
callq 0x5332
movl %eax, %ebp
negl %ebp
jmp 0x5763
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %rbx, %rdi
callq 0x5308
subl %eax, %r13d
jmp 0x5739
movq %r15, %rdi
callq 0x5308
movl %eax, %r13d
movq %r15, %rdi
callq 0x5332
movw $0x2, %cx
cwtd
idivw %cx
movl %eax, %r12d
movq %rbx, %rdi
callq 0x5332
cwtd
movw $0xfffe, %cx            # imm = 0xFFFE
idivw %cx
movl %eax, %ebp
addl %r12d, %ebp
movq %rbx, %rdi
callq 0x47bc
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 0x47df
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