// File: chhylp123[P]hifiasm/rcut.cpp
// Function: get_w_scale(kv_u_trans_t*)
double get_w_scale(kv_u_trans_t *ta)
{
	uint32_t i, max_w_i, min_w_i;
	double max_w = 0, min_w = 0, w;
	max_w_i = min_w_i = (uint32_t)-1;
	for (i = 0; i < ta->n; ++i)
	{
		if(ta->a[i].del) continue;
		if(ta->a[i].nw == 0) continue;
		w = (ta->a[i].nw >= 0? ta->a[i].nw:-ta->a[i].nw);
		if(max_w_i == (uint32_t)-1 || max_w < w) max_w = w, max_w_i = i;
		if(min_w_i == (uint32_t)-1 || min_w > w) min_w = w, min_w_i = i;
	}

	if(max_w_i == (uint32_t)-1 || min_w_i == (uint32_t)-1) return 1;
	if(min_w > 1.1) return 1;
	double sc_max = (double)(1<<30), sc_min = 1.1;

	return MIN(sc_max/max_w, sc_min/min_w) + sc_min;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x219b38
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x28(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x219a3e
jmp 0x219b2a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x219a65
jp 0x219a65
jmp 0x219b2a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x219aa3
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x219ad6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cmpl $-0x1, -0x18(%rbp)
je 0x219af6
movsd -0x28(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x219b06
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x1c(%rbp)
je 0x219b18
movsd -0x30(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x219b28
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x219b2a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x219a0d
cmpl $-0x1, -0x18(%rbp)
je 0x219b44
cmpl $-0x1, -0x1c(%rbp)
jne 0x219b56
movsd 0x1684b4(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x8(%rbp)
jmp 0x219bdb
movsd -0x30(%rbp), %xmm0
movsd 0x16cce5(%rip), %xmm1   # 0x386848
ucomisd %xmm1, %xmm0
jbe 0x219b78
movsd 0x16848f(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x8(%rbp)
jmp 0x219bdb
movsd 0x167dd0(%rip), %xmm0   # 0x381950
movsd %xmm0, -0x40(%rbp)
movsd 0x16ccbb(%rip), %xmm0   # 0x386848
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x219bbd
movsd -0x40(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x219bcc
movsd -0x48(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
popq %rbp
retq
nopw %cs:(%rax,%rax)