// File: /workspace/github_c_makefile_star2_O2/intel[P]pf-bb-config/vrb2/vrb2_cfg_app.c
// Function: vrb2_fft_reconfig
static int
vrb2_fft_reconfig(uint8_t *d, int template_idx, bool lut_programming, hw_device *accel_pci_dev)
{
	int16_t gTDWinCoff[VRB2_LUT_SIZE], ret, offset, i, pageIdx;
	const char *lut_filename;
	FILE *fp;
	bool unsafe_path;

	/* Default FFT configuration. */
	vrb2_reg_write(d, HWPfFftConfig0 + template_idx * 0x1000,
			b0_variant ? VRB2_FFT_CFG_0 : VRB2_FFT_CFG_0_A0);
	vrb2_reg_write(d, HWPfFftParityMask8 + template_idx * 0x1000,
			b0_variant ? VRB2_FFT_ECC : VRB2_FFT_ECC_A0);

	if (!lut_programming)
		return 0;

	/* Load the FFT windows LUT. */
	lut_filename = accel_pci_dev->fft_lut_filename;
	unsafe_path = cfg_file_check_path_safety(lut_filename);
	if (unsafe_path == true) {
		LOG(ERR, "error, FFT LUT file path \"%s\" is not safe", lut_filename);
		return -ENOENT;
	}

	fp = fopen(lut_filename, "rb");
	if (fp == NULL) {
		LOG(ERR, "  Error reading from %s on engine %d ", lut_filename, template_idx);
		return -ENOENT;
	}
	ret = fread((char *)gTDWinCoff, VRB2_LUT_SIZE * 2, 1, fp);
	if (ret <= 0) {
		LOG(ERR, "  Error reading from %s on engine %d ", lut_filename, template_idx);
		fclose(fp);
		return -ENOENT;
	}
	if (template_idx == 0)
		LOG(INFO, "  FFT Window coeffs preloading from %s on engine %d ",
				lut_filename, template_idx);

	offset = VRB2_FFT_FIST_OFFSET;
	pageIdx = 0;
	vrb2_reg_fast_write(d, HWPfFftRamPageAccess + template_idx * 0x1000, VRB2_FFT_RAM_EN);
	for (i = 0; i < VRB2_LUT_SIZE; i++) {
		vrb2_reg_fast_write(d, HWPfFftRamOff + offset *
				VRB2_BYTES_IN_WORD + template_idx * 0x1000,
				gTDWinCoff[i]);
		offset++;
		if ((offset % VRB2_FFT_PAGE_SIZE) == 0) {
			offset = 0;
			pageIdx++;
			fflush(stdout);
			vrb2_reg_fast_write(d, HWPfFftRamPageAccess + template_idx * 0x1000,
					VRB2_FFT_RAM_EN + pageIdx);
		}
	}

	vrb2_reg_fast_write(d, HWPfFftRamPageAccess + template_idx * 0x1000, VRB2_FFT_RAM_DIS);
	fclose(fp);

	if (template_idx != 0)
		return 0;

	vrb_fft_win_check(gTDWinCoff, accel_pci_dev);

	vrb_fft_lut_md5sum(lut_filename, accel_pci_dev);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xfe28, %rsp           # imm = 0xFE28
movq %rcx, %r14
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r15
movl %esi, %r13d
shll $0xc, %r13d
leal 0xb58004(%r13), %eax
movzbl 0x25831(%rip), %ecx     # 0x3b931
addl $0x2001, %ecx           # imm = 0x2001
movl %ecx, (%rdi,%rax)
pushq $0x1
popq %r12
movl %r12d, %edi
callq 0xd460
leal 0xb5803c(%r13), %eax
cmpb $0x0, 0x2580e(%rip)     # 0x3b931
movl $0x180, %ecx            # imm = 0x180
pushq $0x60
popq %rdx
cmovnel %ecx, %edx
movl %edx, (%r15,%rax)
movl %r12d, %edi
callq 0xd460
xorl %r12d, %r12d
testl %ebx, %ebx
je 0x162b7
movq 0x10(%r14), %rbx
movq %rbx, %rdi
callq 0x137d0
testb %al, %al
je 0x16170
callq 0x16020
leaq 0x1ed6f(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
leaq 0x679d(%rip), %rdx      # 0x1c908
jmp 0x162a2
leaq 0x67c2(%rip), %rsi      # 0x1c939
movq %rbx, %rdi
callq 0xd330
testq %rax, %rax
je 0x16289
movq %rax, %r12
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rdx
movl $0xfe00, %esi           # imm = 0xFE00
movq %rax, %rcx
callq 0xd0d0
testw %ax, %ax
jle 0x162cc
movq %r12, 0x18(%rsp)
movq %r14, 0x8(%rsp)
testl %ebp, %ebp
jne 0x161e4
callq 0x16020
leaq 0x1ed0d(%rip), %rcx     # 0x34ed0
movq 0x10(%rcx), %r8
andl $0x0, (%rsp)
leaq 0x7514(%rip), %rdx      # 0x1d6e6
pushq $0x2
popq %rdi
xorl %esi, %esi
movq %rax, %rcx
movq %rbx, %r9
xorl %eax, %eax
callq 0x19400
movq %rbx, 0x10(%rsp)
leal 0xb5800c(%r13), %r12d
movl $0x80000000, (%r15,%r12) # imm = 0x80000000
addl $0xb58800, %r13d        # imm = 0xB58800
movw $0x100, %ax             # imm = 0x100
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpq $0x7f00, %r14           # imm = 0x7F00
je 0x1624f
movswl %ax, %ecx
leal (%r13,%rcx,4), %ecx
movswl 0x20(%rsp,%r14,2), %edx
movl %edx, (%r15,%rcx)
incl %eax
testw $0x1ff, %ax             # imm = 0x1FF
jne 0x1624a
incl %ebx
movq 0x1dd9c(%rip), %rax     # 0x33fd0
movq (%rax), %rdi
callq 0xd290
movswl %bx, %eax
addl $0x80000000, %eax       # imm = 0x80000000
movl %eax, (%r15,%r12)
xorl %eax, %eax
incq %r14
jmp 0x16208
movl $0x0, (%r15,%r12)
movq 0x18(%rsp), %rdi
callq 0xd0f0
xorl %r12d, %r12d
testl %ebp, %ebp
jne 0x162b7
leaq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x112ad
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x11406
jmp 0x162b7
callq 0x16020
leaq 0x1ec3b(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
movl %ebp, (%rsp)
leaq 0x7417(%rip), %rdx      # 0x1d6b9
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
movq %rbx, %r9
xorl %eax, %eax
callq 0x19400
pushq $-0x2
popq %r12
movl %r12d, %eax
addq $0xfe28, %rsp           # imm = 0xFE28
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x16020
leaq 0x1ebf8(%rip), %rcx     # 0x34ed0
movq (%rcx), %r8
movl %ebp, (%rsp)
leaq 0x73d4(%rip), %rdx      # 0x1d6b9
xorl %edi, %edi
xorl %esi, %esi
movq %rax, %rcx
movq %rbx, %r9
xorl %eax, %eax
callq 0x19400
movq %r12, %rdi
callq 0xd0f0
jmp 0x162b3