// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %r8, %r12
movq %rdi, -0x68(%rbp)
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, -0x54(%rbp)     # imm = 0x202
movw %ax, -0x52(%rbp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jae 0x4afa
testl %esi, %esi
jle 0x4d9d
movq %rdx, %r14
movslq %r14d, %rbx
movl %esi, %r13d
shlq $0x2, %rbx
leal -0x1(%rdx), %r15d
addl $-0x3, %r14d
cmpl $0x2, %r15d
jb 0x4a36
cmpl $0x1, %r14d
movss -0x40(%rbp), %xmm1
movss -0x48(%rbp), %xmm2
movss -0x38(%rbp), %xmm3
ja 0x4a42
movss 0x8(%r12), %xmm1
movss (%r12), %xmm2
movss 0x4(%r12), %xmm3
jmp 0x4a42
movss (%r12), %xmm1
movaps %xmm1, %xmm3
movaps %xmm1, %xmm2
movaps %xmm3, %xmm4
maxss %xmm1, %xmm4
movaps %xmm2, %xmm0
maxss %xmm4, %xmm0
xorps %xmm5, %xmm5
cvtss2sd %xmm0, %xmm5
movaps %xmm1, %xmm4
movsd 0xd77e(%rip), %xmm1     # 0x121e0
ucomisd %xmm5, %xmm1
movss %xmm4, -0x40(%rbp)
movss %xmm2, -0x48(%rbp)
movss %xmm3, -0x38(%rbp)
jbe 0x4a83
movb $0x0, -0x2b(%rbp)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
jmp 0x4ac9
leaq -0x80(%rbp), %rdi
movss %xmm0, -0x50(%rbp)
callq 0x2090
movb -0x80(%rbp), %al
mulss 0xd740(%rip), %xmm0     # 0x121dc
divss -0x50(%rbp), %xmm0
movss -0x48(%rbp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movss -0x38(%rbp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movb %dl, -0x2b(%rbp)
mulss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %edx
addb $-0x80, %al
movb %cl, -0x2c(%rbp)
movb %al, -0x29(%rbp)
movb %dl, -0x2a(%rbp)
movl $0x4, %esi
movl $0x1, %edx
leaq -0x2c(%rbp), %rdi
movq -0x68(%rbp), %rcx
callq 0x2410
addq %rbx, %r12
decq %r13
jne 0x4a05
jmp 0x4d9d
leal (%rsi,%rsi), %r14d
leal (%rsi,%rsi,2), %r15d
movq %rsi, -0x48(%rbp)
movl %esi, %eax
movslq %edx, %rdx
leaq (%rcx,%rax), %r10
addq %rcx, %r14
movq %rcx, -0x78(%rbp)
addq %rcx, %r15
leaq (,%rdx,4), %r11
xorl %r13d, %r13d
leal -0x1(%rdx), %ebx
movsd 0xd6b1(%rip), %xmm1     # 0x121e0
addl $-0x3, %edx
movq %rdx, -0x98(%rbp)
movq %rax, -0x60(%rbp)
movq %r10, -0x90(%rbp)
movl %ebx, -0x7c(%rbp)
cmpl $0x2, %ebx
jb 0x4b6b
cmpl $0x1, -0x98(%rbp)
ja 0x4b77
movss 0x8(%r12), %xmm2
movss (%r12), %xmm3
movss 0x4(%r12), %xmm4
jmp 0x4b77
movss (%r12), %xmm2
movaps %xmm2, %xmm4
movaps %xmm2, %xmm3
movaps %xmm4, %xmm5
maxss %xmm2, %xmm5
movaps %xmm3, %xmm0
maxss %xmm5, %xmm0
xorps %xmm5, %xmm5
cvtss2sd %xmm0, %xmm5
ucomisd %xmm5, %xmm1
jbe 0x4b9c
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
xorl %esi, %esi
jmp 0x4c16
leaq -0x84(%rbp), %rdi
movq %r11, %rbx
movss %xmm2, -0x40(%rbp)
movss %xmm3, -0x38(%rbp)
movss %xmm4, -0x50(%rbp)
movss %xmm0, -0x70(%rbp)
callq 0x2090
movss -0x50(%rbp), %xmm4
movss -0x38(%rbp), %xmm3
movss -0x40(%rbp), %xmm2
movq %rbx, %r11
movl -0x7c(%rbp), %ebx
movq -0x90(%rbp), %r10
movb -0x84(%rbp), %al
mulss 0xd5f3(%rip), %xmm0     # 0x121dc
divss -0x70(%rbp), %xmm0
movaps %xmm3, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movaps %xmm4, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movsd 0xd5d4(%rip), %xmm1     # 0x121e0
mulss %xmm2, %xmm0
cvttss2si %xmm0, %esi
addb $-0x80, %al
movq -0x78(%rbp), %rdi
movb %dl, (%rdi,%r13)
movb %cl, (%r10,%r13)
movb %sil, (%r14,%r13)
movb %al, (%r15,%r13)
incq %r13
addq %r11, %r12
movq -0x60(%rbp), %rax
cmpq %r13, %rax
jne 0x4b47
leaq -0x54(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq -0x68(%rbp), %rcx
callq 0x2410
movq -0x60(%rbp), %rcx
leaq -0x3(%rcx), %rdi
xorl %ebx, %ebx
movq -0x78(%rbp), %rax
movq %rax, %r8
movq -0x48(%rbp), %rsi
movq %rdi, -0x50(%rbp)
movq %rbx, -0x70(%rbp)
movq %rbx, %r9
imulq %rcx, %r9
addq %rax, %r9
xorl %r15d, %r15d
movq %r9, -0x40(%rbp)
movq %r8, -0x38(%rbp)
leal 0x2(%r15), %eax
movl %esi, %r14d
cmpl %esi, %eax
jge 0x4cbe
movslq %r15d, %rax
movb (%r9,%rax), %cl
decq %rax
movl %r15d, %r14d
movb 0x2(%r8,%rax), %dl
cmpb %dl, %cl
jne 0x4cae
cmpb 0x3(%r8,%rax), %cl
je 0x4cbe
incl %r14d
incq %rax
movl %edx, %ecx
cmpq %rdi, %rax
jl 0x4c9e
movl %esi, %r14d
cmpl %r14d, %r15d
jge 0x4cf7
movq -0x68(%rbp), %r13
movl $0x80, %ebx
movl %r14d, %r12d
subl %r15d, %r12d
cmpl %ebx, %r12d
cmovgel %ebx, %r12d
movslq %r15d, %r15
leaq (%r9,%r15), %rdx
movq %r13, %rdi
movl %r12d, %esi
callq 0x494b
movq -0x40(%rbp), %r9
addl %r12d, %r15d
cmpl %r14d, %r15d
jl 0x4ccc
leal 0x2(%r14), %eax
movq -0x48(%rbp), %rdx
cmpl %edx, %eax
jge 0x4d6c
movslq %r15d, %rax
movb (%r9,%rax), %cl
movslq %r14d, %rax
incl %r14d
cmpl %r14d, %edx
cmovgl %edx, %r14d
movq -0x60(%rbp), %rdx
movl $0x7f, %ebx
movq -0x38(%rbp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x4d33
incq %rax
cmpq %rdx, %rax
jl 0x4d24
jmp 0x4d36
movl %eax, %r14d
cmpl %r14d, %r15d
jge 0x4d6c
movq -0x68(%rbp), %r13
movl %r14d, %r12d
subl %r15d, %r12d
cmpl $0x7f, %r12d
cmovgel %ebx, %r12d
movslq %r15d, %r15
movzbl (%r9,%r15), %edx
movq %r13, %rdi
movl %r12d, %esi
callq 0x48f8
movq -0x40(%rbp), %r9
addl %r12d, %r15d
cmpl %r14d, %r15d
jl 0x4d3f
movq -0x48(%rbp), %rsi
cmpl %esi, %r15d
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %r8
jl 0x4c86
movq -0x70(%rbp), %rbx
incq %rbx
movq -0x60(%rbp), %rcx
addq %rcx, %r8
cmpq $0x4, %rbx
movq -0x78(%rbp), %rax
jne 0x4c6d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq