// File: /workspace/github_c_makefile_star2_O1/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 %rcx, -0x68(%rbp)
movl %edx, %r14d
movq %rdi, -0x80(%rbp)
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, -0x5c(%rbp)     # imm = 0x202
movw %ax, -0x5a(%rbp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jae 0x4a0e
testl %esi, %esi
jle 0x4ce8
movslq %r14d, %rbx
movl %esi, %r13d
shlq $0x2, %rbx
leal -0x1(%r14), %r15d
addl $-0x3, %r14d
cmpl $0x2, %r15d
jb 0x4947
cmpl $0x1, %r14d
movss -0x40(%rbp), %xmm1
movss -0x38(%rbp), %xmm2
movss -0x48(%rbp), %xmm3
ja 0x4953
movss 0x8(%r12), %xmm1
movss (%r12), %xmm2
movss 0x4(%r12), %xmm3
jmp 0x4953
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 0xd86d(%rip), %xmm1     # 0x121e0
ucomisd %xmm5, %xmm1
movss %xmm4, -0x40(%rbp)
movss %xmm2, -0x38(%rbp)
movss %xmm3, -0x48(%rbp)
jbe 0x4991
movl $0x0, -0x2c(%rbp)
jmp 0x49e6
leaq -0x84(%rbp), %rdi
movss %xmm0, -0x58(%rbp)
callq 0x2090
movb -0x84(%rbp), %al
mulss 0xd82c(%rip), %xmm0     # 0x121dc
divss -0x58(%rbp), %xmm0
movss -0x38(%rbp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movss -0x48(%rbp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movb %cl, -0x2c(%rbp)
mulss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movb %dl, -0x2b(%rbp)
movb %cl, -0x2a(%rbp)
addb $-0x80, %al
movb %al, -0x29(%rbp)
movl $0x4, %esi
movl $0x1, %edx
leaq -0x2c(%rbp), %rdi
movq -0x80(%rbp), %rcx
callq 0x2410
addq %rbx, %r12
decq %r13
jne 0x4916
jmp 0x4ce8
movl %esi, %r8d
movq %rsi, -0x38(%rbp)
testl %esi, %esi
movq %r8, -0x78(%rbp)
jle 0x4b7a
movq -0x38(%rbp), %rax
leal (%rax,%rax), %esi
leal (%rax,%rax,2), %edi
movslq %r14d, %rcx
movq -0x68(%rbp), %rax
leaq (%rax,%r8), %rdx
addq %rax, %rsi
addq %rax, %rdi
leaq (,%rcx,4), %rbx
xorl %r13d, %r13d
leal -0x1(%rcx), %r15d
movsd 0xd78d(%rip), %xmm1     # 0x121e0
addl $-0x3, %ecx
movq %rcx, -0x50(%rbp)
movq %rdx, -0x98(%rbp)
movq %rdi, -0x90(%rbp)
cmpl $0x2, %r15d
jb 0x4a8a
cmpl $0x1, -0x50(%rbp)
ja 0x4a96
movss 0x8(%r12), %xmm2
movss (%r12), %xmm3
movss 0x4(%r12), %xmm4
jmp 0x4a96
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 0x4abd
movl $0x0, -0x2c(%rbp)
jmp 0x4b4b
leaq -0x88(%rbp), %rdi
movq %rsi, %r14
movss %xmm2, -0x40(%rbp)
movss %xmm3, -0x48(%rbp)
movss %xmm4, -0x58(%rbp)
movss %xmm0, -0x70(%rbp)
callq 0x2090
movss -0x58(%rbp), %xmm4
movss -0x48(%rbp), %xmm3
movss -0x40(%rbp), %xmm2
movq -0x90(%rbp), %rdi
movq %r14, %rsi
movb -0x88(%rbp), %al
mulss 0xd6d5(%rip), %xmm0     # 0x121dc
divss -0x70(%rbp), %xmm0
movaps %xmm3, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movaps %xmm4, %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movsd 0xd6b6(%rip), %xmm1     # 0x121e0
movb %cl, -0x2c(%rbp)
mulss %xmm2, %xmm0
cvttss2si %xmm0, %ecx
movb %dl, -0x2b(%rbp)
movq -0x98(%rbp), %rdx
movq -0x78(%rbp), %r8
movb %cl, -0x2a(%rbp)
addb $-0x80, %al
movb %al, -0x29(%rbp)
movb -0x2c(%rbp), %al
movq -0x68(%rbp), %rcx
movb %al, (%rcx,%r13)
movb -0x2b(%rbp), %al
movb %al, (%rdx,%r13)
movb -0x2a(%rbp), %al
movb %al, (%rsi,%r13)
movb -0x29(%rbp), %al
movb %al, (%rdi,%r13)
incq %r13
addq %rbx, %r12
cmpq %r13, %r8
jne 0x4a68
leaq -0x5c(%rbp), %rdi
movl $0x4, %esi
movq %r8, %rbx
movl $0x1, %edx
movq -0x80(%rbp), %rcx
callq 0x2410
leaq -0x3(%rbx), %rsi
movq -0x68(%rbp), %rax
leaq 0x2(%rax), %rdi
movq $0x0, -0x50(%rbp)
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdx
movq %rsi, -0x58(%rbp)
testl %edx, %edx
jle 0x4cc8
movq -0x50(%rbp), %r8
imulq -0x78(%rbp), %r8
addq -0x68(%rbp), %r8
xorl %r15d, %r15d
movq %rdi, -0x48(%rbp)
movq %r8, -0x40(%rbp)
leal 0x2(%r15), %eax
movl %edx, %r13d
cmpl %edx, %eax
jge 0x4c05
movslq %r15d, %rax
decq %rax
movl %r15d, %r13d
movb -0x1(%rdi,%rax), %cl
cmpb (%rdi,%rax), %cl
jne 0x4bf7
cmpb 0x1(%rdi,%rax), %cl
je 0x4c05
incl %r13d
incq %rax
cmpq %rsi, %rax
jl 0x4be8
movl %edx, %r13d
cmpl %r13d, %r15d
jge 0x4c3e
movq -0x80(%rbp), %r14
movl $0x80, %ebx
movl %r13d, %r12d
subl %r15d, %r12d
cmpl %ebx, %r12d
cmovgel %ebx, %r12d
movslq %r15d, %r15
leaq (%r8,%r15), %rdx
movq %r14, %rdi
movl %r12d, %esi
callq 0x4858
movq -0x40(%rbp), %r8
addl %r12d, %r15d
cmpl %r13d, %r15d
jl 0x4c13
leal 0x2(%r13), %eax
movq -0x38(%rbp), %rdx
cmpl %edx, %eax
jge 0x4cb3
movslq %r15d, %rax
movb (%r8,%rax), %cl
movslq %r13d, %rax
incl %r13d
cmpl %r13d, %edx
cmovgl %edx, %r13d
movq -0x78(%rbp), %rdx
movl $0x7f, %ebx
movq -0x70(%rbp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x4c7a
incq %rax
cmpq %rdx, %rax
jl 0x4c6b
jmp 0x4c7d
movl %eax, %r13d
cmpl %r13d, %r15d
jge 0x4cb3
movq -0x80(%rbp), %r14
movl %r13d, %r12d
subl %r15d, %r12d
cmpl $0x7f, %r12d
cmovgel %ebx, %r12d
movslq %r15d, %r15
movzbl (%r8,%r15), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x4805
movq -0x40(%rbp), %r8
addl %r12d, %r15d
cmpl %r13d, %r15d
jl 0x4c86
movq -0x38(%rbp), %rdx
cmpl %edx, %r15d
movq -0x58(%rbp), %rsi
movq -0x48(%rbp), %rdi
jl 0x4bd4
movq -0x50(%rbp), %rcx
incq %rcx
movq -0x78(%rbp), %rax
addq %rax, %rdi
addq %rax, -0x70(%rbp)
movq %rcx, -0x50(%rbp)
cmpq $0x4, %rcx
jne 0x4bb4
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq