// File: /workspace/github_c_makefile_star2_O3/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 0x1fadb
movl %r9d, %ecx
movslq %r8d, %rdx
movslq %r9d, %r10
movl %esi, %edi
leaq (%rbx,%r10,4), %r10
movl %edx, %r11d
xorl %r15d, %r15d
movss 0x397b(%rip), %xmm0     # 0x233fc
xorps %xmm1, %xmm1
xorl %r12d, %r12d
testl %r8d, %r8d
jle 0x1fad0
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 0x1fac8
movss (%r13,%rbp,4), %xmm3
mulss %xmm2, %xmm3
movss %xmm3, (%r13,%rbp,4)
incq %rbp
cmpq %rbp, %r11
jne 0x1fab1
incq %r12
addl %r8d, %r15d
cmpq %rdi, %r12
jne 0x1fa87
movl 0xf0(%rsp), %ecx
testl %r8d, %r8d
jle 0x1fb11
xorl %edx, %edx
movl %eax, %edi
andl $0x2, %edi
xorl %r13d, %r13d
movl %r9d, %r10d
xorl %edx, %r10d
orl %edi, %r10d
je 0x1fb08
movslq %r13d, %r10
incl %r13d
movw %dx, 0x30(%rsp,%r10,2)
incl %edx
cmpl %edx, %r8d
jne 0x1faf1
jmp 0x1fb14
xorl %r13d, %r13d
cmpl $0x7, %ecx
ja 0x20154
movl %ecx, %ecx
leaq 0x3db6(%rip), %rdx      # 0x238dc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movl %r13d, 0x4(%rsp)
jmpq *%rcx
testl %esi, %esi
jle 0x20142
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x38b1(%rip), %xmm0     # 0x233fc
movss 0x38a5(%rip), %xmm1     # 0x233f8
xorps %xmm2, %xmm2
movsd 0x48ba(%rip), %xmm3     # 0x24418
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1fba5
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 0x1fb73
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1fb60
jmp 0x20142
testl %esi, %esi
jle 0x20142
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x3830(%rip), %xmm0     # 0x233fc
xorps %xmm1, %xmm1
movsd 0x4839(%rip), %xmm2     # 0x24410
movsd 0x4839(%rip), %xmm3     # 0x24418
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1fc26
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 0x1fbf4
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1fbe1
jmp 0x20142
testl %esi, %esi
jle 0x20142
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
movss 0x37af(%rip), %xmm0     # 0x233fc
movss 0x37af(%rip), %xmm1     # 0x23404
xorps %xmm2, %xmm2
movsd 0x47b8(%rip), %xmm3     # 0x24418
xorl %esi, %esi
testl %r8d, %r8d
jle 0x1fca8
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 0x1fc75
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x1fc62
jmp 0x20142
testl %esi, %esi
jle 0x20142
movslq %r8d, %rcx
movq %rcx, 0x18(%rsp)
movslq %r9d, %rcx
movq %rcx, 0x8(%rsp)
movl %esi, %ecx
movq %rcx, 0x10(%rsp)
movl %r13d, %r15d
xorl %edx, %edx
movss 0x3718(%rip), %xmm2     # 0x233fc
xorps %xmm3, %xmm3
movss 0x3785(%rip), %xmm4     # 0x23474
movss 0x370d(%rip), %xmm5     # 0x23404
movsd 0x4719(%rip), %xmm6     # 0x24418
movq %rdx, %r12
imulq 0x18(%rsp), %r12
testl %r13d, %r13d
jle 0x1fdb8
movq %rdx, 0x20(%rsp)
xorl %ebp, %ebp
movzwl 0x30(%rsp,%rbp,2), %r13d
addq %r12, %r13
movss (%rbx,%r13,4), %xmm0
movaps %xmm2, %xmm1
minss %xmm0, %xmm1
cmpltss %xmm3, %xmm0
andnps %xmm1, %xmm0
ucomiss %xmm0, %xmm4
jae 0x1fd7d
movss 0x3735(%rip), %xmm1     # 0x23478
callq 0x5640
movsd 0x46c8(%rip), %xmm6     # 0x24418
movss 0x36ac(%rip), %xmm5     # 0x23404
movss 0x3714(%rip), %xmm4     # 0x23474
xorps %xmm3, %xmm3
movss 0x3691(%rip), %xmm2     # 0x233fc
mulss 0x36f5(%rip), %xmm0     # 0x23468
addss 0x3701(%rip), %xmm0     # 0x2347c
jmp 0x1fd85
mulss 0x36db(%rip), %xmm0     # 0x23460
mulss %xmm5, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %eax
movw %ax, (%r14,%r13,2)
incq %rbp
cmpq %rbp, %r15
jne 0x1fd18
movq 0x28(%rsp), %rax
movl 0x54(%rax), %eax
movl 0x4(%rsp), %r13d
movq 0x20(%rsp), %rdx
testb $0x2, %al
jne 0x1fdeb
addq 0x8(%rsp), %r12
movss (%rbx,%r12,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, (%r14,%r12,2)
incq %rdx
cmpq 0x10(%rsp), %rdx
jne 0x1fcff
jmp 0x20142
testl %esi, %esi
jle 0x20142
movslq %r8d, %rcx
movq %rcx, 0x18(%rsp)
movslq %r9d, %rcx
movq %rcx, 0x8(%rsp)
movl %esi, %ecx
movq %rcx, 0x10(%rsp)
movl %r13d, %r12d
xorl %ecx, %ecx
movss 0x364a(%rip), %xmm1     # 0x23474
movq %rcx, %r15
imulq 0x18(%rsp), %r15
testl %r13d, %r13d
jle 0x1fea2
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
movzwl 0x30(%rsp,%rbp,2), %r13d
addq %r15, %r13
movss (%rbx,%r13,4), %xmm0
ucomiss %xmm0, %xmm1
jae 0x1fe7a
movss 0x361d(%rip), %xmm1     # 0x23478
callq 0x5640
movss 0x360c(%rip), %xmm1     # 0x23474
mulss 0x35f8(%rip), %xmm0     # 0x23468
addss 0x3604(%rip), %xmm0     # 0x2347c
jmp 0x1fe82
mulss 0x35de(%rip), %xmm0     # 0x23460
movss %xmm0, (%r14,%r13,4)
incq %rbp
cmpq %rbp, %r12
jne 0x1fe3f
movq 0x28(%rsp), %rax
movl 0x54(%rax), %eax
movl 0x4(%rsp), %r13d
movq 0x20(%rsp), %rcx
testb $0x2, %al
jne 0x1feb7
addq 0x8(%rsp), %r15
movss (%rbx,%r15,4), %xmm0
movss %xmm0, (%r14,%r15,4)
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x1fe2a
jmp 0x20142
testl %esi, %esi
jle 0x20142
movslq %r8d, %rax
movslq %r9d, %rcx
movl %esi, %edx
movl %r13d, %esi
xorl %edi, %edi
movss 0x3599(%rip), %xmm0     # 0x23480
movss 0x3595(%rip), %xmm1     # 0x23484
leaq 0x436a(%rip), %r8       # 0x24260
movss 0x34fe(%rip), %xmm2     # 0x233fc
movss 0x34f2(%rip), %xmm3     # 0x233f8
xorps %xmm4, %xmm4
movsd 0x4507(%rip), %xmm5     # 0x24418
movq %rdi, %r9
imulq %rax, %r9
testl %r13d, %r13d
jle 0x1ff7a
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 0x1ff20
movq 0x28(%rsp), %r10
testb $0x2, 0x54(%r10)
jne 0x1ffb3
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
jne 0x1ff11
jmp 0x20142
testl %esi, %esi
jle 0x20142
movslq %r8d, %rax
movq %rax, 0x18(%rsp)
movslq %r9d, %rax
movq %rax, 0x8(%rsp)
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %r13d, %r12d
xorl %r15d, %r15d
movss 0x340b(%rip), %xmm2     # 0x233fc
xorps %xmm3, %xmm3
movss 0x3478(%rip), %xmm4     # 0x23474
movsd 0x440c(%rip), %xmm5     # 0x24410
movsd 0x440c(%rip), %xmm6     # 0x24418
movq %r15, 0x20(%rsp)
imulq 0x18(%rsp), %r15
testl %r13d, %r13d
jle 0x200b0
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 0x20087
movss 0x342b(%rip), %xmm1     # 0x23478
callq 0x5640
movsd 0x43be(%rip), %xmm6     # 0x24418
movsd 0x43ae(%rip), %xmm5     # 0x24410
movss 0x340a(%rip), %xmm4     # 0x23474
xorps %xmm3, %xmm3
movss 0x3387(%rip), %xmm2     # 0x233fc
mulss 0x33eb(%rip), %xmm0     # 0x23468
addss 0x33f7(%rip), %xmm0     # 0x2347c
jmp 0x2008f
mulss 0x33d1(%rip), %xmm0     # 0x23460
cvtss2sd %xmm0, %xmm0
mulsd %xmm5, %xmm0
addsd %xmm6, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, (%r14,%r13,4)
incq %rbp
cmpq %rbp, %r12
jne 0x20022
movq 0x28(%rsp), %rax
testb $0x2, 0x54(%rax)
jne 0x200e9
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), %r13d
jne 0x2000c
jmp 0x20142
testl %esi, %esi
jle 0x20142
movl %esi, %eax
movl %r8d, %ecx
xorl %edx, %edx
xorl %esi, %esi
testl %r8d, %r8d
jle 0x20137
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 0x20123
incq %rsi
addl %r8d, %edx
cmpq %rax, %rsi
jne 0x20110
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5612(%rip), %rdi      # 0x2576d
leaq 0x4e1c(%rip), %rsi      # 0x24f7e
leaq 0x58e7(%rip), %rcx      # 0x25a50
movl $0x743, %edx            # imm = 0x743
callq 0x5130