// File: /workspace/github_c_makefile_star2_O3/ender672[P]liboil/oil_resample.c
// Function: oil_scale_init
int oil_scale_init(struct oil_scale *os, int in_height, int out_height,
	int in_width, int out_width, enum oil_colorspace cs)
{
	int taps_x, taps_y, coeffs_x_len, coeffs_y_len, borders_x_len,
		borders_y_len, rb_len, sums_len, tmp_len;

	if (!os || in_height > MAX_DIMENSION || out_height > MAX_DIMENSION ||
		in_height < 1 || out_height < 1 ||
		in_width > MAX_DIMENSION || out_width > MAX_DIMENSION ||
		in_width < 1 || out_width < 1) {
		return -1;
	}

	// Lazy perform global init, in case oil_global_ini() hasn't been
	// called yet.
	if (!s2l_map[128]) {
		oil_global_init();
	}

	taps_x = calc_taps(in_width, out_width);
	taps_y = calc_taps(in_height, out_height);

	coeffs_x_len = calc_coeffs_len(in_width, out_width);
	borders_x_len = calc_borders_len(in_width, out_width);
	coeffs_y_len = calc_coeffs_len(in_height, out_height);
	borders_y_len = calc_borders_len(in_height, out_height);
	rb_len = out_width * OIL_CMP(cs) * taps_y * sizeof(float);
	tmp_len = max(taps_x, taps_y) * sizeof(float);
	sums_len = 0;
	if (out_height <= in_height) {
		sums_len = out_width * OIL_CMP(cs) * 4 * sizeof(float);
		rb_len = out_width * OIL_CMP(cs) * sizeof(float);
	}

	memset(os, 0, sizeof(struct oil_scale));
	os->in_height = in_height;
	os->out_height = out_height;
	os->in_width = in_width;
	os->out_width = out_width;
	os->cs = cs;
	os->coeffs_x = calloc(1, coeffs_x_len);
	os->borders_x = calloc(1, borders_x_len);
	os->coeffs_y = calloc(1, coeffs_y_len);
	os->borders_y = calloc(1, borders_y_len);
	os->rb = calloc(1, rb_len);
	os->sums_y = calloc(1, sums_len);
	os->tmp_coeffs = malloc(tmp_len);

	if (!os->coeffs_x || !os->borders_x || !os->coeffs_y ||
		!os->borders_y || !os->rb || !os->tmp_coeffs ||
		(sums_len && !os->sums_y)) {
		oil_scale_free(os);
		return -2;
	}

	set_coeffs(in_width, out_width, os->coeffs_x, os->borders_x, os->tmp_coeffs);
	set_coeffs(in_height, out_height, os->coeffs_y, os->borders_y, os->tmp_coeffs);

	return 0;
}

