// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movl 0x54(%rdi), %eax
testl %esi, %esi
setle %cl
orb %al, %cl
testb $0x1, %cl
jne 0x1f58a
movl %r9d, %ecx
movslq %r8d, %rdx
movslq %r9d, %r10
movl %esi, %edi
leaq (%rbx,%r10,4), %r10
movl %edx, %r11d
xorl %r15d, %r15d
movss 0x3e4c(%rip), %xmm0     # 0x2337c
xorps %xmm1, %xmm1
xorl %r12d, %r12d
testl %r8d, %r8d
jle 0x1f57f
movq %r12, %rbp
imulq %rdx, %rbp
movl %r15d, %r13d
leaq (%rbx,%r13,4), %r13
movss (%r10,%rbp,4), %xmm2
movaps %xmm0, %xmm3
divss %xmm2, %xmm3
cmpneqss %xmm1, %xmm2
andps %xmm3, %xmm2
xorl %ebp, %ebp
cmpq %rbp, %rcx
je 0x1f577
movss (%r13,%rbp,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r13,%rbp,4)
incq %rbp
cmpq %rbp, %r11
jne 0x1f560
incq %r12
addl %r8d, %r15d
cmpq %rdi, %r12
jne 0x1f536
movl 0xf0(%rsp), %ecx
testl %r8d, %r8d
jle 0x1f5bb
xorl %edx, %edx
andl $0x2, %eax
xorl %r10d, %r10d
movl %r9d, %edi
xorl %edx, %edi
orl %eax, %edi
je 0x1f5b2
movslq %r10d, %rdi
incl %r10d
movw %dx, 0x30(%rsp,%rdi,2)
incl %edx
cmpl %edx, %r8d
jne 0x1f59e
jmp 0x1f5be
xorl %r10d, %r10d
cmpl $0x7, %ecx
ja 0x1fbfd
movl %ecx, %eax
leaq 0x41cc(%rip), %rcx      # 0x2379c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r10d, 0x4(%rsp)
jmpq *%rax
testl %esi, %esi
jle 0x1fbeb
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x3d87(%rip), %xmm0     # 0x2337c
movss 0x3d7b(%rip), %xmm1     # 0x23378
xorps %xmm2, %xmm2
movsd 0x4cb8(%rip), %xmm3     # 0x242c0
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1f64f
movl %edx, %r9d
leaq (%r14,%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 0x1f61d
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1f60a
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x3d06(%rip), %xmm0     # 0x2337c
xorps %xmm1, %xmm1
movsd 0x4c5f(%rip), %xmm2     # 0x242e0
movsd 0x4c37(%rip), %xmm3     # 0x242c0
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1f6d0
movl %edx, %r9d
leaq (%r14,%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 0x1f69e
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1f68b
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x3c85(%rip), %xmm0     # 0x2337c
movss 0x3c85(%rip), %xmm1     # 0x23384
xorps %xmm2, %xmm2
movsd 0x4bb6(%rip), %xmm3     # 0x242c0
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1f752
movl %edx, %r9d
leaq (%r14,%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 0x1f71f
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1f70c
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movslq %r8d, %rax
movq %rax, 0x18(%rsp)
movslq %r9d, %rax
movq %rax, 0x8(%rsp)
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %r10d, %r12d
xorl %r13d, %r13d
movss 0x3bed(%rip), %xmm2     # 0x2337c
xorps %xmm3, %xmm3
movss 0x3c5a(%rip), %xmm4     # 0x233f4
movss 0x3be2(%rip), %xmm5     # 0x23384
movsd 0x4b16(%rip), %xmm6     # 0x242c0
movq %r13, 0x20(%rsp)
imulq 0x18(%rsp), %r13
testl %r10d, %r10d
jle 0x1f84e
xorl %ebp, %ebp
movzwl 0x30(%rsp,%rbp,2), %r15d
addq %r13, %r15
movss (%rbx,%r15,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm4
jae 0x1f825
movss 0x3c0d(%rip), %xmm1     # 0x233f8
callq 0x5650
movsd 0x4ac8(%rip), %xmm6     # 0x242c0
movss 0x3b84(%rip), %xmm5     # 0x23384
movss 0x3bec(%rip), %xmm4     # 0x233f4
xorps %xmm3, %xmm3
movss 0x3b69(%rip), %xmm2     # 0x2337c
mulss 0x3bcd(%rip), %xmm0     # 0x233e8
addss 0x3bd9(%rip), %xmm0     # 0x233fc
jmp 0x1f82d
mulss 0x3bb3(%rip), %xmm0     # 0x233e0
mulss %xmm5, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r14,%r15,2)
incq %rbp
cmpq %rbp, %r12
jne 0x1f7c0
movq 0x28(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x1f888
addq 0x8(%rsp), %r13
movss (%rbx,%r13,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, (%r14,%r13,2)
movq 0x20(%rsp), %r13
incq %r13
cmpq 0x10(%rsp), %r13
movl 0x4(%rsp), %r10d
jne 0x1f7aa
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movslq %r8d, %rax
movq %rax, 0x18(%rsp)
movslq %r9d, %rax
movq %rax, 0x8(%rsp)
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %r10d, %r12d
xorl %r15d, %r15d
movss 0x3b22(%rip), %xmm1     # 0x233f4
movq %r15, 0x20(%rsp)
imulq 0x18(%rsp), %r15
testl %r10d, %r10d
jle 0x1f935
xorl %ebp, %ebp
movzwl 0x30(%rsp,%rbp,2), %r13d
addq %r15, %r13
movss (%rbx,%r13,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0x1f91f
movss 0x3af8(%rip), %xmm1     # 0x233f8
callq 0x5650
movss 0x3ae7(%rip), %xmm1     # 0x233f4
mulss 0x3ad3(%rip), %xmm0     # 0x233e8
addss 0x3adf(%rip), %xmm0     # 0x233fc
jmp 0x1f927
mulss 0x3ab9(%rip), %xmm0     # 0x233e0
movss %xmm0, (%r14,%r13,4)
incq %rbp
cmpq %rbp, %r12
jne 0x1f8e4
movq 0x28(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x1f951
addq 0x8(%rsp), %r15
movss (%rbx,%r15,4), %xmm0
movss %xmm0, (%r14,%r15,4)
movq 0x20(%rsp), %r15
incq %r15
cmpq 0x10(%rsp), %r15
movl 0x4(%rsp), %r10d
jne 0x1f8d2
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movslq %r8d, %rax
movslq %r9d, %rcx
movl %esi, %edx
movl %r10d, %esi
xorl %edi, %edi
movss 0x3a75(%rip), %xmm0     # 0x23400
movss 0x3a71(%rip), %xmm1     # 0x23404
leaq 0x4786(%rip), %r8       # 0x24120
movss 0x39da(%rip), %xmm2     # 0x2337c
movss 0x39ce(%rip), %xmm3     # 0x23378
xorps %xmm4, %xmm4
movsd 0x490b(%rip), %xmm5     # 0x242c0
movq %rdi, %r9
imulq %rax, %r9
testl %r10d, %r10d
jle 0x1fa1e
xorl %r10d, %r10d
movzwl 0x30(%rsp,%r10,2), %r11d
addq %r9, %r11
movss (%rbx,%r11,4), %xmm6
maxss %xmm0, %xmm6
movaps %xmm1, %xmm7
minss %xmm6, %xmm7
movd %xmm7, %r15d
leal -0x39000000(%r15), %r12d
shrl $0x14, %r12d
movl (%r8,%r12,4), %ebp
movzwl %bp, %r12d
shrl $0x7, %ebp
andl $0xfffe00, %ebp         # imm = 0xFFFE00
shrl $0xc, %r15d
movzbl %r15b, %r15d
imull %r12d, %r15d
addl %ebp, %r15d
shrl $0x10, %r15d
movb %r15b, (%r14,%r11)
incq %r10
cmpq %r10, %rsi
jne 0x1f9c4
movq 0x28(%rsp), %r10
testb $0x2, 0x54(%r10)
jne 0x1fa57
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, (%r14,%r9)
incq %rdi
cmpq %rdx, %rdi
movl 0x4(%rsp), %r10d
jne 0x1f9b5
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movslq %r8d, %rax
movq %rax, 0x18(%rsp)
movslq %r9d, %rax
movq %rax, 0x8(%rsp)
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %r10d, %r12d
xorl %r15d, %r15d
movss 0x38e2(%rip), %xmm2     # 0x2337c
xorps %xmm3, %xmm3
movss 0x394f(%rip), %xmm4     # 0x233f4
movsd 0x4833(%rip), %xmm5     # 0x242e0
movsd 0x480b(%rip), %xmm6     # 0x242c0
movq %r15, 0x20(%rsp)
imulq 0x18(%rsp), %r15
testl %r10d, %r10d
jle 0x1fb59
xorl %ebp, %ebp
movzwl 0x30(%rsp,%rbp,2), %r13d
addq %r15, %r13
movss (%rbx,%r13,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm4
jae 0x1fb30
movss 0x3902(%rip), %xmm1     # 0x233f8
callq 0x5650
movsd 0x47bd(%rip), %xmm6     # 0x242c0
movsd 0x47d5(%rip), %xmm5     # 0x242e0
movss 0x38e1(%rip), %xmm4     # 0x233f4
xorps %xmm3, %xmm3
movss 0x385e(%rip), %xmm2     # 0x2337c
mulss 0x38c2(%rip), %xmm0     # 0x233e8
addss 0x38ce(%rip), %xmm0     # 0x233fc
jmp 0x1fb38
mulss 0x38a8(%rip), %xmm0     # 0x233e0
cvtss2sd %xmm0, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r14,%r13,4)
incq %rbp
cmpq %rbp, %r12
jne 0x1facb
movq 0x28(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x1fb92
addq 0x8(%rsp), %r15
movss (%rbx,%r15,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, (%r14,%r15,4)
movq 0x20(%rsp), %r15
incq %r15
cmpq 0x10(%rsp), %r15
movl 0x4(%rsp), %r10d
jne 0x1fab5
jmp 0x1fbeb
testl %esi, %esi
jle 0x1fbeb
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1fbe0
movl %edx, %r9d
leaq (%r14,%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 0x1fbcc
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1fbb9
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5a35(%rip), %rdi      # 0x25639
leaq 0x523f(%rip), %rsi      # 0x24e4a
leaq 0x5d3c(%rip), %rcx      # 0x2594e
movl $0x743, %edx            # imm = 0x743
callq 0x5130