// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %r8, %r12
movq %rcx, 0x48(%rsp)
movl %edx, %ebp
movq %rdi, 0x28(%rsp)
movl %esi, %eax
rolw $0x8, %ax
movl $0x202, 0x44(%rsp)      # imm = 0x202
movw %ax, 0x46(%rsp)
leal -0x8000(%rsi), %eax
cmpl $0xffff8008, %eax       # imm = 0xFFFF8008
jae 0x23f93
testl %esi, %esi
jle 0x2424b
movslq %ebp, %rbx
addl $-0x3, %ebp
movl %esi, %r13d
shlq $0x2, %rbx
leaq 0xc(%rsp), %r14
leaq 0x60(%rsp), %r15
cmpl $0x1, %ebp
ja 0x23ecc
movss 0x8(%r12), %xmm1
movss (%r12), %xmm3
movss 0x4(%r12), %xmm2
jmp 0x23ed8
movss (%r12), %xmm1
movaps %xmm1, %xmm2
movaps %xmm1, %xmm3
movaps %xmm2, %xmm0
maxss %xmm1, %xmm0
movaps %xmm3, %xmm4
maxss %xmm0, %xmm4
movss 0x9b3a(%rip), %xmm0     # 0x2da28
ucomiss %xmm4, %xmm0
jbe 0x23efd
movl $0x0, 0xc(%rsp)
jmp 0x23f6f
movaps %xmm4, %xmm0
movq %r15, %rdi
movss %xmm1, 0x18(%rsp)
movss %xmm2, 0x38(%rsp)
movss %xmm3, 0x30(%rsp)
movss %xmm4, 0x10(%rsp)
callq 0x40c0
mulss 0x9b04(%rip), %xmm0     # 0x2da2c
divss 0x10(%rsp), %xmm0
movss 0x30(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movb 0x60(%rsp), %cl
movss 0x38(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %edx
movb %al, 0xc(%rsp)
movss 0x18(%rsp), %xmm1
mulss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movb %dl, 0xd(%rsp)
movb %al, 0xe(%rsp)
addb $-0x80, %cl
movb %cl, 0xf(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
movl $0x4, %edx
callq *(%rax)
addq %rbx, %r12
decq %r13
jne 0x23eb1
jmp 0x2424b
movl %esi, %edx
movq %rsi, 0x18(%rsp)
testl %esi, %esi
movq %rdx, 0x10(%rsp)
jle 0x240de
movq 0x18(%rsp), %rax
leal (%rax,%rax), %r13d
leal (%rax,%rax,2), %r15d
movslq %ebp, %r9
addl $-0x3, %ebp
movq 0x48(%rsp), %rax
leaq (%rax,%rdx), %r14
addq %rax, %r13
addq %rax, %r15
shlq $0x2, %r9
xorl %ebx, %ebx
movss 0x9a51(%rip), %xmm1     # 0x2da28
movl %ebp, 0x5c(%rsp)
cmpl $0x1, %ebp
ja 0x23ff6
movss 0x8(%r12), %xmm2
movss (%r12), %xmm4
movss 0x4(%r12), %xmm3
jmp 0x24002
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 0x24022
movl $0x0, 0xc(%rsp)
jmp 0x240aa
leaq 0x64(%rsp), %rdi
movq %r9, %rbp
movss %xmm2, 0x38(%rsp)
movss %xmm3, 0x30(%rsp)
movss %xmm4, 0x50(%rsp)
movss %xmm0, 0x20(%rsp)
callq 0x40c0
movss 0x99d9(%rip), %xmm1     # 0x2da28
movq %rbp, %r9
movl 0x5c(%rsp), %ebp
mulss 0x99ce(%rip), %xmm0     # 0x2da2c
divss 0x20(%rsp), %xmm0
movss 0x50(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %eax
movb 0x64(%rsp), %cl
movss 0x30(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %edx
movb %al, 0xc(%rsp)
movss 0x38(%rsp), %xmm2
mulss %xmm0, %xmm2
cvttss2si %xmm2, %eax
movb %dl, 0xd(%rsp)
movq 0x10(%rsp), %rdx
movb %al, 0xe(%rsp)
addb $-0x80, %cl
movb %cl, 0xf(%rsp)
movb 0xc(%rsp), %al
movq 0x48(%rsp), %rcx
movb %al, (%rcx,%rbx)
movb 0xd(%rsp), %al
movb %al, (%r14,%rbx)
movb 0xe(%rsp), %al
movb %al, (%r13,%rbx)
movb 0xf(%rsp), %al
movb %al, (%r15,%rbx)
incq %rbx
addq %r9, %r12
cmpq %rbx, %rdx
jne 0x23fdb
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x44(%rsp), %rsi
movq %rdx, %rbx
movl $0x4, %edx
callq *(%rax)
leaq -0x3(%rbx), %rsi
movq 0x48(%rsp), %rax
leaq 0x2(%rax), %rdi
movq $0x0, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rdx
movq %rsi, 0x30(%rsp)
testl %edx, %edx
jle 0x24227
movq 0x20(%rsp), %r13
imulq 0x10(%rsp), %r13
addq 0x48(%rsp), %r13
xorl %r12d, %r12d
movq %rdi, 0x38(%rsp)
leal 0x2(%r12), %eax
movl %edx, %ebx
cmpl %edx, %eax
jge 0x2416a
movslq %r12d, %rax
decq %rax
movl %r12d, %ebx
movb -0x1(%rdi,%rax), %cl
cmpb (%rdi,%rax), %cl
jne 0x2415e
cmpb 0x1(%rdi,%rax), %cl
je 0x2416a
incl %ebx
incq %rax
cmpq %rsi, %rax
jl 0x2414f
movl %edx, %ebx
cmpl %ebx, %r12d
jge 0x2419f
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 0x23df1
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x2417a
leal 0x2(%rbx), %eax
movq 0x18(%rsp), %rdx
cmpl %edx, %eax
jge 0x2420f
movslq %r12d, %rax
movb (%r13,%rax), %cl
movslq %ebx, %rax
incl %ebx
cmpl %ebx, %edx
cmovgl %edx, %ebx
movq 0x10(%rsp), %rdx
movl $0x7f, %r15d
movq 0x50(%rsp), %rsi
cmpb %cl, (%rsi,%rax)
jne 0x241dc
incq %rax
cmpq %rdx, %rax
jl 0x241cd
jmp 0x241de
movl %eax, %ebx
cmpl %ebx, %r12d
jge 0x2420f
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 0x23d91
addl %ebp, %r12d
cmpl %ebx, %r12d
jl 0x241e8
movq 0x18(%rsp), %rdx
cmpl %edx, %r12d
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdi
jl 0x2413b
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
addq %rax, %rdi
addq %rax, 0x50(%rsp)
movq %rcx, 0x20(%rsp)
cmpq $0x4, %rcx
jne 0x2411b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq