// File: /workspace/github_c_makefile_star2_O3/nilesr[P]dotter/./stb/stb_image_write.h
// Function: stbiw__write_hdr_scanline
void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
{
   unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
   unsigned char rgbe[4];
   float linear[3];
   int x;

   scanlineheader[2] = (width&0xff00)>>8;
   scanlineheader[3] = (width&0x00ff);

   /* skip RLE for images too small or large */
   if (width < 8 || width >= 32768) {
      for (x=0; x < width; x++) {
         switch (ncomp) {
            case 4: /* fallthrough */
            case 3: linear[2] = scanline[x*ncomp + 2];
                    linear[1] = scanline[x*ncomp + 1];
                    linear[0] = scanline[x*ncomp + 0];
                    break;
            default:
                    linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
                    break;
         }
         stbiw__linear_to_rgbe(rgbe, linear);
         s->func(s->context, rgbe, 4);
      }
   } else {
      int c,r;
      /* encode into scratch buffer */
      for (x=0; x < width; x++) {
         switch(ncomp) {
            case 4: /* fallthrough */
            case 3: linear[2] = scanline[x*ncomp + 2];
                    linear[1] = scanline[x*ncomp + 1];
                    linear[0] = scanline[x*ncomp + 0];
                    break;
            default:
                    linear[0] = linear[1] = linear[2] = scanline[x*ncomp + 0];
                    break;
         }
         stbiw__linear_to_rgbe(rgbe, linear);
         scratch[x + width*0] = rgbe[0];
         scratch[x + width*1] = rgbe[1];
         scratch[x + width*2] = rgbe[2];
         scratch[x + width*3] = rgbe[3];
      }

      s->func(s->context, scanlineheader, 4);

      /* RLE each component separately */
      for (c=0; c < 4; c++) {
         unsigned char *comp = &scratch[width*c];

         x = 0;
         while (x < width) {
            // find first run
            r = x;
            while (r+2 < width) {
               if (comp[r] == comp[r+1] && comp[r] == comp[r+2])
                  break;
               ++r;
            }
            if (r+2 >= width)
               r = width;
            // dump up to first run
            while (x < r) {
               int len = r-x;
               if (len > 128) len = 128;
               stbiw__write_dump_data(s, len, &comp[x]);
               x += len;
            }
            // if there's a run, output it
            if (r+2 < width) { // same test as what we break out of in search loop, so only true if we break'd
               // find next byte after run
               while (r < width && comp[r] == comp[x])
                  ++r;
               // output run up to r
               while (x < r) {
                  int len = r-x;
                  if (len > 127) len = 127;
                  stbiw__write_run_data(s, len, comp[x]);
                  x += len;
               }
            }
         }
      }
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r12
movl %edx, %ebp
movq %rdi, 0x28(%rsp)
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, 0x1c(%rsp)      # imm = 0x202
movw %ax, 0x1e(%rsp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jae 0x1a0c
testl %esi, %esi
jle 0x1c0c
movslq %ebp, %rbx
addl $-0x3, %ebp
movl %esi, %r13d
shlq $0x2, %rbx
leaq 0xc(%rsp), %r14
leaq 0x10(%rsp), %r15
cmpl $0x1, %ebp
ja 0x19c9
movsd 0x4(%r12), %xmm0
movsd %xmm0, 0x14(%rsp)
movss (%r12), %xmm0
jmp 0x19db
movss (%r12), %xmm0
movss %xmm0, 0x18(%rsp)
movss %xmm0, 0x14(%rsp)
movss %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x17ea
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
movl $0x4, %edx
callq *(%rax)
addq %rbx, %r12
decq %r13
jne 0x19af
jmp 0x1c0c
leal (%rsi,%rsi), %ebx
leal (%rsi,%rsi,2), %r14d
movslq %ebp, %r15
addl $-0x3, %ebp
movl %ebp, 0x30(%rsp)
movq %rsi, 0x40(%rsp)
movl %esi, %eax
movq %rax, 0x20(%rsp)
leaq (%rcx,%rax), %r13
addq %rcx, %rbx
movq %rcx, 0x38(%rsp)
addq %rcx, %r14
shlq $0x2, %r15
xorl %ebp, %ebp
cmpl $0x1, 0x30(%rsp)
ja 0x1a5a
movsd 0x4(%r12), %xmm0
movsd %xmm0, 0x14(%rsp)
movss (%r12), %xmm0
jmp 0x1a6c
movss (%r12), %xmm0
movss %xmm0, 0x18(%rsp)
movss %xmm0, 0x14(%rsp)
movss %xmm0, 0x10(%rsp)
leaq 0xc(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x17ea
movb 0xc(%rsp), %al
movq 0x38(%rsp), %rcx
movb %al, (%rcx,%rbp)
movb 0xd(%rsp), %al
movb %al, (%r13,%rbp)
movb 0xe(%rsp), %al
movb %al, (%rbx,%rbp)
movb 0xf(%rsp), %al
movb %al, (%r14,%rbp)
incq %rbp
addq %r15, %r12
cmpq %rbp, 0x20(%rsp)
movq 0x28(%rsp), %rax
jne 0x1a3e
movq 0x8(%rax), %rdi
leaq 0x1c(%rsp), %rsi
movl $0x4, %edx
callq *(%rax)
movq 0x20(%rsp), %rcx
leaq -0x3(%rcx), %rdi
xorl %r13d, %r13d
movq 0x38(%rsp), %rax
movq %rax, %r8
movq 0x40(%rsp), %rsi
movq %rdi, 0x50(%rsp)
movq %r13, 0x48(%rsp)
imulq %rcx, %r13
addq %rax, %r13
xorl %r12d, %r12d
movq %r8, 0x30(%rsp)
leal 0x2(%r12), %eax
movl %esi, %ebx
cmpl %esi, %eax
jge 0x1b30
movslq %r12d, %rax
movb (%r13,%rax), %cl
decq %rax
movl %r12d, %ebx
movb 0x2(%r8,%rax), %dl
cmpb %dl, %cl
jne 0x1b22
cmpb 0x3(%r8,%rax), %cl
je 0x1b30
incl %ebx
incq %rax
movl %edx, %ecx
cmpq %rdi, %rax
jl 0x1b12
movl %esi, %ebx
cmpl %ebx, %r12d
jge 0x1b65
movq 0x28(%rsp), %r15
movl $0x80, %r14d
movl %ebx, %ebp
subl %r12d, %ebp
cmpl %r14d, %ebp
cmovgel %r14d, %ebp
movslq %r12d, %r12
leaq (%r12,%r13), %rdx
movq %r15, %rdi
movl %ebp, %esi
callq 0x18f8
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x1b40
leal 0x2(%rbx), %eax
movq 0x40(%rsp), %rdx
cmpl %edx, %eax
jge 0x1bd5
movslq %r12d, %rax
movb (%r13,%rax), %cl
movslq %ebx, %rax
incl %ebx
cmpl %ebx, %edx
cmovgl %edx, %ebx
movq 0x20(%rsp), %rdx
movl $0x7f, %r14d
movq 0x30(%rsp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x1ba2
incq %rax
cmpq %rdx, %rax
jl 0x1b93
jmp 0x1ba4
movl %eax, %ebx
cmpl %ebx, %r12d
jge 0x1bd5
movq 0x28(%rsp), %r15
movl %ebx, %ebp
subl %r12d, %ebp
cmpl $0x7f, %ebp
cmovgel %r14d, %ebp
movslq %r12d, %r12
movzbl (%r13,%r12), %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x1898
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x1bae
movq 0x40(%rsp), %rsi
cmpl %esi, %r12d
movq 0x50(%rsp), %rdi
movq 0x30(%rsp), %r8
jl 0x1af9
movq 0x48(%rsp), %r13
incq %r13
movq 0x20(%rsp), %rcx
addq %rcx, %r8
cmpq $0x4, %r13
movq 0x38(%rsp), %rax
jne 0x1ae5
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq