// File: srajangarg[P]raytracer/src/core/stb_image.hpp
// Function: stbi__hdr_to_ldr(float*, int, int, int)
static stbi_uc *stbi__hdr_to_ldr(float   *data, int x, int y, int comp)
{
   int i,k,n;
   stbi_uc *output = (stbi_uc *) stbi__malloc(x * y * comp);
   if (output == NULL) { STBI_FREE(data); return stbi__errpuc("outofmem", "Out of memory"); }
   // compute number of non-alpha components
   if (comp & 1) n = comp; else n = comp-1;
   for (i=0; i < x*y; ++i) {
      for (k=0; k < n; ++k) {
         float z = (float) pow(data[i*comp+k]*stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f;
         if (z < 0) z = 0;
         if (z > 255) z = 255;
         output[i*comp + k] = (stbi_uc) stbi__float2int(z);
      }
      if (k < comp) {
         float z = data[i*comp+k] * 255 + 0.5f;
         if (z < 0) z = 0;
         if (z > 255) z = 255;
         output[i*comp + k] = (stbi_uc) stbi__float2int(z);
      }
   }
   STBI_FREE(data);
   return output;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
movslq %eax, %rdi
callq 0x27f20
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2a81c
movq -0x10(%rbp), %rdi
callq 0x54c0
leaq 0x1d7e2(%rip), %rdi     # 0x47fe5
callq 0x275b0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
cmovneq %rax, %rax
movq %rax, -0x8(%rbp)
jmp 0x2a9ac
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2a82f
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x2a838
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x14(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2a99b
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2a905
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
mulss 0x31baa(%rip), %xmm0    # 0x5c42c
movss 0x31b9e(%rip), %xmm1    # 0x5c428
callq 0x376f0
movss 0x1d44d(%rip), %xmm1    # 0x47ce4
mulss %xmm1, %xmm0
movss 0x1d445(%rip), %xmm1    # 0x47ce8
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x34(%rbp), %xmm0
jbe 0x2a8bd
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x34(%rbp), %xmm0
movss 0x1d41a(%rip), %xmm1    # 0x47ce4
ucomiss %xmm1, %xmm0
jbe 0x2a8dc
movss 0x1d40d(%rip), %xmm0    # 0x47ce4
movss %xmm0, -0x34(%rbp)
cvttss2si -0x34(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2a858
movl -0x24(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x2a98b
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x1d3b9(%rip), %xmm1    # 0x47ce4
mulss %xmm1, %xmm0
movss 0x1d3b1(%rip), %xmm1    # 0x47ce8
addss %xmm1, %xmm0
movss %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x38(%rbp), %xmm0
jbe 0x2a951
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x38(%rbp), %xmm0
movss 0x1d386(%rip), %xmm1    # 0x47ce4
ucomiss %xmm1, %xmm0
jbe 0x2a970
movss 0x1d379(%rip), %xmm0    # 0x47ce4
movss %xmm0, -0x38(%rbp)
cvttss2si -0x38(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x2a98d
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2a83f
movq -0x10(%rbp), %rdi
callq 0x54c0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)