// File: /workspace/github_c_makefile_star2_O1/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
movq %rcx, 0x18(%rsp)
movl %edx, %ebp
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, 0x14(%rsp)      # imm = 0x202
movw %ax, 0x16(%rsp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %rdi, 0x28(%rsp)
jae 0x1a62
testl %esi, %esi
jle 0x1c9e
movslq %ebp, %rbx
addl $-0x3, %ebp
movl %esi, %r13d
shlq $0x2, %rbx
leaq 0x4(%rsp), %r14
leaq 0x8(%rsp), %r15
cmpl $0x1, %ebp
ja 0x1a1f
movss 0x8(%r12), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x4(%r12), %xmm0
movss %xmm0, 0xc(%rsp)
movss (%r12), %xmm0
jmp 0x1a31
movss (%r12), %xmm0
movss %xmm0, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movss %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x182d
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
movl $0x4, %edx
callq *(%rax)
addq %rbx, %r12
decq %r13
jne 0x19f8
jmp 0x1c9e
movq %rdi, %rcx
movl %esi, %edx
movq %rsi, 0x30(%rsp)
testl %esi, %esi
movq %rdx, 0x20(%rsp)
jle 0x1b36
movq 0x30(%rsp), %rax
leal (%rax,%rax), %r14d
leal (%rax,%rax,2), %r13d
movslq %ebp, %r15
addl $-0x3, %ebp
movq 0x18(%rsp), %rax
leaq (%rax,%rdx), %rcx
movq %rcx, 0x40(%rsp)
addq %rax, %r14
addq %rax, %r13
shlq $0x2, %r15
xorl %ebx, %ebx
cmpl $0x1, %ebp
ja 0x1acd
movss 0x8(%r12), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x4(%r12), %xmm0
movss %xmm0, 0xc(%rsp)
movss (%r12), %xmm0
jmp 0x1adf
movss (%r12), %xmm0
movss %xmm0, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
movss %xmm0, 0x8(%rsp)
leaq 0x4(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x182d
movb 0x4(%rsp), %al
movq 0x18(%rsp), %rcx
movb %al, (%rcx,%rbx)
movb 0x5(%rsp), %al
movq 0x40(%rsp), %rcx
movb %al, (%rcx,%rbx)
movb 0x6(%rsp), %al
movb %al, (%r14,%rbx)
movb 0x7(%rsp), %al
movb %al, (%r13,%rbx)
incq %rbx
addq %r15, %r12
movq 0x20(%rsp), %rdx
cmpq %rbx, %rdx
movq 0x28(%rsp), %rcx
jne 0x1aa6
movq 0x8(%rcx), %rdi
leaq 0x14(%rsp), %rsi
movq %rdx, %rbx
movl $0x4, %edx
callq *(%rcx)
leaq -0x3(%rbx), %rsi
movq 0x18(%rsp), %rax
leaq 0x2(%rax), %rdi
movq $0x0, 0x38(%rsp)
movq %rax, 0x48(%rsp)
movq 0x30(%rsp), %rdx
movq %rsi, 0x50(%rsp)
testl %edx, %edx
jle 0x1c7a
movq 0x38(%rsp), %r13
imulq 0x20(%rsp), %r13
addq 0x18(%rsp), %r13
xorl %r12d, %r12d
movq %rdi, 0x40(%rsp)
leal 0x2(%r12), %eax
movl %edx, %ebx
cmpl %edx, %eax
jge 0x1bbd
movslq %r12d, %rax
decq %rax
movl %r12d, %ebx
movb -0x1(%rdi,%rax), %cl
cmpb (%rdi,%rax), %cl
jne 0x1bb1
cmpb 0x1(%rdi,%rax), %cl
je 0x1bbd
incl %ebx
incq %rax
cmpq %rsi, %rax
jl 0x1ba2
movl %edx, %ebx
cmpl %ebx, %r12d
jge 0x1bf2
movq 0x28(%rsp), %r14
movl $0x80, %r15d
movl %ebx, %ebp
subl %r12d, %ebp
cmpl %r15d, %ebp
cmovgel %r15d, %ebp
movslq %r12d, %r12
leaq (%r12,%r13), %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x1938
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x1bcd
leal 0x2(%rbx), %eax
movq 0x30(%rsp), %rdx
cmpl %edx, %eax
jge 0x1c62
movslq %r12d, %rax
movb (%r13,%rax), %cl
movslq %ebx, %rax
incl %ebx
cmpl %ebx, %edx
cmovgl %edx, %ebx
movq 0x20(%rsp), %rdx
movl $0x7f, %r15d
movq 0x48(%rsp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x1c2f
incq %rax
cmpq %rdx, %rax
jl 0x1c20
jmp 0x1c31
movl %eax, %ebx
cmpl %ebx, %r12d
jge 0x1c62
movq 0x28(%rsp), %r14
movl %ebx, %ebp
subl %r12d, %ebp
cmpl $0x7f, %ebp
cmovgel %r15d, %ebp
movslq %r12d, %r12
movzbl (%r13,%r12), %edx
movq %r14, %rdi
movl %ebp, %esi
callq 0x18d8
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x1c3b
movq 0x30(%rsp), %rdx
cmpl %edx, %r12d
movq 0x50(%rsp), %rsi
movq 0x40(%rsp), %rdi
jl 0x1b8e
movq 0x38(%rsp), %rcx
incq %rcx
movq 0x20(%rsp), %rax
addq %rax, %rdi
addq %rax, 0x48(%rsp)
movq %rcx, 0x38(%rsp)
cmpq $0x4, %rcx
jne 0x1b6e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq