// File: /workspace/github_cpp_makefile_star2_O3/srajangarg[P]raytracer/src/core/stb_image_write.hpp
// Function: stbiw__write_hdr_scanline(stbi__write_context*, int, int, unsigned char*, float*)
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
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, 0x34(%rsp)      # imm = 0x202
movw %ax, 0x36(%rsp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
movq %rdi, 0x18(%rsp)
jae 0x245bd
testl %esi, %esi
jle 0x2482c
movslq %ebp, %rbx
addl $-0x3, %ebp
movl %esi, %r13d
shlq $0x2, %rbx
leaq 0x4(%rsp), %r14
leaq 0x50(%rsp), %r15
cmpl $0x1, %ebp
ja 0x244f3
movss 0x8(%r12), %xmm1
movss (%r12), %xmm3
movss 0x4(%r12), %xmm2
jmp 0x244ff
movss (%r12), %xmm1
movaps %xmm1, %xmm2
movaps %xmm1, %xmm3
movaps %xmm2, %xmm0
maxss %xmm1, %xmm0
movaps %xmm3, %xmm4
maxss %xmm0, %xmm4
movss 0x85cf(%rip), %xmm0     # 0x2cae4
ucomiss %xmm4, %xmm0
jbe 0x24527
movb $0x0, 0x5(%rsp)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
jmp 0x2458c
movaps %xmm4, %xmm0
movq %r15, %rdi
movss %xmm1, 0x28(%rsp)
movss %xmm2, 0x10(%rsp)
movss %xmm3, 0x20(%rsp)
movss %xmm4, 0x8(%rsp)
callq 0x40c0
movb 0x50(%rsp), %al
mulss 0x8592(%rip), %xmm0     # 0x2cae8
divss 0x8(%rsp), %xmm0
movss 0x20(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %ecx
movss 0x10(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movb %dl, 0x5(%rsp)
movss 0x28(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
addb $-0x80, %al
movq 0x18(%rsp), %r8
movb %cl, 0x4(%rsp)
movb %al, 0x7(%rsp)
movb %dl, 0x6(%rsp)
movq 0x8(%r8), %rdi
movq %r14, %rsi
movl $0x4, %edx
callq *(%r8)
addq %rbx, %r12
decq %r13
jne 0x244d8
jmp 0x2482c
movq %rdi, %r8
leal (%rsi,%rsi), %ebx
leal (%rsi,%rsi,2), %r14d
movslq %ebp, %r15
addl $-0x3, %ebp
movl %ebp, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movl %esi, %eax
leaq (%rcx,%rax), %r13
addq %rcx, %rbx
movq %rcx, 0x40(%rsp)
addq %rcx, %r14
shlq $0x2, %r15
xorl %ebp, %ebp
movss 0x84ef(%rip), %xmm1     # 0x2cae4
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x10(%rsp)
ja 0x24617
movss 0x8(%r12), %xmm2
movss (%r12), %xmm4
movss 0x4(%r12), %xmm3
jmp 0x24623
movss (%r12), %xmm2
movaps %xmm2, %xmm3
movaps %xmm2, %xmm4
movaps %xmm3, %xmm5
maxss %xmm2, %xmm5
movaps %xmm4, %xmm0
maxss %xmm5, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x24640
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
xorl %esi, %esi
jmp 0x246ad
leaq 0x54(%rsp), %rdi
movss %xmm2, 0x20(%rsp)
movss %xmm3, 0x38(%rsp)
movss %xmm4, 0x4c(%rsp)
movss %xmm0, 0x48(%rsp)
callq 0x40c0
movss 0x847a(%rip), %xmm1     # 0x2cae4
movq 0x18(%rsp), %r8
mulss 0x8471(%rip), %xmm0     # 0x2cae8
divss 0x48(%rsp), %xmm0
movss 0x4c(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %ecx
movb 0x54(%rsp), %al
movss 0x38(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %edx
movss 0x20(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %esi
addb $-0x80, %al
movq 0x40(%rsp), %rdi
movb %cl, (%rdi,%rbp)
movb %dl, (%r13,%rbp)
movb %sil, (%rbx,%rbp)
movb %al, (%r14,%rbp)
incq %rbp
addq %r15, %r12
movq 0x8(%rsp), %rax
cmpq %rbp, %rax
jne 0x245fa
movq 0x8(%r8), %rdi
leaq 0x34(%rsp), %rsi
movl $0x4, %edx
callq *(%r8)
movq 0x8(%rsp), %rcx
leaq -0x3(%rcx), %rdi
xorl %r13d, %r13d
movq 0x40(%rsp), %rax
movq %rax, %r8
movq 0x28(%rsp), %rsi
movq %rdi, 0x20(%rsp)
movq %r13, 0x38(%rsp)
imulq %rcx, %r13
addq %rax, %r13
xorl %r12d, %r12d
movq %r8, 0x10(%rsp)
leal 0x2(%r12), %eax
movl %esi, %ebx
cmpl %esi, %eax
jge 0x24750
movslq %r12d, %rax
movb (%r13,%rax), %cl
decq %rax
movl %r12d, %ebx
movb 0x2(%r8,%rax), %dl
cmpb %dl, %cl
jne 0x24742
cmpb 0x3(%r8,%rax), %cl
je 0x24750
incl %ebx
incq %rax
movl %edx, %ecx
cmpq %rdi, %rax
jl 0x24732
movl %esi, %ebx
cmpl %ebx, %r12d
jge 0x24785
movq 0x18(%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 0x2441d
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x24760
leal 0x2(%rbx), %eax
movq 0x28(%rsp), %rdx
cmpl %edx, %eax
jge 0x247f5
movslq %r12d, %rax
movb (%r13,%rax), %cl
movslq %ebx, %rax
incl %ebx
cmpl %ebx, %edx
cmovgl %edx, %ebx
movq 0x8(%rsp), %rdx
movl $0x7f, %r14d
movq 0x10(%rsp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x247c2
incq %rax
cmpq %rdx, %rax
jl 0x247b3
jmp 0x247c4
movl %eax, %ebx
cmpl %ebx, %r12d
jge 0x247f5
movq 0x18(%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 0x243bd
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x247ce
movq 0x28(%rsp), %rsi
cmpl %esi, %r12d
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
jl 0x24719
movq 0x38(%rsp), %r13
incq %r13
movq 0x8(%rsp), %rcx
addq %rcx, %r8
cmpq $0x4, %r13
movq 0x40(%rsp), %rax
jne 0x24705
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq