// File: lunasorcery[P]brailify/./stb/stb_image_resize.h
// Function: stbir__resize_allocated(stbir__info*, void const*, int, void*, int, int, unsigned int, stbir_datatype, stbir_edge, stbir_edge, stbir_colorspace, void*, unsigned long)
static int stbir__resize_allocated(stbir__info *info,
    const void* input_data, int input_stride_in_bytes,
    void* output_data, int output_stride_in_bytes,
    int alpha_channel, stbir_uint32 flags, stbir_datatype type,
    stbir_edge edge_horizontal, stbir_edge edge_vertical, stbir_colorspace colorspace,
    void* tempmem, size_t tempmem_size_in_bytes)
{
    size_t memory_required = stbir__calculate_memory(info);

    int width_stride_input = input_stride_in_bytes ? input_stride_in_bytes : info->channels * info->input_w * stbir__type_size[type];
    int width_stride_output = output_stride_in_bytes ? output_stride_in_bytes : info->channels * info->output_w * stbir__type_size[type];

#ifdef STBIR_DEBUG_OVERWRITE_TEST
#define OVERWRITE_ARRAY_SIZE 8
    unsigned char overwrite_output_before_pre[OVERWRITE_ARRAY_SIZE];
    unsigned char overwrite_tempmem_before_pre[OVERWRITE_ARRAY_SIZE];
    unsigned char overwrite_output_after_pre[OVERWRITE_ARRAY_SIZE];
    unsigned char overwrite_tempmem_after_pre[OVERWRITE_ARRAY_SIZE];

    size_t begin_forbidden = width_stride_output * (info->output_h - 1) + info->output_w * info->channels * stbir__type_size[type];
    memcpy(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE);
    memcpy(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE);
    memcpy(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE);
    memcpy(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE);
#endif

    STBIR_ASSERT(info->channels >= 0);
    STBIR_ASSERT(info->channels <= STBIR_MAX_CHANNELS);

    if (info->channels < 0 || info->channels > STBIR_MAX_CHANNELS)
        return 0;

    STBIR_ASSERT(info->horizontal_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table));
    STBIR_ASSERT(info->vertical_filter < STBIR__ARRAY_SIZE(stbir__filter_info_table));

    if (info->horizontal_filter >= STBIR__ARRAY_SIZE(stbir__filter_info_table))
        return 0;
    if (info->vertical_filter >= STBIR__ARRAY_SIZE(stbir__filter_info_table))
        return 0;

    if (alpha_channel < 0)
        flags |= STBIR_FLAG_ALPHA_USES_COLORSPACE | STBIR_FLAG_ALPHA_PREMULTIPLIED;

    if (!(flags&STBIR_FLAG_ALPHA_USES_COLORSPACE) || !(flags&STBIR_FLAG_ALPHA_PREMULTIPLIED))
        STBIR_ASSERT(alpha_channel >= 0 && alpha_channel < info->channels);

    if (alpha_channel >= info->channels)
        return 0;

    STBIR_ASSERT(tempmem);

    if (!tempmem)
        return 0;

    STBIR_ASSERT(tempmem_size_in_bytes >= memory_required);

    if (tempmem_size_in_bytes < memory_required)
        return 0;

    memset(tempmem, 0, tempmem_size_in_bytes);

    info->input_data = input_data;
    info->input_stride_bytes = width_stride_input;

    info->output_data = output_data;
    info->output_stride_bytes = width_stride_output;

    info->alpha_channel = alpha_channel;
    info->flags = flags;
    info->type = type;
    info->edge_horizontal = edge_horizontal;
    info->edge_vertical = edge_vertical;
    info->colorspace = colorspace;

    info->horizontal_coefficient_width   = stbir__get_coefficient_width  (info->horizontal_filter, info->horizontal_scale);
    info->vertical_coefficient_width     = stbir__get_coefficient_width  (info->vertical_filter  , info->vertical_scale  );
    info->horizontal_filter_pixel_width  = stbir__get_filter_pixel_width (info->horizontal_filter, info->horizontal_scale);
    info->vertical_filter_pixel_width    = stbir__get_filter_pixel_width (info->vertical_filter  , info->vertical_scale  );
    info->horizontal_filter_pixel_margin = stbir__get_filter_pixel_margin(info->horizontal_filter, info->horizontal_scale);
    info->vertical_filter_pixel_margin   = stbir__get_filter_pixel_margin(info->vertical_filter  , info->vertical_scale  );

    info->ring_buffer_length_bytes = info->output_w * info->channels * sizeof(float);
    info->decode_buffer_pixels = info->input_w + info->horizontal_filter_pixel_margin * 2;

