// File: /workspace/github_cpp_makefile_star2_O1/lunasorcery[P]brailify/./stb/stb_image_resize.h
// Function: stbir__encode_scanline(stbir__info*, int, void*, float*, int, int, int)
static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void *output_buffer, float *encode_buffer, int channels, int alpha_channel, int decode)
{
    int x;
    int n;
    int num_nonalpha;
    stbir_uint16 nonalpha[STBIR_MAX_CHANNELS];

    if (!(stbir_info->flags&STBIR_FLAG_ALPHA_PREMULTIPLIED))
    {
        for (x=0; x < num_pixels; ++x)
        {
            int pixel_index = x*channels;

            float alpha = encode_buffer[pixel_index + alpha_channel];
            float reciprocal_alpha = alpha ? 1.0f / alpha : 0;

            // unrolling this produced a 1% slowdown upscaling a large RGBA linear-space image on my machine - stb
            for (n = 0; n < channels; n++)
                if (n != alpha_channel)
                    encode_buffer[pixel_index + n] *= reciprocal_alpha;

            // We added in a small epsilon to prevent the color channel from being deleted with zero alpha.
            // Because we only add it for integer types, it will automatically be discarded on integer
            // conversion, so we don't need to subtract it back out (which would be problematic for
            // numeric precision reasons).
        }
    }

    // build a table of all channels that need colorspace correction, so
    // we don't perform colorspace correction on channels that don't need it.
    for (x=0, num_nonalpha=0; x < channels; ++x)
        if (x != alpha_channel || (stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE))
            nonalpha[num_nonalpha++] = x;

    #define STBIR__ROUND_INT(f)    ((int)          ((f)+0.5))
    #define STBIR__ROUND_UINT(f)   ((stbir_uint32) ((f)+0.5))

    #ifdef STBIR__SATURATE_INT
    #define STBIR__ENCODE_LINEAR8(f)   stbir__saturate8 (STBIR__ROUND_INT((f) * 255  ))
    #define STBIR__ENCODE_LINEAR16(f)  stbir__saturate16(STBIR__ROUND_INT((f) * 65535))
    #else
    #define STBIR__ENCODE_LINEAR8(f)   (unsigned char ) STBIR__ROUND_INT(stbir__saturate(f) * 255  )
    #define STBIR__ENCODE_LINEAR16(f)  (unsigned short) STBIR__ROUND_INT(stbir__saturate(f) * 65535)
    #endif

    switch (decode)
    {
        case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_LINEAR):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < channels; n++)
                {
                    int index = pixel_index + n;
                    ((unsigned char*)output_buffer)[index] = STBIR__ENCODE_LINEAR8(encode_buffer[index]);
                }
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_SRGB):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < num_nonalpha; n++)
                {
                    int index = pixel_index + nonalpha[n];
                    ((unsigned char*)output_buffer)[index] = stbir__linear_to_srgb_uchar(encode_buffer[index]);
                }

                if (!(stbir_info->flags & STBIR_FLAG_ALPHA_USES_COLORSPACE))
                    ((unsigned char *)output_buffer)[pixel_index + alpha_channel] = STBIR__ENCODE_LINEAR8(encode_buffer[pixel_index+alpha_channel]);
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_LINEAR):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < channels; n++)
                {
                    int index = pixel_index + n;
                    ((unsigned short*)output_buffer)[index] = STBIR__ENCODE_LINEAR16(encode_buffer[index]);
                }
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_UINT16, STBIR_COLORSPACE_SRGB):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < num_nonalpha; n++)
                {
                    int index = pixel_index + nonalpha[n];
                    ((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * 65535);
                }

                if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
                    ((unsigned short*)output_buffer)[pixel_index + alpha_channel] = STBIR__ENCODE_LINEAR16(encode_buffer[pixel_index + alpha_channel]);
            }

            break;

        case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_LINEAR):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < channels; n++)
                {
                    int index = pixel_index + n;
                    ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__saturate(encode_buffer[index])) * 4294967295);
                }
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_UINT32, STBIR_COLORSPACE_SRGB):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < num_nonalpha; n++)
                {
                    int index = pixel_index + nonalpha[n];
                    ((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_UINT(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * 4294967295);
                }

                if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
                    ((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * 4294967295);
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_LINEAR):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < channels; n++)
                {
                    int index = pixel_index + n;
                    ((float*)output_buffer)[index] = encode_buffer[index];
                }
            }
            break;

        case STBIR__DECODE(STBIR_TYPE_FLOAT, STBIR_COLORSPACE_SRGB):
            for (x=0; x < num_pixels; ++x)
            {
                int pixel_index = x*channels;

                for (n = 0; n < num_nonalpha; n++)
                {
                    int index = pixel_index + nonalpha[n];
                    ((float*)output_buffer)[index] = stbir__linear_to_srgb(encode_buffer[index]);
                }

                if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE))
                    ((float*)output_buffer)[pixel_index + alpha_channel] = encode_buffer[pixel_index + alpha_channel];
            }
            break;

        default:
            STBIR_ASSERT(!"Unknown type/colorspace/channels combination.");
            break;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %rbx
