// File: /workspace/github_cpp_makefile_star2_O3/eggnot[P]pixel_camera/matrix/lib/framebuffer.cc
// Function: rgb_matrix::internal::Framebuffer::SetPixel(int, int, unsigned char, unsigned char, unsigned char)
void Framebuffer::SetPixel(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
  if (x < 0 || x >= columns_ || y < 0 || y >= height_) return;

  const uint16_t red   = MapColor(r);
  const uint16_t green = MapColor(PANEL_SWAP_G_B_ ? b : g);
  const uint16_t blue  = MapColor(PANEL_SWAP_G_B_ ? g : b);

  const int min_bit_plane = kBitPlanes - pwm_bits_;
  IoBits *bits = ValueAt(y & row_mask_, x, min_bit_plane);

  // Manually expand the three cases for better performance.
  // TODO(hzeller): This is a bit repetetive. Test if it pays off to just
  // pre-calc rgb mask and apply.
  if (y < rows_) {
    // Parallel chain #1
    if (y < double_rows_) {   // Upper sub-panel.
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p0_r1 = (red & mask) == mask;
        bits->bits.p0_g1 = (green & mask) == mask;
        bits->bits.p0_b1 = (blue & mask) == mask;
        bits += columns_;
      }
    } else {
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p0_r2 = (red & mask) == mask;
        bits->bits.p0_g2 = (green & mask) == mask;
        bits->bits.p0_b2 = (blue & mask) == mask;
        bits += columns_;
      }
    }
#ifndef ONLY_SINGLE_CHAIN
  } else if (y >= rows_ && y < 2 * rows_) {
    // Parallel chain #2
    if (y - rows_ < double_rows_) {   // Upper sub-panel.
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p1_r1 = (red & mask) == mask;
        bits->bits.p1_g1 = (green & mask) == mask;
        bits->bits.p1_b1 = (blue & mask) == mask;
        bits += columns_;
      }
    } else {
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p1_r2 = (red & mask) == mask;
        bits->bits.p1_g2 = (green & mask) == mask;
        bits->bits.p1_b2 = (blue & mask) == mask;
        bits += columns_;
      }
    }
  } else {
    // Parallel chain #3
    if (y - 2*rows_ < double_rows_) {   // Upper sub-panel.
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p2_r1 = (red & mask) == mask;
        bits->bits.p2_g1 = (green & mask) == mask;
        bits->bits.p2_b1 = (blue & mask) == mask;
        bits += columns_;
      }
    } else {
      for (int b = min_bit_plane; b < kBitPlanes; ++b) {
        const uint16_t mask = 1 << b;
        bits->bits.p2_r2 = (red & mask) == mask;
        bits->bits.p2_g2 = (green & mask) == mask;
        bits->bits.p2_b2 = (blue & mask) == mask;
        bits += columns_;
      }
    }