#define STBIR__NEXT_MEMPTR(current, newtype) (newtype*)(((unsigned char*)current) + current##_size)

    info->horizontal_contributors = (stbir__contributors *) tempmem;
    info->horizontal_coefficients = STBIR__NEXT_MEMPTR(info->horizontal_contributors, float);
    info->vertical_contributors = STBIR__NEXT_MEMPTR(info->horizontal_coefficients, stbir__contributors);
    info->vertical_coefficients = STBIR__NEXT_MEMPTR(info->vertical_contributors, float);
    info->decode_buffer = STBIR__NEXT_MEMPTR(info->vertical_coefficients, float);

    if (stbir__use_height_upsampling(info))
    {
        info->horizontal_buffer = NULL;
        info->ring_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float);
        info->encode_buffer = STBIR__NEXT_MEMPTR(info->ring_buffer, float);

        STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->encode_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
    }
    else
    {
        info->horizontal_buffer = STBIR__NEXT_MEMPTR(info->decode_buffer, float);
        info->ring_buffer = STBIR__NEXT_MEMPTR(info->horizontal_buffer, float);
        info->encode_buffer = NULL;

        STBIR_ASSERT((size_t)STBIR__NEXT_MEMPTR(info->ring_buffer, unsigned char) == (size_t)tempmem + tempmem_size_in_bytes);
    }

#undef STBIR__NEXT_MEMPTR

    // This signals that the ring buffer is empty
    info->ring_buffer_begin_index = -1;

    stbir__calculate_filters(info, info->horizontal_contributors, info->horizontal_coefficients, info->horizontal_filter, info->horizontal_scale, info->horizontal_shift, info->input_w, info->output_w);
    stbir__calculate_filters(info, info->vertical_contributors, info->vertical_coefficients, info->vertical_filter, info->vertical_scale, info->vertical_shift, info->input_h, info->output_h);

    STBIR_PROGRESS_REPORT(0);

    if (stbir__use_height_upsampling(info))
        stbir__buffer_loop_upsample(info);
    else
        stbir__buffer_loop_downsample(info);

    STBIR_PROGRESS_REPORT(1);

