// File: /workspace/github_c_makefile_star2_O2/algorithm-archivists[P]GathVL/src/objects/../../include/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++] = (stbir_uint16)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) * stbir__max_uint8_as_float ))
    #define STBIR__ENCODE_LINEAR16(f)  stbir__saturate16(STBIR__ROUND_INT((f) * stbir__max_uint16_as_float))
    #else
    #define STBIR__ENCODE_LINEAR8(f)   (unsigned char ) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint8_as_float )
    #define STBIR__ENCODE_LINEAR16(f)  (unsigned short) STBIR__ROUND_INT(stbir__saturate(f) * stbir__max_uint16_as_float)
    #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])) * stbir__max_uint16_as_float);
                }

                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])) * stbir__max_uint32_as_float);
                }
            }
            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]))) * stbir__max_uint32_as_float);
                }

                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])) * stbir__max_uint32_as_float);
            }
            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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, 0x20(%rsp)
movl 0x54(%rdi), %eax
movslq %r8d, %r13
movslq %r9d, %rbp
testb $0x1, %al
movq %rbp, 0x18(%rsp)
jne 0x17b5a
movl %ebp, %ecx
xorl %edx, %edx
testl %r8d, %r8d
cmovlel %edx, %r8d
testl %esi, %esi
movl $0x0, %r12d
cmovgl %esi, %r12d
leaq (%rbx,%rbp,4), %rdi
leaq (,%r13,4), %r10
movss 0x38f3(%rip), %xmm0     # 0x1b3fc
xorps %xmm1, %xmm1
movq %rbx, %r11
cmpq %r12, %rdx
je 0x17b66
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 0x17b52
cmpq %r15, %rcx
je 0x17b4d
movss (%r11,%r15,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r11,%r15,4)
incq %r15
jmp 0x17b33
incq %rdx
addq %r10, %r11
jmp 0x17b0f
xorl %ecx, %ecx
testl %r8d, %r8d
cmovgl %r8d, %ecx
movl %ecx, %r8d
movl 0xf0(%rsp), %ecx
xorl %ebp, %ebp
andl $0x2, %eax
xorl %edx, %edx
cmpl %edx, %r8d
je 0x17b90
movl %r9d, %edi
xorl %edx, %edi
orl %eax, %edi
je 0x17b8c
movslq %ebp, %rdi
incl %ebp
movw %dx, 0x30(%rsp,%rdi,2)
incl %edx
jmp 0x17b74
cmpl $0x7, %ecx
ja 0x1815f
movl %ecx, %eax
leaq 0x3bd2(%rip), %rcx      # 0x1b774
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq %r13, 0x28(%rsp)
jmpq *%rax
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
leaq (,%r13,4), %rdx
movss 0x3832(%rip), %xmm0     # 0x1b3fc
movss 0x3826(%rip), %xmm1     # 0x1b3f8
xorps %xmm2, %xmm2
movsd 0x46c3(%rip), %xmm3     # 0x1c2a0
cmpq %rsi, %rax
je 0x1814d
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x17c1c
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 0x17be9
incq %rax
addq %rdx, %rbx
addq %r13, %r14
jmp 0x17bdd
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
shlq $0x2, %r13
movss 0x37bf(%rip), %xmm0     # 0x1b3fc
xorps %xmm1, %xmm1
movsd 0x4668(%rip), %xmm2     # 0x1c2b0
movsd 0x4650(%rip), %xmm3     # 0x1c2a0
cmpq %rsi, %rax
je 0x1814d
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x17c8e
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 0x17c5b
incq %rax
addq %r13, %rbx
addq %r13, %r14
jmp 0x17c50
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
leaq (,%r13,4), %rdx
addq %r13, %r13
movss 0x3746(%rip), %xmm0     # 0x1b3fc
movss 0x3746(%rip), %xmm1     # 0x1b404
xorps %xmm2, %xmm2
movsd 0x45d7(%rip), %xmm3     # 0x1c2a0
cmpq %rsi, %rax
je 0x1814d
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x17d09
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 0x17cd5
incq %rax
addq %rdx, %rbx
addq %r13, %r14
jmp 0x17cc9
xorl %r12d, %r12d
testl %ebp, %ebp
cmovlel %r12d, %ebp
testl %esi, %esi
cmovlel %r12d, %esi
movss 0x36d1(%rip), %xmm2     # 0x1b3fc
movss 0x36d1(%rip), %xmm3     # 0x1b404
xorps %xmm4, %xmm4
movsd 0x4562(%rip), %xmm5     # 0x1c2a0
movss 0x372e(%rip), %xmm6     # 0x1b474
movq %rsi, 0x10(%rsp)
cmpq %rsi, %r12
je 0x1814d
movq %r12, 0x8(%rsp)
imulq %r13, %r12
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x17df3
movzwl 0x30(%rsp,%r13,2), %r15d
addq %r12, %r15
movss (%rbx,%r15,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm4, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm6
jae 0x17dce
movss 0x36e4(%rip), %xmm1     # 0x1b478
callq 0x5660
movss 0x36d3(%rip), %xmm6     # 0x1b474
movsd 0x44f7(%rip), %xmm5     # 0x1c2a0
xorps %xmm4, %xmm4
movss 0x3650(%rip), %xmm3     # 0x1b404
movss 0x3640(%rip), %xmm2     # 0x1b3fc
mulss 0x36a4(%rip), %xmm0     # 0x1b468
addss 0x36b0(%rip), %xmm0     # 0x1b47c
jmp 0x17dd6
mulss 0x368a(%rip), %xmm0     # 0x1b460
mulss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r14,%r15,2)
incq %r13
jmp 0x17d60
movq 0x20(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x17e2d
addq 0x18(%rsp), %r12
movss (%rbx,%r12,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,%r12,2)
movq 0x8(%rsp), %r12
incq %r12
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r13
jmp 0x17d4b
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
testl %esi, %esi
cmovlel %r15d, %esi
movss 0x3619(%rip), %xmm1     # 0x1b474
movq %rsi, 0x10(%rsp)
cmpq %rsi, %r15
je 0x1814d
movq %r15, 0x8(%rsp)
imulq %r13, %r15
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x17ec8
movzwl 0x30(%rsp,%r13,2), %r12d
addq %r15, %r12
movss (%rbx,%r12,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0x17eb5
movss 0x35e2(%rip), %xmm1     # 0x1b478
callq 0x5660
movss 0x35d1(%rip), %xmm1     # 0x1b474
mulss 0x35bd(%rip), %xmm0     # 0x1b468
addss 0x35c9(%rip), %xmm0     # 0x1b47c
jmp 0x17ebd
mulss 0x35a3(%rip), %xmm0     # 0x1b460
movss %xmm0, (%r14,%r12,4)
incq %r13
jmp 0x17e75
movq 0x20(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x17ee4
addq 0x18(%rsp), %r15
movss (%rbx,%r15,4), %xmm0
movss %xmm0, (%r14,%r15,4)
movq 0x8(%rsp), %r15
incq %r15
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r13
jmp 0x17e60
xorl %eax, %eax
testl %ebp, %ebp
cmovlel %eax, %ebp
testl %esi, %esi
cmovlel %eax, %esi
movss 0x34ed(%rip), %xmm0     # 0x1b3fc
movss 0x34e1(%rip), %xmm1     # 0x1b3f8
xorps %xmm2, %xmm2
movsd 0x437e(%rip), %xmm3     # 0x1c2a0
movss 0x3556(%rip), %xmm4     # 0x1b480
movss 0x3552(%rip), %xmm5     # 0x1b484
leaq 0x41b7(%rip), %rcx      # 0x1c0f0
cmpq %rsi, %rax
je 0x1814d
movq %rax, %rdx
imulq %r13, %rdx
xorl %r11d, %r11d
cmpq %r11, %rbp
je 0x17fa9
movzwl 0x30(%rsp,%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 0x17f4c
movq 0x20(%rsp), %rdi
testb $0x2, 0x54(%rdi)
jne 0x17fe1
addq 0x18(%rsp), %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 0x17f39
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
testl %esi, %esi
cmovlel %r15d, %esi
movss 0x33fc(%rip), %xmm2     # 0x1b3fc
xorps %xmm3, %xmm3
movsd 0x42a5(%rip), %xmm4     # 0x1c2b0
movsd 0x428d(%rip), %xmm5     # 0x1c2a0
movss 0x3459(%rip), %xmm6     # 0x1b474
movq %rsi, 0x10(%rsp)
cmpq %rsi, %r15
je 0x1814d
movq %r15, 0x8(%rsp)
imulq %r13, %r15
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x180c8
movzwl 0x30(%rsp,%r13,2), %r12d
addq %r15, %r12
movss (%rbx,%r12,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm6
jae 0x180a3
movss 0x340f(%rip), %xmm1     # 0x1b478
callq 0x5660
movss 0x33fe(%rip), %xmm6     # 0x1b474
movsd 0x4222(%rip), %xmm5     # 0x1c2a0
movsd 0x422a(%rip), %xmm4     # 0x1c2b0
xorps %xmm3, %xmm3
movss 0x336b(%rip), %xmm2     # 0x1b3fc
mulss 0x33cf(%rip), %xmm0     # 0x1b468
addss 0x33db(%rip), %xmm0     # 0x1b47c
jmp 0x180ab
mulss 0x33b5(%rip), %xmm0     # 0x1b460
cvtss2sd %xmm0, %xmm0
mulsd %xmm4, %xmm0
addsd %xmm5, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r14,%r12,4)
incq %r13
jmp 0x18035
movq 0x20(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x18101
addq 0x18(%rsp), %r15
movss (%rbx,%r15,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,%r15,4)
movq 0x8(%rsp), %r15
incq %r15
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r13
jmp 0x18020
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %esi
movl %r8d, %ecx
shlq $0x2, %r13
cmpq %rsi, %rax
je 0x1814d
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x18142
movss (%rbx,%rdx,4), %xmm0
movss %xmm0, (%r14,%rdx,4)
incq %rdx
jmp 0x1812d
incq %rax
addq %r13, %rbx
addq %r13, %r14
jmp 0x18126
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x549f(%rip), %rdi      # 0x1d605
leaq 0x4ca9(%rip), %rsi      # 0x1ce16
leaq 0x5774(%rip), %rcx      # 0x1d8e8
movl $0x743, %edx            # imm = 0x743
callq 0x5130