// Assembly:
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r8d, %r8d
jle 0x162d
testl %ecx, %ecx
jle 0x162d
cmpl $0xf4240, %r8d          # imm = 0xF4240
jg 0x162d
cmpl $0xf4240, %ecx          # imm = 0xF4240
jg 0x162d
movl %edx, %r10d
testl %edx, %edx
jle 0x162d
movl %esi, %r11d
testl %esi, %esi
jle 0x162d
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
testq %rdi, %rdi
je 0x161f
cmpl $0xf4240, %r11d         # imm = 0xF4240
jg 0x161f
cmpl $0xf4240, %r10d         # imm = 0xF4240
jg 0x161f
movss 0x5e77(%rip), %xmm0     # 0x72c0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1476
jp 0x1476
movl %r10d, %ebx
movl %r9d, %r13d
movq %r11, %r14
movl %r8d, %ebp
movq %rcx, %r12
callq 0x122c
movq %r12, %rcx
movl %ebp, %r8d
movq %r14, %r11
movl %r13d, %r9d
movl %ebx, %r10d
movl $0x4, %edx
movl $0x4, %edi
cmpl %ecx, %r8d
ja 0x149e
leal (,%rcx,4), %eax
xorl %edx, %edx
divl %r8d
movl $0x4, %edx
movl %eax, %edi
andl $0x7ffffffe, %edi       # imm = 0x7FFFFFFE
movl $0x4, %eax
cmpl %r11d, %r10d
jg 0x14bc
leal (,%r11,4), %eax
cltd
idivl %r10d
andl $-0x2, %eax
movl $0x1, %edx
cmpl %r8d, %ecx
movl %r8d, %esi
cmoval %ecx, %esi
movl %r8d, %r12d
cmovbl %ecx, %r12d
shll $0x4, %esi
shll $0x2, %r12d
cmpl %r10d, %r11d
movl %r10d, %ebp
cmovgl %r11d, %ebp
movl %r10d, %ebx
cmovll %r11d, %ebx
shll $0x4, %ebp
shll $0x2, %ebx
movzbl %r9b, %r14d
imull %r8d, %r14d
cmpl %eax, %edi
cmovgl %edi, %eax
shll $0x2, %eax
movl %eax, 0x14(%rsp)
movl %r14d, %eax
shll $0x4, %eax
xorl %r13d, %r13d
cmpl %r11d, %r10d
cmovlel %eax, %r13d
imull %edx, %r14d
shll $0x2, %r14d
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15)
movq %r11, 0x20(%rsp)
movl %r11d, (%r15)
movl %r10d, 0x10(%rsp)
movl %r10d, 0x4(%r15)
movq %rcx, 0x18(%rsp)
movl %ecx, 0x8(%r15)
movl %r8d, 0xc(%rsp)
movl %r8d, 0xc(%r15)
movl %r9d, 0x10(%r15)
movl $0x1, %edi
callq 0x10d0
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%r15)
movl $0x1, %edi
movq %r12, %rsi
callq 0x10d0
movq %rax, %r12
movq %rax, 0x30(%r15)
movslq %ebp, %rsi
movl %r13d, %ebp
movl $0x1, %edi
callq 0x10d0
movq %rax, %r13
movq %rax, 0x20(%r15)
movslq %ebx, %rsi
movl $0x1, %edi
callq 0x10d0
movq %rax, %rbx
movq %rax, 0x38(%r15)
movslq %r14d, %rsi
movl $0x1, %edi
callq 0x10d0
movq %rax, 0x28(%rsp)
movq %rax, 0x48(%r15)
movslq %ebp, %rsi
movl $0x1, %edi
callq 0x10d0
movq %rax, %r14
movq %rax, 0x40(%r15)
movslq 0x14(%rsp), %rdi
callq 0x1100
movq 0x30(%rsp), %rdx
movq %rax, 0x50(%r15)
movq %rdx, %xmm0
movq %rbx, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r12, %xmm1
movq %r13, %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
pxor %xmm2, %xmm2
pcmpeqd %xmm2, %xmm1
pcmpeqd %xmm2, %xmm0
movdqa %xmm1, %xmm2
shufps $0xdd, %xmm0, %xmm2     # xmm2 = xmm2[1,3],xmm0[1,3]
shufps $0x88, %xmm0, %xmm1     # xmm1 = xmm1[0,2],xmm0[0,2]
andps %xmm2, %xmm1
movmskps %xmm1, %esi
testl %esi, %esi
je 0x162e
movq %r15, %rdi
callq 0x167f
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x28(%rsp)
je 0x1612
testq %rax, %rax
je 0x1612
testl %ebp, %ebp
sete %dil
testq %r14, %r14
setne %sil
orb %dil, %sil
je 0x1612
movq 0x18(%rsp), %rdi
movl 0xc(%rsp), %esi
movq %r12, %rcx
movq %rax, %r8
callq 0x16f1
movq 0x20(%r15), %rdx
movq 0x38(%r15), %rcx
movq 0x50(%r15), %r8
movq 0x20(%rsp), %rdi
movl 0x10(%rsp), %esi
callq 0x16f1
xorl %eax, %eax
jmp 0x161f