// File: /workspace/github_c_makefile_star2_O0/OnionIoT[P]lv_example/lvgl/src/lv_draw/lv_draw_img.c
// Function: lv_img_buf_get_px_alpha
lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
{
    if(x >= (lv_coord_t)dsc->header.w) {
        x = dsc->header.w - 1;
        LV_LOG_WARN("lv_canvas_get_px: x is too large (out of canvas)");
    } else if(x < 0) {
        x = 0;
        LV_LOG_WARN("lv_canvas_get_px: x is < 0 (out of canvas)");
    }

    if(y >= (lv_coord_t)dsc->header.h) {
        y = dsc->header.h - 1;
        LV_LOG_WARN("lv_canvas_get_px: y is too large (out of canvas)");
    } else if(y < 0) {
        y = 0;
        LV_LOG_WARN("lv_canvas_get_px: y is < 0 (out of canvas)");
    }

    uint8_t * buf_u8 = (uint8_t *)dsc->data;

    if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
        uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE;
        return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
        uint8_t bit = x & 0x7;
        x           = x >> 3;

        /* Get the current pixel.
         * dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
         * so the possible real width are 8 ,16, 24 ...*/
        uint32_t px    = ((dsc->header.w + 7) >> 3) * y + x;
        uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
        return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER;
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
        const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/

        uint8_t bit = (x & 0x3) * 2;
        x           = x >> 2;

        /* Get the current pixel.
         * dsc->header.w + 4 means rounding up to 8 because the lines are byte aligned
         * so the possible real width are 4 ,8, 12 ...*/
        uint32_t px    = ((dsc->header.w + 3) >> 2) * y + x;
        uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
        return opa_table[px_opa];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
        const uint8_t opa_table[16] = {0,  17, 34,  51, /*Opacity mapping with bpp = 4*/
                                       68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255};

        uint8_t bit = (x & 0x1) * 4;
        x           = x >> 1;

        /* Get the current pixel.
         * dsc->header.w + 1 means rounding up to 8 because the lines are byte aligned
         * so the possible real width are 2 ,4, 6 ...*/
        uint32_t px    = ((dsc->header.w + 1) >> 1) * y + x;
        uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
        return opa_table[px_opa];
    } else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
        uint32_t px = dsc->header.w * y + x;
        return buf_u8[px];
    }

    return LV_OPA_COVER;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movw %dx, %ax
movw %si, %cx
movq %rdi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movw %ax, -0x14(%rbp)
movswl -0x12(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shrl $0xa, %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
movswl %cx, %ecx
cmpl %ecx, %eax
jl 0x625e7
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
subl $0x1, %eax
movw %ax, -0x12(%rbp)
jmp 0x625f8
movswl -0x12(%rbp), %eax
cmpl $0x0, %eax
jge 0x625f6
movw $0x0, -0x12(%rbp)
jmp 0x625f8
movswl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shrl $0x15, %ecx
movswl %cx, %ecx
cmpl %ecx, %eax
jl 0x6261e
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x15, %eax
subl $0x1, %eax
movw %ax, -0x14(%rbp)
jmp 0x6262f
movswl -0x14(%rbp), %eax
cmpl $0x0, %eax
jge 0x6262d
movw $0x0, -0x14(%rbp)
jmp 0x6262f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1f, %eax
cmpl $0x5, %eax
jne 0x62687
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movswl -0x14(%rbp), %ecx
imull %ecx, %eax
imull $0x3, %eax, %eax
movswl -0x12(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x3, %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x6289a
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1f, %eax
cmpl $0xb, %eax
jne 0x6271c
movswl -0x12(%rbp), %eax
andl $0x7, %eax
movb %al, -0x25(%rbp)
movswl -0x12(%rbp), %eax
sarl $0x3, %eax
movw %ax, -0x12(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
addl $0x7, %eax
sarl $0x3, %eax
movswl -0x14(%rbp), %ecx
imull %ecx, %eax
movswl -0x12(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x25(%rbp), %edx
movl $0x7, %ecx
subl %edx, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movzbl -0x25(%rbp), %edx
movl $0x7, %ecx
subl %edx, %ecx
sarl %cl, %eax
movb %al, -0x2d(%rbp)
movzbl -0x2d(%rbp), %edx
movl $0xff, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, -0x1(%rbp)
jmp 0x6289a
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1f, %eax
cmpl $0xc, %eax
jne 0x627b3
movl 0x9882(%rip), %eax      # 0x6bfb6
movl %eax, -0x31(%rbp)
movswl -0x12(%rbp), %eax
andl $0x3, %eax
shll %eax
movb %al, -0x32(%rbp)
movswl -0x12(%rbp), %eax
sarl $0x2, %eax
movw %ax, -0x12(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
addl $0x3, %eax
sarl $0x2, %eax
movswl -0x14(%rbp), %ecx
imull %ecx, %eax
movswl -0x12(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x32(%rbp), %edx
movl $0x6, %ecx
subl %edx, %ecx
movl $0x3, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movzbl -0x32(%rbp), %edx
movl $0x6, %ecx
subl %edx, %ecx
sarl %cl, %eax
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
movb -0x31(%rbp,%rax), %al
movb %al, -0x1(%rbp)
jmp 0x6289a
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1f, %eax
cmpl $0xd, %eax
jne 0x62853
movq 0x97f4(%rip), %rax      # 0x6bfc0
movq %rax, -0x50(%rbp)
movq 0x97f1(%rip), %rax      # 0x6bfc8
movq %rax, -0x48(%rbp)
movswl -0x12(%rbp), %eax
andl $0x1, %eax
shll $0x2, %eax
movb %al, -0x51(%rbp)
movswl -0x12(%rbp), %eax
sarl %eax
movw %ax, -0x12(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
addl $0x1, %eax
sarl %eax
movswl -0x14(%rbp), %ecx
imull %ecx, %eax
movswl -0x12(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x51(%rbp), %edx
movl $0x4, %ecx
subl %edx, %ecx
movl $0xf, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movzbl -0x51(%rbp), %edx
movl $0x4, %ecx
subl %edx, %ecx
sarl %cl, %eax
movb %al, -0x59(%rbp)
movzbl -0x59(%rbp), %eax
movb -0x50(%rbp,%rax), %al
movb %al, -0x1(%rbp)
jmp 0x6289a
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1f, %eax
cmpl $0xe, %eax
jne 0x6288e
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0xa, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movswl -0x14(%rbp), %ecx
imull %ecx, %eax
movswl -0x12(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl -0x60(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x6289a
jmp 0x62890
jmp 0x62892
jmp 0x62894
jmp 0x62896
movb $-0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
popq %rbp
retq
nop