#ifdef STBIR_DEBUG_OVERWRITE_TEST
    STBIR_ASSERT(memcmp(overwrite_output_before_pre, &((unsigned char*)output_data)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
    STBIR_ASSERT(memcmp(overwrite_output_after_pre, &((unsigned char*)output_data)[begin_forbidden], OVERWRITE_ARRAY_SIZE) == 0);
    STBIR_ASSERT(memcmp(overwrite_tempmem_before_pre, &((unsigned char*)tempmem)[-OVERWRITE_ARRAY_SIZE], OVERWRITE_ARRAY_SIZE) == 0);
    STBIR_ASSERT(memcmp(overwrite_tempmem_after_pre, &((unsigned char*)tempmem)[tempmem_size_in_bytes], OVERWRITE_ARRAY_SIZE) == 0);
#endif

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x19b30
movl %eax, %eax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x19e53
movl -0x1c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x19e78
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x8(%rcx), %eax
movl 0x18(%rbp), %ecx
movl %ecx, %edx
leaq 0xc6a2(%rip), %rcx      # 0x26510
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x19e8c
movl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x19eb1
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x20(%rcx), %eax
movl 0x18(%rbp), %ecx
movl %ecx, %edx
leaq 0xc669(%rip), %rcx      # 0x26510
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jl 0x19ec3
jmp 0x19ee2
leaq 0x7464(%rip), %rdi      # 0x2132e
leaq 0x7299(%rip), %rsi      # 0x2116a
movl $0x8ff, %edx            # imm = 0x8FF
leaq 0x7465(%rip), %rcx      # 0x21342
callq 0x1090
movq -0x10(%rbp), %rax
cmpl $0x40, 0x4c(%rax)
jg 0x19eee
jmp 0x19f0d
leaq 0x74f5(%rip), %rdi      # 0x213ea
leaq 0x726e(%rip), %rsi      # 0x2116a
movl $0x900, %edx            # imm = 0x900
leaq 0x743a(%rip), %rcx      # 0x21342
callq 0x1090
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jl 0x19f21
movq -0x10(%rbp), %rax
cmpl $0x40, 0x4c(%rax)
jle 0x19f2d
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %eax
cmpq $0x6, %rax
jae 0x19f3c
jmp 0x19f5b
leaq 0x7274(%rip), %rdi      # 0x211b7
leaq 0x7220(%rip), %rsi      # 0x2116a
movl $0x905, %edx            # imm = 0x905
leaq 0x73ec(%rip), %rcx      # 0x21342
callq 0x1090
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
cmpq $0x6, %rax
jae 0x19f6a
jmp 0x19f89
leaq 0x72c6(%rip), %rdi      # 0x21237
leaq 0x71f2(%rip), %rsi      # 0x2116a
movl $0x906, %edx            # imm = 0x906
leaq 0x73be(%rip), %rcx      # 0x21342
callq 0x1090
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %eax
cmpq $0x6, %rax
jb 0x19fa2
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
movq -0x10(%rbp), %rax
movl 0x60(%rax), %eax
cmpq $0x6, %rax
jb 0x19fbb
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
cmpl $0x0, -0x30(%rbp)
jge 0x19fca
movl 0x10(%rbp), %eax
orl $0x3, %eax
movl %eax, 0x10(%rbp)
movl 0x10(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x19fe0
movl 0x10(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1a027
xorl %eax, %eax
cmpl $0x0, -0x30(%rbp)
movb %al, -0x49(%rbp)
jl 0x19ffb
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
setl %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x1a004
jmp 0x1a006
jmp 0x1a025
leaq 0x73f2(%rip), %rdi      # 0x213ff
leaq 0x7156(%rip), %rsi      # 0x2116a
movl $0x911, %edx            # imm = 0x911
leaq 0x7322(%rip), %rcx      # 0x21342
callq 0x1090
jmp 0x1a027
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4c(%rcx), %eax
jl 0x1a03f
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
cmpq $0x0, 0x38(%rbp)
je 0x1a048
jmp 0x1a067
leaq 0x73e5(%rip), %rdi      # 0x21434
leaq 0x7114(%rip), %rsi      # 0x2116a
movl $0x916, %edx            # imm = 0x916
leaq 0x72e0(%rip), %rcx      # 0x21342
callq 0x1090
cmpq $0x0, 0x38(%rbp)
jne 0x1a07a
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
movq 0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0x1a086
jmp 0x1a0a5
leaq 0x73af(%rip), %rdi      # 0x2143c
leaq 0x70d6(%rip), %rsi      # 0x2116a
movl $0x91b, %edx            # imm = 0x91B
leaq 0x72a2(%rip), %rcx      # 0x21342
callq 0x1090
movq 0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x1a0bb
movl $0x0, -0x4(%rbp)
jmp 0x1a4e0
movq 0x38(%rbp), %rdi
movq 0x40(%rbp), %rdx
xorl %esi, %esi
callq 0x1070
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movl 0x10(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movl 0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movl 0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x64(%rax)
movl 0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
movl 0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x44(%rax), %xmm0
callq 0x1ac30
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xa8(%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x48(%rax), %xmm0
callq 0x1ac30
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xac(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x44(%rax), %xmm0
callq 0x1a550
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xb0(%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x48(%rax), %xmm0
callq 0x1a550
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x44(%rax), %xmm0
callq 0x1a520
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xb8(%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %edi
movq -0x10(%rbp), %rax
movss 0x48(%rax), %xmm0
callq 0x1a520
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xbc(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x4c(%rcx), %eax
cltq
shlq $0x2, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc8(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %eax
shll %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x90(%rax)
movq 0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xe8(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xec(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xf0(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xf4(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x10(%rbp), %rdi
callq 0x1a730
cmpl $0x0, %eax
je 0x1a37f
movq -0x10(%rbp), %rax
movq $0x0, 0xa0(%rax)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xf8(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0x100(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xe0(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x104(%rcx), %rcx
addq %rcx, %rax
movq 0x38(%rbp), %rcx
addq 0x40(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1a35b
jmp 0x1a37a
leaq 0x7103(%rip), %rdi      # 0x21465
leaq 0x6e01(%rip), %rsi      # 0x2116a
movl $0x947, %edx            # imm = 0x947
leaq 0x6fcd(%rip), %rcx      # 0x21342
callq 0x1090
jmp 0x1a41f
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xf8(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0xfc(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0xe0(%rax)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x100(%rcx), %rcx
addq %rcx, %rax
movq 0x38(%rbp), %rcx
addq 0x40(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1a3fe
jmp 0x1a41d
leaq 0x70e6(%rip), %rdi      # 0x214eb
leaq 0x6d5e(%rip), %rsi      # 0x2116a
movl $0x94f, %edx            # imm = 0x94F
leaq 0x6f2a(%rip), %rcx      # 0x21342
callq 0x1090
jmp 0x1a41f
movq -0x10(%rbp), %rax
movl $0xffffffff, 0xd4(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %ecx
movq -0x10(%rbp), %rax
movss 0x44(%rax), %xmm0
movq -0x10(%rbp), %rax
movss 0x3c(%rax), %xmm1
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0x10(%rbp), %rax
movl 0x20(%rax), %r9d
callq 0x1acd0
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %rax
movss 0x48(%rax), %xmm0
movq -0x10(%rbp), %rax
movss 0x40(%rax), %xmm1
movq -0x10(%rbp), %rax
movl 0xc(%rax), %r8d
movq -0x10(%rbp), %rax
movl 0x24(%rax), %r9d
callq 0x1acd0
movq -0x10(%rbp), %rdi
callq 0x1a730
cmpl $0x0, %eax
je 0x1a4d0
movq -0x10(%rbp), %rdi
callq 0x1af80
jmp 0x1a4d9
movq -0x10(%rbp), %rdi
callq 0x1b1a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)