#endif
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testl %esi, %esi
js 0x4368
movl %edx, %ebp
testl %edx, %edx
js 0x4368
movl %esi, %r14d
movq %rdi, %rbx
cmpl %esi, 0xc(%rdi)
jle 0x4368
cmpl %ebp, 0x8(%rbx)
jle 0x4368
movl %r9d, %r15d
movl %r8d, %r12d
movl %ecx, %r13d
movb 0x11(%rbx), %cl
cmpb $0x1, %cl
jne 0x3f3f
movb 0x42ba(%rip), %al       # 0x81d0
testb %al, %al
je 0x4377
movzbl %r13b, %ecx
movzbl 0x12(%rbx), %eax
imulq $0xc8, %rcx, %rcx
addq 0x4294(%rip), %rcx      # 0x81c8
movzwl -0x2(%rcx,%rax,2), %r13d
movb 0x11(%rbx), %cl
jmp 0x3f5f
movzbl %r13b, %edx
movzbl 0x12(%rbx), %eax
imull %eax, %edx
shrl $0x2, %edx
imull $0x147b, %edx, %r13d    # imm = 0x147B
shrl $0xe, %r13d
andl $0x7f8, %r13d           # imm = 0x7F8
testb $0x1, %cl
je 0x3f93
movb 0x4266(%rip), %al       # 0x81d0
testb %al, %al
je 0x43a8
movzbl %r12b, %ecx
movzbl 0x12(%rbx), %eax
imulq $0xc8, %rcx, %rcx
addq 0x4240(%rip), %rcx      # 0x81c8
movzwl -0x2(%rcx,%rax,2), %r12d
movb 0x11(%rbx), %cl
jmp 0x3fb2
movzbl %r12b, %edx
movzbl %al, %esi
imull %edx, %esi
shrl $0x2, %esi
imull $0x147b, %esi, %r12d    # imm = 0x147B
shrl $0xe, %r12d
andl $0x7f8, %r12d           # imm = 0x7F8
testb $0x1, %cl
je 0x3fe2
movb 0x4213(%rip), %al       # 0x81d0
testb %al, %al
je 0x43d9
movzbl %r15b, %eax
movzbl 0x12(%rbx), %ecx
imulq $0xc8, %rax, %rax
addq 0x41ed(%rip), %rax      # 0x81c8
movzwl -0x2(%rax,%rcx,2), %edx
jmp 0x3ffe
movzbl %r15b, %ecx
movzbl %al, %eax
imull %ecx, %eax
shrl $0x2, %eax
imull $0x147b, %eax, %edx     # imm = 0x147B
shrl $0xe, %edx
andl $0x7f8, %edx            # imm = 0x7F8
movzbl 0x10(%rbx), %esi
movl $0xb, %ecx
subl %esi, %ecx
movzbl 0x18(%rbx), %eax
andl %ebp, %eax
leal (%rax,%rax,4), %edi
leal (%rax,%rdi,2), %eax
addl %ecx, %eax
imull 0xc(%rbx), %eax
addl %r14d, %eax
cltq
shlq $0x2, %rax
addq 0x20(%rbx), %rax
movl (%rbx), %r8d
movl %ebp, %edi
subl %r8d, %edi
jge 0x40c3
cmpl %ebp, 0x14(%rbx)
jle 0x4160
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xf7fff77f, %r8d       # imm = 0xF7FFF77F
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %ebp, %ebp
cmpl %r10d, %r11d
sete %bpl
shll $0xb, %ebp
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %r14d
andl %edi, %r14d
xorl %r15d, %r15d
cmpl %r10d, %r14d
sete %r15b
shll $0x1b, %r15d
andl %edx, %r9d
xorl %r14d, %r14d
cmpl %r10d, %r9d
sete %r14b
shll $0x7, %r14d
orl %ebp, %r15d
orl %r14d, %r15d
orl %r11d, %r15d
movl %r15d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x4059
jmp 0x4368
addl %r8d, %r8d
movl 0x14(%rbx), %r9d
subl %r8d, %ebp
jge 0x41e4
cmpl %r9d, %edi
jge 0x426c
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xffffef9f, %r8d       # imm = 0xFFFFEF9F
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %ebp, %ebp
cmpl %r10d, %r11d
sete %bpl
shll $0xc, %ebp
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %r14d
andl %edi, %r14d
xorl %r15d, %r15d
cmpl %r10d, %r14d
sete %r15b
shll $0x5, %r15d
andl %edx, %r9d
xorl %r14d, %r14d
cmpl %r10d, %r9d
sete %r14b
shll $0x6, %r14d
orl %ebp, %r15d
orl %r14d, %r15d
orl %r11d, %r15d
movl %r15d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x40f6
jmp 0x4368
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xfffff8ff, %r8d       # imm = 0xFFFFF8FF
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %ebp, %ebp
cmpl %r10d, %r11d
sete %bpl
shll $0x8, %ebp
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %r14d
andl %edi, %r14d
xorl %r15d, %r15d
cmpl %r10d, %r14d
sete %r15b
shll $0x9, %r15d
andl %edx, %r9d
xorl %r14d, %r14d
cmpl %r10d, %r9d
sete %r14b
shll $0xa, %r14d
orl %ebp, %r15d
orl %r14d, %r15d
orl %r11d, %r15d
movl %r15d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x417a
jmp 0x4368
cmpl %r9d, %ebp
jge 0x42ed
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xffffbff3, %r8d       # imm = 0xFFFFBFF3
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %r14d, %r14d
cmpl %r10d, %r11d
sete %r14b
shll $0xe, %r14d
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %ebp
andl %edi, %ebp
xorl %r15d, %r15d
cmpl %r10d, %ebp
sete %r15b
andl %edx, %r9d
xorl %r12d, %r12d
cmpl %r10d, %r9d
sete %r12b
leal (%r14,%r15,4), %r9d
leal (%r9,%r12,8), %r9d
orl %r11d, %r9d
movl %r9d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x4207
jmp 0x4368
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xffe7dfff, %r8d       # imm = 0xFFE7DFFF
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %ebp, %ebp
cmpl %r10d, %r11d
sete %bpl
shll $0x13, %ebp
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %r14d
andl %edi, %r14d
xorl %r15d, %r15d
cmpl %r10d, %r14d
sete %r15b
shll $0xd, %r15d
andl %edx, %r9d
xorl %r14d, %r14d
cmpl %r10d, %r9d
sete %r14b
shll $0x14, %r14d
orl %ebp, %r15d
orl %r14d, %r15d
orl %r11d, %r15d
movl %r15d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x4286
jmp 0x4368
testb %sil, %sil
je 0x4368
movzwl %r13w, %esi
movzwl %r12w, %edi
movzwl %dx, %edx
movl $0xfbdeffff, %r8d       # imm = 0xFBDEFFFF
movl $0x1, %r9d
shll %cl, %r9d
movzwl %r9w, %r10d
movl %r9d, %r11d
andl %esi, %r11d
xorl %ebp, %ebp
cmpl %r10d, %r11d
sete %bpl
shll $0x1a, %ebp
movl (%rax), %r11d
andl %r8d, %r11d
movl %r9d, %r14d
andl %edi, %r14d
xorl %r15d, %r15d
cmpl %r10d, %r14d
sete %r15b
shll $0x10, %r15d
andl %edx, %r9d
xorl %r14d, %r14d
cmpl %r10d, %r9d
sete %r14b
shll $0x15, %r14d
orl %ebp, %r15d
orl %r14d, %r15d
orl %r11d, %r15d
movl %r15d, (%rax)
movslq 0xc(%rbx), %r9
leaq (%rax,%r9,4), %rax
incl %ecx
cmpl $0xb, %ecx
jne 0x4303
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e52(%rip), %rdi      # 0x81d0
callq 0x22c0
testl %eax, %eax
je 0x3f1e
callq 0x4581
movq %rax, 0x3e31(%rip)      # 0x81c8
leaq 0x3e32(%rip), %rdi      # 0x81d0
callq 0x2100
jmp 0x3f1e
leaq 0x3e21(%rip), %rdi      # 0x81d0
callq 0x22c0
testl %eax, %eax
je 0x3f72
callq 0x4581
movq %rax, 0x3e00(%rip)      # 0x81c8
leaq 0x3e01(%rip), %rdi      # 0x81d0
callq 0x2100
jmp 0x3f72
leaq 0x3df0(%rip), %rdi      # 0x81d0
callq 0x22c0
testl %eax, %eax
je 0x3fc5
callq 0x4581
movq %rax, 0x3dcf(%rip)      # 0x81c8
leaq 0x3dd0(%rip), %rdi      # 0x81d0
callq 0x2100
jmp 0x3fc5
jmp 0x440e
jmp 0x440e
movq %rax, %rbx
leaq 0x3db8(%rip), %rdi      # 0x81d0
callq 0x20f0
movq %rbx, %rdi
callq 0x22a0
nop