// File: /workspace/github_cpp_makefile_star2_O3/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 0x14dde
movl %r9d, %ecx
movslq %r8d, %rdx
movslq %r9d, %r10
movl %esi, %edi
leaq (%rbx,%r10,4), %r10
movl %edx, %r11d
xorl %r15d, %r15d
movss 0x1283(%rip), %xmm0     # 0x16008
xorps %xmm1, %xmm1
xorl %r12d, %r12d
testl %r8d, %r8d
jle 0x14dd3
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 0x14dcb
movss (%r14,%r13,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r14,%r13,4)
incq %r13
cmpq %r13, %r11
jne 0x14db6
incq %r12
addl %r8d, %r15d
cmpq %rdi, %r12
jne 0x14d8b
movl 0x10(%rbp), %ecx
testl %r8d, %r8d
jle 0x14e13
xorl %edx, %edx
movl %eax, %edi
andl $0x2, %edi
xorl %r14d, %r14d
movl %r9d, %r10d
xorl %edx, %r10d
orl %edi, %r10d
je 0x14e0a
movslq %r14d, %r10
incl %r14d
movw %dx, -0xe0(%rbp,%r10,2)
incl %edx
cmpl %edx, %r8d
jne 0x14df0
jmp 0x14e16
xorl %r14d, %r14d
cmpl $0x7, %ecx
ja 0x1546e
movl %ecx, %ecx
leaq 0x1554(%rip), %rdx      # 0x1637c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq -0x30(%rbp), %r11
movl %r14d, -0x34(%rbp)
jmpq *%rcx
testl %esi, %esi
jle 0x1545c
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x11b8(%rip), %xmm0     # 0x16008
movss 0x11ac(%rip), %xmm1     # 0x16004
xorps %xmm2, %xmm2
movsd 0x1ecd(%rip), %xmm3     # 0x16d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x14ead
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 0x14e7b
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x14e65
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x1134(%rip), %xmm0     # 0x16008
xorps %xmm1, %xmm1
movsd 0x1e81(%rip), %xmm2     # 0x16d60
movsd 0x1e49(%rip), %xmm3     # 0x16d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x14f32
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 0x14f00
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x14ee9
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x10af(%rip), %xmm0     # 0x16008
movss 0x10bf(%rip), %xmm1     # 0x16020
xorps %xmm2, %xmm2
movsd 0x1dc4(%rip), %xmm3     # 0x16d30
xorl %esi, %esi
testl %r8d, %r8d
jle 0x14fb8
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 0x14f85
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x14f6e
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movslq %r8d, %rcx
movq %rcx, -0x50(%rbp)
movslq %r9d, %rcx
movq %rcx, -0x40(%rbp)
movl %esi, %ecx
movq %rcx, -0x48(%rbp)
movl %r14d, %r13d
xorl %edx, %edx
movss 0x1017(%rip), %xmm2     # 0x16008
xorps %xmm3, %xmm3
movss 0x1090(%rip), %xmm4     # 0x1608c
movss 0x101c(%rip), %xmm5     # 0x16020
movsd 0x1d24(%rip), %xmm6     # 0x16d30
movq %rdx, %r15
imulq -0x50(%rbp), %r15
testl %r14d, %r14d
jle 0x150c8
movq %rdx, -0x58(%rbp)
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 0x15090
movss 0x103e(%rip), %xmm1     # 0x16090
callq 0x1180
movsd 0x1cd1(%rip), %xmm6     # 0x16d30
movss 0xfb9(%rip), %xmm5      # 0x16020
movss 0x101d(%rip), %xmm4     # 0x1608c
xorps %xmm3, %xmm3
movss 0xf8e(%rip), %xmm2      # 0x16008
movq -0x30(%rbp), %r11
mulss 0xffa(%rip), %xmm0      # 0x16080
addss 0x1006(%rip), %xmm0     # 0x16094
jmp 0x15098
mulss 0xfe0(%rip), %xmm0      # 0x16078
mulss %xmm5, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r11,%r14,2)
incq %r12
cmpq %r12, %r13
jne 0x15024
movq -0x60(%rbp), %rax
movl 0x54(%rax), %eax
movl -0x34(%rbp), %r14d
movq -0x58(%rbp), %rdx
testb $0x2, %al
jne 0x150fa
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, %ecx
movw %cx, (%r11,%r15,2)
incq %rdx
cmpq -0x48(%rbp), %rdx
jne 0x1500c
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movslq %r8d, %rcx
movq %rcx, -0x50(%rbp)
movslq %r9d, %rcx
movq %rcx, -0x40(%rbp)
movl %esi, %ecx
movq %rcx, -0x48(%rbp)
movl %r14d, %r12d
xorl %ecx, %ecx
movss 0xf57(%rip), %xmm1      # 0x1608c
movq %rcx, %r15
imulq -0x50(%rbp), %r15
testl %r14d, %r14d
jle 0x151b0
movq %rcx, -0x58(%rbp)
xorl %r14d, %r14d
movzwl -0xe0(%rbp,%r14,2), %r13d
addq %r15, %r13
movss (%rbx,%r13,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0x1518b
movss 0xf28(%rip), %xmm1      # 0x16090
callq 0x1180
movss 0xf17(%rip), %xmm1      # 0x1608c
movq -0x30(%rbp), %r11
mulss 0xeff(%rip), %xmm0      # 0x16080
addss 0xf0b(%rip), %xmm0      # 0x16094
jmp 0x15193
mulss 0xee5(%rip), %xmm0      # 0x16078
movss %xmm0, (%r11,%r13,4)
incq %r14
cmpq %r14, %r12
jne 0x15149
movq -0x60(%rbp), %rax
movl 0x54(%rax), %eax
movl -0x34(%rbp), %r14d
movq -0x58(%rbp), %rcx
testb $0x2, %al
jne 0x151c4
addq -0x40(%rbp), %r15
movss (%rbx,%r15,4), %xmm0
movss %xmm0, (%r11,%r15,4)
incq %rcx
cmpq -0x48(%rbp), %rcx
jne 0x15135
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movslq %r8d, %rax
movslq %r9d, %rcx
movl %esi, %edx
movl %r14d, %esi
xorl %edi, %edi
movss 0xea5(%rip), %xmm0      # 0x16098
movss 0xea1(%rip), %xmm1      # 0x1609c
leaq 0x198e(%rip), %r8       # 0x16b90
movss 0xdfe(%rip), %xmm2      # 0x16008
movss 0xdf2(%rip), %xmm3      # 0x16004
xorps %xmm4, %xmm4
movsd 0x1b13(%rip), %xmm5     # 0x16d30
movq %rdi, %r9
imulq %rax, %r9
testl %r14d, %r14d
jle 0x15293
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 0x1522c
movq -0x60(%rbp), %r10
testb $0x2, 0x54(%r10)
jne 0x152cb
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), %r14d
jne 0x1521d
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movslq %r8d, %rax
movq %rax, -0x50(%rbp)
movslq %r9d, %rax
movq %rax, -0x40(%rbp)
movl %esi, %eax
movq %rax, -0x48(%rbp)
movl %r14d, %r15d
xorl %r12d, %r12d
movss 0xcfe(%rip), %xmm2      # 0x16008
xorps %xmm3, %xmm3
movss 0xd77(%rip), %xmm4      # 0x1608c
movsd 0x1a43(%rip), %xmm5     # 0x16d60
movsd 0x1a0b(%rip), %xmm6     # 0x16d30
movq %r12, -0x58(%rbp)
imulq -0x50(%rbp), %r12
testl %r14d, %r14d
jle 0x153cf
xorl %r13d, %r13d
movzwl -0xe0(%rbp,%r13,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 0x153a6
movss 0xd28(%rip), %xmm1      # 0x16090
callq 0x1180
movsd 0x19bb(%rip), %xmm6     # 0x16d30
movsd 0x19e3(%rip), %xmm5     # 0x16d60
movss 0xd07(%rip), %xmm4      # 0x1608c
xorps %xmm3, %xmm3
movss 0xc78(%rip), %xmm2      # 0x16008
movq -0x30(%rbp), %r11
mulss 0xce4(%rip), %xmm0      # 0x16080
addss 0xcf0(%rip), %xmm0      # 0x16094
jmp 0x153ae
mulss 0xcca(%rip), %xmm0      # 0x16078
cvtss2sd %xmm0, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r11,%r14,4)
incq %r13
cmpq %r13, %r15
jne 0x1533a
movq -0x60(%rbp), %rax
testb $0x2, 0x54(%rax)
jne 0x15406
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), %r14d
jne 0x15325
jmp 0x1545c
testl %esi, %esi
jle 0x1545c
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
xorl %esi, %esi
testl %r8d, %r8d
jle 0x15451
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 0x1543d
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1542a
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c0e(%rip), %rdi      # 0x18083
leaq 0x23f8(%rip), %rsi      # 0x17874
leaq 0x2efe(%rip), %rcx      # 0x18381
movl $0x73b, %edx            # imm = 0x73B
callq 0x1080