// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rdi, -0x50(%rbp)
movl 0x54(%rdi), %eax
movslq %r8d, %r13
movslq %r9d, %r15
testb $0x1, %al
movq %r15, -0x48(%rbp)
jne 0xec58
movl %r15d, %ecx
xorl %edx, %edx
testl %r8d, %r8d
cmovlel %edx, %r8d
testl %esi, %esi
movl $0x0, %r12d
cmovgl %esi, %r12d
leaq (%rbx,%r15,4), %rdi
leaq (,%r13,4), %r10
movss 0x1401(%rip), %xmm0     # 0x10008
xorps %xmm1, %xmm1
movq %rbx, %r11
cmpq %r12, %rdx
je 0xec66
movq %rdx, %r15
imulq %r13, %r15
movss (%rdi,%r15,4), %xmm2
movaps %xmm0, %xmm3
divss %xmm2, %xmm3
cmpneqss %xmm1, %xmm2
andps %xmm3, %xmm2
xorl %r15d, %r15d
cmpq %r15, %r8
je 0xec50
cmpq %r15, %rcx
je 0xec4b
movss (%r11,%r15,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r11,%r15,4)
incq %r15
jmp 0xec31
incq %rdx
addq %r10, %r11
jmp 0xec0d
xorl %ecx, %ecx
testl %r8d, %r8d
cmovgl %r8d, %ecx
movl %ecx, %r8d
jmp 0xec6a
movq -0x48(%rbp), %r15
movl 0x10(%rbp), %ecx
xorl %r10d, %r10d
andl $0x2, %eax
xorl %edx, %edx
cmpl %edx, %r8d
je 0xec95
movl %r9d, %edi
xorl %edx, %edi
orl %eax, %edi
je 0xec91
movslq %r10d, %rdi
incl %r10d
movw %dx, -0xe0(%rbp,%rdi,2)
incl %edx
jmp 0xec75
cmpl $0x7, %ecx
ja 0xf27f
movl %ecx, %eax
leaq 0x15ed(%rip), %rcx      # 0x10294
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r13, -0x58(%rbp)
jmpq *%rax
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
leaq (,%r13,4), %rdx
movss 0x133a(%rip), %xmm0     # 0x10008
movss 0x132e(%rip), %xmm1     # 0x10004
xorps %xmm2, %xmm2
movsd 0x1f8f(%rip), %xmm3     # 0x10c70
cmpq %rsi, %rax
je 0xf26d
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0xed20
movss (%rbx,%r8,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, %edi
movb %dil, (%r14,%r8)
incq %r8
jmp 0xeced
incq %rax
addq %rdx, %rbx
addq %r13, %r14
jmp 0xece1
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
shlq $0x2, %r13
movss 0x12c7(%rip), %xmm0     # 0x10008
xorps %xmm1, %xmm1
movsd 0x1f34(%rip), %xmm2     # 0x10c80
movsd 0x1f1c(%rip), %xmm3     # 0x10c70
cmpq %rsi, %rax
je 0xf26d
xorl %edx, %edx
cmpq %rdx, %rcx
je 0xed92
movss (%rbx,%rdx,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, %rdi
movl %edi, (%r14,%rdx,4)
incq %rdx
jmp 0xed5f
incq %rax
addq %r13, %rbx
addq %r13, %r14
jmp 0xed54
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
leaq (,%r13,4), %rdx
addq %r13, %r13
movss 0x124e(%rip), %xmm0     # 0x10008
movss 0x125e(%rip), %xmm1     # 0x10020
xorps %xmm2, %xmm2
movsd 0x1ea3(%rip), %xmm3     # 0x10c70
cmpq %rsi, %rax
je 0xf26d
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0xee0d
movss (%rbx,%r8,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, %edi
movw %di, (%r14,%r8,2)
incq %r8
jmp 0xedd9
incq %rax
addq %rdx, %rbx
addq %r13, %r14
jmp 0xedcd
xorl %r15d, %r15d
testl %r10d, %r10d
cmovlel %r15d, %r10d
movq %r10, -0x40(%rbp)
testl %esi, %esi
cmovlel %r15d, %esi
movss 0x11d4(%rip), %xmm2     # 0x10008
movss 0x11e4(%rip), %xmm3     # 0x10020
xorps %xmm4, %xmm4
movsd 0x1e29(%rip), %xmm5     # 0x10c70
movss 0x123d(%rip), %xmm6     # 0x1008c
movq %rsi, -0x38(%rbp)
cmpq %rsi, %r15
je 0xf26d
movq %r15, -0x30(%rbp)
imulq %r13, %r15
xorl %r13d, %r13d
cmpq %r13, -0x40(%rbp)
je 0xeefe
movzwl -0xe0(%rbp,%r13,2), %r12d
addq %r15, %r12
movss (%rbx,%r12,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm4, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm6
jae 0xeed9
movss 0x11f1(%rip), %xmm1     # 0x10090
callq 0x1190
movss 0x11e0(%rip), %xmm6     # 0x1008c
movsd 0x1dbc(%rip), %xmm5     # 0x10c70
xorps %xmm4, %xmm4
movss 0x1161(%rip), %xmm3     # 0x10020
movss 0x1141(%rip), %xmm2     # 0x10008
mulss 0x11b1(%rip), %xmm0     # 0x10080
addss 0x11bd(%rip), %xmm0     # 0x10094
jmp 0xeee1
mulss 0x1197(%rip), %xmm0     # 0x10078
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r14,%r12,2)
incq %r13
jmp 0xee67
movq -0x50(%rbp), %rax
testb $0x2, 0x54(%rax)
movq -0x48(%rbp), %rax
jne 0xef39
addq %rax, %r15
movss (%rbx,%r15,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
mulss %xmm3, %xmm1
cmpltss %xmm4, %xmm0
andnps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r14,%r15,2)
movq -0x30(%rbp), %r15
incq %r15
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %r13
jmp 0xee53
xorl %ecx, %ecx
testl %r10d, %r10d
cmovlel %ecx, %r10d
movq %r10, -0x40(%rbp)
testl %esi, %esi
cmovlel %ecx, %esi
movss 0x1125(%rip), %xmm1     # 0x1008c
movq %rsi, -0x38(%rbp)
cmpq %rsi, %rcx
je 0xf26d
movq %r13, %rax
movq %rcx, -0x30(%rbp)
movq %rcx, %r13
imulq %rax, %r13
xorl %r12d, %r12d
cmpq %r12, -0x40(%rbp)
je 0xefdc
movzwl -0xe0(%rbp,%r12,2), %r15d
addq %r13, %r15
movss (%rbx,%r15,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0xefc9
movss 0x10e6(%rip), %xmm1     # 0x10090
callq 0x1190
movss 0x10d5(%rip), %xmm1     # 0x1008c
mulss 0x10c1(%rip), %xmm0     # 0x10080
addss 0x10cd(%rip), %xmm0     # 0x10094
jmp 0xefd1
mulss 0x10a7(%rip), %xmm0     # 0x10078
movss %xmm0, (%r14,%r15,4)
incq %r12
jmp 0xef85
movq -0x50(%rbp), %rax
testb $0x2, 0x54(%rax)
movq -0x48(%rbp), %rax
jne 0xeff9
addq %rax, %r13
movss (%rbx,%r13,4), %xmm0
movss %xmm0, (%r14,%r13,4)
movq -0x30(%rbp), %rcx
incq %rcx
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %r13
jmp 0xef6b
xorl %eax, %eax
testl %r10d, %r10d
cmovlel %eax, %r10d
movq %r10, %r12
testl %esi, %esi
cmovlel %eax, %esi
movss 0xfe2(%rip), %xmm0      # 0x10008
movss 0xfd6(%rip), %xmm1      # 0x10004
xorps %xmm2, %xmm2
movsd 0x1c37(%rip), %xmm3     # 0x10c70
movss 0x1057(%rip), %xmm4     # 0x10098
movss 0x1053(%rip), %xmm5     # 0x1009c
leaq 0x1a60(%rip), %rcx      # 0x10ab0
cmpq %rsi, %rax
je 0xf26d
movq %rax, %rdx
imulq %r13, %rdx
xorl %r11d, %r11d
cmpq %r11, %r12
je 0xf0c3
movzwl -0xe0(%rbp,%r11,2), %edi
addq %rdx, %rdi
movss (%rbx,%rdi,4), %xmm6
maxss %xmm4, %xmm6
movaps %xmm5, %xmm7
minss %xmm6, %xmm7
movd %xmm7, %r8d
leal -0x39000000(%r8), %r9d
shrl $0x14, %r9d
movl (%rcx,%r9,4), %r9d
movzwl %r9w, %r10d
shrl $0x7, %r9d
andl $0xfffe00, %r9d         # imm = 0xFFFE00
shrl $0xc, %r8d
movzbl %r8b, %r8d
imull %r10d, %r8d
addl %r9d, %r8d
shrl $0x10, %r8d
movb %r8b, (%r14,%rdi)
incq %r11
jmp 0xf063
movq -0x50(%rbp), %rdi
testb $0x2, 0x54(%rdi)
jne 0xf0f8
addq %r15, %rdx
movss (%rbx,%rdx,4), %xmm6
movaps %xmm0, %xmm7
minss %xmm6, %xmm7
mulss %xmm1, %xmm7
cmpltss %xmm2, %xmm6
andnps %xmm7, %xmm6
cvtss2sd %xmm6, %xmm6
addsd %xmm3, %xmm6
cvttsd2si %xmm6, %edi
movb %dil, (%r14,%rdx)
incq %rax
jmp 0xf050
xorl %ecx, %ecx
testl %r10d, %r10d
cmovlel %ecx, %r10d
movq %r10, -0x40(%rbp)
testl %esi, %esi
cmovlel %ecx, %esi
movss 0xeee(%rip), %xmm2      # 0x10008
xorps %xmm3, %xmm3
movsd 0x1b5b(%rip), %xmm4     # 0x10c80
movsd 0x1b43(%rip), %xmm5     # 0x10c70
movss 0xf57(%rip), %xmm6      # 0x1008c
movq %rsi, -0x38(%rbp)
cmpq %rsi, %rcx
je 0xf26d
movq %r13, %rax
movq %rcx, -0x30(%rbp)
movq %rcx, %r13
imulq %rax, %r13
xorl %r15d, %r15d
cmpq %r15, -0x40(%rbp)
je 0xf1ea
movzwl -0xe0(%rbp,%r15,2), %r12d
addq %r13, %r12
movss (%rbx,%r12,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm6
jae 0xf1c5
movss 0xf05(%rip), %xmm1      # 0x10090
callq 0x1190
movss 0xef4(%rip), %xmm6      # 0x1008c
movsd 0x1ad0(%rip), %xmm5     # 0x10c70
movsd 0x1ad8(%rip), %xmm4     # 0x10c80
xorps %xmm3, %xmm3
movss 0xe55(%rip), %xmm2      # 0x10008
mulss 0xec5(%rip), %xmm0      # 0x10080
addss 0xed1(%rip), %xmm0      # 0x10094
jmp 0xf1cd
mulss 0xeab(%rip), %xmm0      # 0x10078
cvtss2sd %xmm0, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r14,%r12,4)
incq %r15
jmp 0xf153
movq -0x50(%rbp), %rax
testb $0x2, 0x54(%rax)
movq -0x48(%rbp), %rax
jne 0xf224
addq %rax, %r13
movss (%rbx,%r13,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, (%r14,%r13,4)
movq -0x30(%rbp), %rcx
incq %rcx
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %r13
jmp 0xf139
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
shlq $0x2, %r13
cmpq %rsi, %rax
je 0xf26d
xorl %edx, %edx
cmpq %rdx, %rcx
je 0xf262
movss (%rbx,%rdx,4), %xmm0
movss %xmm0, (%r14,%rdx,4)
incq %rdx
jmp 0xf24d
incq %rax
addq %r13, %rbx
addq %r13, %r14
jmp 0xf246
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d1d(%rip), %rdi      # 0x11fa3
leaq 0x2507(%rip), %rsi      # 0x11794
leaq 0x300d(%rip), %rcx      # 0x122a1
movl $0x73b, %edx            # imm = 0x73B
callq 0x1080