movq %rdx, -0x30(%rbp)
movq %rdi, -0x60(%rbp)
movl 0x54(%rdi), %eax
testl %esi, %esi
setle %cl
orb %al, %cl
testb $0x1, %cl
jne 0x15b35
movl %r9d, %ecx
movslq %r8d, %rdx
movslq %r9d, %r10
movl %esi, %edi
leaq (%rbx,%r10,4), %r10
movl %edx, %r11d
xorl %r15d, %r15d
movss 0x152c(%rip), %xmm0     # 0x17008
xorps %xmm1, %xmm1
xorl %r12d, %r12d
testl %r8d, %r8d
jle 0x15b2a
movq %r12, %r13
imulq %rdx, %r13
movl %r15d, %r14d
leaq (%rbx,%r14,4), %r14
movss (%r10,%r13,4), %xmm2
movaps %xmm0, %xmm3
divss %xmm2, %xmm3
cmpneqss %xmm1, %xmm2
andps %xmm3, %xmm2
xorl %r13d, %r13d
cmpq %r13, %rcx
je 0x15b22
movss (%r14,%r13,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r14,%r13,4)
incq %r13
cmpq %r13, %r11
jne 0x15b0d
incq %r12
addl %r8d, %r15d
cmpq %rdi, %r12
jne 0x15ae2
movl 0x10(%rbp), %ecx
testl %r8d, %r8d
jle 0x15b65
xorl %edx, %edx
andl $0x2, %eax
xorl %r10d, %r10d
movl %r9d, %edi
xorl %edx, %edi
orl %eax, %edi
je 0x15b5c
movslq %r10d, %rdi
incl %r10d
movw %dx, -0xe0(%rbp,%rdi,2)
incl %edx
cmpl %edx, %r8d
jne 0x15b45
jmp 0x15b68
xorl %r10d, %r10d
cmpl $0x7, %ecx
ja 0x161ba
movl %ecx, %eax
leaq 0x1802(%rip), %rcx      # 0x1737c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq -0x30(%rbp), %r11
movl %r10d, -0x34(%rbp)
jmpq *%rax
testl %esi, %esi
jle 0x161a8
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x1466(%rip), %xmm0     # 0x17008
movss 0x145a(%rip), %xmm1     # 0x17004
xorps %xmm2, %xmm2
movsd 0x217b(%rip), %xmm3     # 0x17d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x15bff
movl %edx, %r9d
movq -0x30(%rbp), %rdi
addq %r9, %rdi
leaq (%rbx,%r9,4), %r9
xorl %r10d, %r10d
movss (%r9,%r10,4), %xmm4
movaps %xmm0, %xmm5
minss %xmm4, %xmm5
mulss %xmm1, %xmm5
cmpltss %xmm2, %xmm4
andnps %xmm5, %xmm4
cvtss2sd %xmm4, %xmm4
addsd %xmm3, %xmm4
cvttsd2si %xmm4, %r11d
movb %r11b, (%rdi,%r10)
incq %r10
cmpq %r10, %rcx
jne 0x15bcd
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x15bb7
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x13e2(%rip), %xmm0     # 0x17008
xorps %xmm1, %xmm1
movsd 0x212f(%rip), %xmm2     # 0x17d60
movsd 0x20f7(%rip), %xmm3     # 0x17d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x15c84
movl %edx, %r9d
movq -0x30(%rbp), %rdi
leaq (%rdi,%r9,4), %rdi
leaq (%rbx,%r9,4), %r9
xorl %r10d, %r10d
movss (%r9,%r10,4), %xmm4
movaps %xmm0, %xmm5
minss %xmm4, %xmm5
cmpltss %xmm1, %xmm4
andnps %xmm5, %xmm4
cvtss2sd %xmm4, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
cvttsd2si %xmm4, %r11
movl %r11d, (%rdi,%r10,4)
incq %r10
cmpq %r10, %rcx
jne 0x15c52
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x15c3b
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x135d(%rip), %xmm0     # 0x17008
movss 0x136d(%rip), %xmm1     # 0x17020
xorps %xmm2, %xmm2
movsd 0x2072(%rip), %xmm3     # 0x17d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x15d0a
movl %edx, %r9d
movq -0x30(%rbp), %rdi
leaq (%rdi,%r9,2), %rdi
leaq (%rbx,%r9,4), %r9
xorl %r10d, %r10d
movss (%r9,%r10,4), %xmm4
movaps %xmm0, %xmm5
minss %xmm4, %xmm5
mulss %xmm1, %xmm5
cmpltss %xmm2, %xmm4
andnps %xmm5, %xmm4
cvtss2sd %xmm4, %xmm4
addsd %xmm3, %xmm4
cvttsd2si %xmm4, %r11d
movw %r11w, (%rdi,%r10,2)
incq %r10
cmpq %r10, %rcx
jne 0x15cd7
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x15cc0
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movslq %r8d, %rax
movq %rax, -0x50(%rbp)
movslq %r9d, %rax
movq %rax, -0x40(%rbp)
movl %esi, %eax
movq %rax, -0x48(%rbp)
movl %r10d, %r13d
xorl %r15d, %r15d
movss 0x12c4(%rip), %xmm2     # 0x17008
xorps %xmm3, %xmm3
movss 0x133d(%rip), %xmm4     # 0x1708c
movss 0x12c9(%rip), %xmm5     # 0x17020
movsd 0x1fd1(%rip), %xmm6     # 0x17d30
movq %r15, -0x58(%rbp)
imulq -0x50(%rbp), %r15
testl %r10d, %r10d
jle 0x15e09
xorl %r12d, %r12d
movzwl -0xe0(%rbp,%r12,2), %r14d
addq %r15, %r14
movss (%rbx,%r14,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm4
jae 0x15de0
movss 0x12ee(%rip), %xmm1     # 0x17090
callq 0x1180
movsd 0x1f81(%rip), %xmm6     # 0x17d30
movss 0x1269(%rip), %xmm5     # 0x17020
movss 0x12cd(%rip), %xmm4     # 0x1708c
xorps %xmm3, %xmm3
movss 0x123e(%rip), %xmm2     # 0x17008
movq -0x30(%rbp), %r11
mulss 0x12aa(%rip), %xmm0     # 0x17080
addss 0x12b6(%rip), %xmm0     # 0x17094
jmp 0x15de8
mulss 0x1290(%rip), %xmm0     # 0x17078
mulss %xmm5, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r11,%r14,2)
incq %r12
cmpq %r12, %r13
jne 0x15d74
movq -0x60(%rbp), %rax
testb $0x2, 0x54(%rax)
jne 0x15e41
addq -0x40(%rbp), %r15
movss (%rbx,%r15,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
mulss %xmm5, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r11,%r15,2)
movq -0x58(%rbp), %r15
incq %r15
cmpq -0x48(%rbp), %r15
movl -0x34(%rbp), %r10d
jne 0x15d5f
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movslq %r8d, %rax
movq %rax, -0x50(%rbp)
movslq %r9d, %rax
movq %rax, -0x40(%rbp)
movl %esi, %eax
movq %rax, -0x48(%rbp)
movl %r10d, %r12d
xorl %r15d, %r15d
movss 0x1207(%rip), %xmm1     # 0x1708c
movq %r15, -0x58(%rbp)
imulq -0x50(%rbp), %r15
testl %r10d, %r10d
jle 0x15eee
xorl %r14d, %r14d
movzwl -0xe0(%rbp,%r14,2), %r13d
addq %r15, %r13
movss (%rbx,%r13,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0x15ed8
movss 0x11db(%rip), %xmm1     # 0x17090
callq 0x1180
movss 0x11ca(%rip), %xmm1     # 0x1708c
movq -0x30(%rbp), %r11
mulss 0x11b2(%rip), %xmm0     # 0x17080
addss 0x11be(%rip), %xmm0     # 0x17094
jmp 0x15ee0
mulss 0x1198(%rip), %xmm0     # 0x17078
movss %xmm0, (%r11,%r13,4)
incq %r14
cmpq %r14, %r12
jne 0x15e96
movq -0x60(%rbp), %rax
testb $0x2, 0x54(%rax)
jne 0x15f08
addq -0x40(%rbp), %r15
movss (%rbx,%r15,4), %xmm0
movss %xmm0, (%r11,%r15,4)
movq -0x58(%rbp), %r15
incq %r15
cmpq -0x48(%rbp), %r15
movl -0x34(%rbp), %r10d
jne 0x15e85
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movslq %r8d, %rax
movslq %r9d, %rcx
movl %esi, %edx
movl %r10d, %esi
xorl %edi, %edi
movss 0x1159(%rip), %xmm0     # 0x17098
movss 0x1155(%rip), %xmm1     # 0x1709c
leaq 0x1c42(%rip), %r8       # 0x17b90
movss 0x10b2(%rip), %xmm2     # 0x17008
movss 0x10a6(%rip), %xmm3     # 0x17004
xorps %xmm4, %xmm4
movsd 0x1dc7(%rip), %xmm5     # 0x17d30
movq %rdi, %r9
imulq %rax, %r9
testl %r10d, %r10d
jle 0x15fdf
xorl %r10d, %r10d
movzwl -0xe0(%rbp,%r10,2), %r11d
addq %r9, %r11
movss (%rbx,%r11,4), %xmm6
maxss %xmm0, %xmm6
movaps %xmm1, %xmm7
minss %xmm6, %xmm7
movd %xmm7, %r14d
leal -0x39000000(%r14), %r15d
shrl $0x14, %r15d
movl (%r8,%r15,4), %r15d
movzwl %r15w, %r12d
shrl $0x7, %r15d
andl $0xfffe00, %r15d        # imm = 0xFFFE00
shrl $0xc, %r14d
movzbl %r14b, %r14d
imull %r12d, %r14d
addl %r15d, %r14d
shrl $0x10, %r14d
movq -0x30(%rbp), %r15
movb %r14b, (%r15,%r11)
movq -0x30(%rbp), %r11
incq %r10
cmpq %r10, %rsi
jne 0x15f78
movq -0x60(%rbp), %r10
testb $0x2, 0x54(%r10)
jne 0x16017
addq %rcx, %r9
movss (%rbx,%r9,4), %xmm6
movaps %xmm2, %xmm7
minss %xmm6, %xmm7
mulss %xmm3, %xmm7
cmpltss %xmm4, %xmm6
andnps %xmm7, %xmm6
cvtss2sd %xmm6, %xmm6
addsd %xmm5, %xmm6
cvttsd2si %xmm6, %r10d
movb %r10b, (%r11,%r9)
incq %rdi
cmpq %rdx, %rdi
movl -0x34(%rbp), %r10d
jne 0x15f69
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movslq %r8d, %rax
movq %rax, -0x50(%rbp)
movslq %r9d, %rax
movq %rax, -0x40(%rbp)
movl %esi, %eax
movq %rax, -0x48(%rbp)
movl %r10d, %r13d
xorl %r12d, %r12d
movss 0xfb2(%rip), %xmm2      # 0x17008
xorps %xmm3, %xmm3
movss 0x102b(%rip), %xmm4     # 0x1708c
movsd 0x1cf7(%rip), %xmm5     # 0x17d60
movsd 0x1cbf(%rip), %xmm6     # 0x17d30
movq %r12, -0x58(%rbp)
imulq -0x50(%rbp), %r12
testl %r10d, %r10d
jle 0x1611b
xorl %r15d, %r15d
movzwl -0xe0(%rbp,%r15,2), %r14d
addq %r12, %r14
movss (%rbx,%r14,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm4
jae 0x160f2
movss 0xfdc(%rip), %xmm1      # 0x17090
callq 0x1180
movsd 0x1c6f(%rip), %xmm6     # 0x17d30
movsd 0x1c97(%rip), %xmm5     # 0x17d60
movss 0xfbb(%rip), %xmm4      # 0x1708c
xorps %xmm3, %xmm3
movss 0xf2c(%rip), %xmm2      # 0x17008
movq -0x30(%rbp), %r11
mulss 0xf98(%rip), %xmm0      # 0x17080
addss 0xfa4(%rip), %xmm0      # 0x17094
jmp 0x160fa
mulss 0xf7e(%rip), %xmm0      # 0x17078
cvtss2sd %xmm0, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r11,%r14,4)
incq %r15
cmpq %r15, %r13
jne 0x16086
movq -0x60(%rbp), %rax
testb $0x2, 0x54(%rax)
jne 0x16152
addq -0x40(%rbp), %r12
movss (%rbx,%r12,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, (%r11,%r12,4)
movq -0x58(%rbp), %r12
incq %r12
cmpq -0x48(%rbp), %r12
movl -0x34(%rbp), %r10d
jne 0x16071
jmp 0x161a8
testl %esi, %esi
jle 0x161a8
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1619d
movl %edx, %r9d
leaq (%r11,%r9,4), %rdi
leaq (%rbx,%r9,4), %r9
xorl %r10d, %r10d
movss (%r9,%r10,4), %xmm0
movss %xmm0, (%rdi,%r10,4)
incq %r10
cmpq %r10, %rcx
jne 0x16189
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x16176
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ec6(%rip), %rdi      # 0x19087
leaq 0x26b0(%rip), %rsi      # 0x18878
leaq 0x31e8(%rip), %rcx      # 0x193b7
movl $0x73b, %edx            # imm = 0x73B
callq 0x1090