// File: /workspace/github_c_makefile_star2_O2/vlenhart[P]q3bsp/./stb_image_write.h
// Function: stbiw__write_hdr_scanline(_IO_FILE*, int, int, unsigned char*, float const*)
void stbiw__write_hdr_scanline(FILE *f, int width, int comp, unsigned char *scratch, const 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 (comp) {
            case 4: /* fallthrough */
            case 3: linear[2] = scanline[x*comp + 2];
                    linear[1] = scanline[x*comp + 1];
                    linear[0] = scanline[x*comp + 0];
                    break;
            case 2: /* fallthrough */
            case 1: linear[0] = linear[1] = linear[2] = scanline[x*comp + 0];
                    break;
         }
         stbiw__linear_to_rgbe(rgbe, linear);
         fwrite(rgbe, 4, 1, f);
      }
   } else {
      int c,r;
      /* encode into scratch buffer */
      for (x=0; x < width; x++) {
         switch(comp) {
            case 4: /* fallthrough */
            case 3: linear[2] = scanline[x*comp + 2];
                    linear[1] = scanline[x*comp + 1];
                    linear[0] = scanline[x*comp + 0];
                    break;
            case 2: /* fallthrough */
            case 1: linear[0] = linear[1] = linear[2] = scanline[x*comp + 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];
      }

      fwrite(scanlineheader, 4, 1, f);

      /* 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(f, 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(f, len, comp[x]);
                  x += len;
               }
            }
         }
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r12
movq %rdi, -0x58(%rbp)
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, -0x44(%rbp)     # imm = 0x202
movw %ax, -0x42(%rbp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jae 0x3ed4
xorl %ebx, %ebx
testl %esi, %esi
cmovgl %esi, %ebx
movslq %edx, %r15
shlq $0x2, %r15
leal -0x1(%rdx), %r13d
leaq -0x2c(%rbp), %r14
addl $-0x3, %edx
movq %rdx, -0x40(%rbp)
subq $0x1, %rbx
jb 0x40bf
cmpl $0x2, %r13d
jb 0x3e9c
cmpl $0x1, -0x40(%rbp)
ja 0x3eb1
movss 0x8(%r12), %xmm0
movss %xmm0, -0x30(%rbp)
movss 0x4(%r12), %xmm0
movss %xmm0, -0x34(%rbp)
movss (%r12), %xmm0
jmp 0x3eac
movss (%r12), %xmm0
movss %xmm0, -0x30(%rbp)
movss %xmm0, -0x34(%rbp)
movss %xmm0, -0x38(%rbp)
movq %r14, %rdi
leaq -0x38(%rbp), %rsi
callq 0x3cb4
movq %r14, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq -0x58(%rbp), %rcx
callq 0x2440
addq %r15, %r12
jmp 0x3e66
leal (%rsi,%rsi), %edi
leal (%rsi,%rsi,2), %r15d
movslq %edx, %rdx
movq %rsi, -0x70(%rbp)
movl %esi, %eax
leaq (%rcx,%rax), %rsi
movq %rsi, -0x60(%rbp)
addq %rcx, %rdi
movq %rdi, -0x50(%rbp)
movq %rcx, -0x68(%rbp)
addq %rcx, %r15
leaq (,%rdx,4), %r13
xorl %ebx, %ebx
leal -0x1(%rdx), %r14d
addl $-0x3, %edx
movq %rdx, -0x78(%rbp)
movq %rax, -0x40(%rbp)
cmpq %rbx, %rax
je 0x3f9e
cmpl $0x2, %r14d
jb 0x3f48
cmpl $0x1, -0x78(%rbp)
ja 0x3f5d
movss 0x8(%r12), %xmm0
movss %xmm0, -0x30(%rbp)
movss 0x4(%r12), %xmm0
movss %xmm0, -0x34(%rbp)
movss (%r12), %xmm0
jmp 0x3f58
movss (%r12), %xmm0
movss %xmm0, -0x30(%rbp)
movss %xmm0, -0x34(%rbp)
movss %xmm0, -0x38(%rbp)
leaq -0x2c(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3cb4
movb -0x2c(%rbp), %al
movq -0x68(%rbp), %rcx
movb %al, (%rcx,%rbx)
movb -0x2b(%rbp), %al
movq -0x60(%rbp), %rcx
movb %al, (%rcx,%rbx)
movb -0x2a(%rbp), %al
movq -0x50(%rbp), %rcx
movb %al, (%rcx,%rbx)
movb -0x29(%rbp), %al
movb %al, (%r15,%rbx)
incq %rbx
addq %r13, %r12
movq -0x40(%rbp), %rax
jmp 0x3f13
leaq -0x44(%rbp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq -0x58(%rbp), %rcx
callq 0x2440
movq -0x40(%rbp), %rsi
xorl %r13d, %r13d
movq -0x68(%rbp), %rax
movq %rax, %rdi
movq -0x70(%rbp), %rdx
cmpq $0x4, %r13
je 0x40bf
movq %r13, -0x60(%rbp)
imulq %rsi, %r13
addq %rax, %r13
xorl %ebx, %ebx
movq %rdi, -0x50(%rbp)
cmpl %edx, %ebx
jge 0x40ac
movslq %ebx, %rax
addq $0x2, %rax
movl %ebx, %r15d
cmpq %rsi, %rax
jge 0x400c
movb -0x2(%rdi,%rax), %cl
cmpb -0x1(%rdi,%rax), %cl
jne 0x4004
cmpb (%rdi,%rax), %cl
je 0x4033
incl %r15d
incq %rax
jmp 0x3ff0
movl %edx, %r15d
jmp 0x4033
movl $0x80, %eax
cmpl %eax, %r12d
cmovgel %eax, %r12d
leaq (%r14,%r13), %rdx
movq -0x58(%rbp), %rdi
movl %r12d, %esi
callq 0x3dae
addl %r12d, %r14d
movl %r14d, %ebx
movl %r15d, %r12d
movslq %ebx, %r14
subl %ebx, %r12d
jg 0x4011
leal 0x2(%r15), %eax
movq -0x70(%rbp), %rdx
cmpl %edx, %eax
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdi
jge 0x3fde
movslq %r15d, %r15
cmpq %rsi, %r15
jge 0x406a
movb (%rdi,%r15), %al
cmpb (%r13,%r14), %al
jne 0x406d
incq %r15
jmp 0x4055
movl %edx, %r15d
pushq $0x7f
popq %r14
movl %r15d, %r12d
subl %ebx, %r12d
jle 0x409b
cmpl $0x7f, %r12d
cmovgel %r14d, %r12d
movslq %ebx, %rax
movzbl (%r13,%rax), %edx
movq -0x58(%rbp), %rdi
movl %r12d, %esi
callq 0x3d5b
addl %r12d, %ebx
jmp 0x4071
movq -0x70(%rbp), %rdx
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdi
jmp 0x3fde
movq -0x60(%rbp), %r13
incq %r13
addq %rsi, %rdi
movq -0x68(%rbp), %rax
jmp 0x3fc3
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq