// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xfe50, %rsp           # imm = 0xFE50
movb %dl, %al
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shll $0xc, %esi
addl $0xb58004, %esi         # imm = 0xB58004
movb 0x2620e(%rip), %cl      # 0x42331
movl $0x2001, %edx           # imm = 0x2001
movl $0x2002, %eax           # imm = 0x2002
testb $0x1, %cl
cmovnel %eax, %edx
callq 0x197e0
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shll $0xc, %esi
addl $0xb5803c, %esi         # imm = 0xB5803C
movb 0x261e3(%rip), %cl      # 0x42331
movl $0x60, %edx
movl $0x180, %eax            # imm = 0x180
testb $0x1, %cl
cmovnel %eax, %edx
callq 0x197e0
testb $0x1, -0x15(%rbp)
jne 0x1c175
movl $0x0, -0x4(%rbp)
jmp 0x1c450
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xfe30(%rbp)
movq -0xfe30(%rbp), %rdi
callq 0x17fc0
andb $0x1, %al
movb %al, -0xfe39(%rbp)
movb -0xfe39(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1c1df
callq 0x1bd70
movq %rax, %rcx
leaq 0x1f719(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
movq -0xfe30(%rbp), %r9
xorl %esi, %esi
leaq 0x87a1(%rip), %rdx      # 0x2496b
movl %esi, %edi
movb $0x0, %al
callq 0x216e0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x1c450
movq -0xfe30(%rbp), %rdi
leaq 0x87af(%rip), %rsi      # 0x2499c
callq 0xd330
movq %rax, -0xfe38(%rbp)
cmpq $0x0, -0xfe38(%rbp)
jne 0x1c240
callq 0x1bd70
movq %rax, %rcx
leaq 0x1f6be(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
movq -0xfe30(%rbp), %r9
movl -0x14(%rbp), %eax
xorl %esi, %esi
leaq 0x94c1(%rip), %rdx      # 0x256e9
movl %esi, %edi
movl %eax, (%rsp)
movb $0x0, %al
callq 0x216e0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x1c450
leaq -0xfe20(%rbp), %rdi
movq -0xfe38(%rbp), %rcx
movl $0xfe00, %esi           # imm = 0xFE00
movl $0x1, %edx
callq 0xd0b0
movw %ax, -0xfe22(%rbp)
movswl -0xfe22(%rbp), %eax
cmpl $0x0, %eax
jg 0x1c2b9
callq 0x1bd70
movq %rax, %rcx
leaq 0x1f651(%rip), %rax     # 0x3b8d0
movq (%rax), %r8
movq -0xfe30(%rbp), %r9
movl -0x14(%rbp), %eax
xorl %esi, %esi
leaq 0x9454(%rip), %rdx      # 0x256e9
movl %esi, %edi
movl %eax, (%rsp)
movb $0x0, %al
callq 0x216e0
movq -0xfe38(%rbp), %rdi
callq 0xd0d0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x1c450
cmpl $0x0, -0x14(%rbp)
jne 0x1c2f4
callq 0x1bd70
movq %rax, %rcx
leaq 0x1f602(%rip), %rax     # 0x3b8d0
movq 0x10(%rax), %r8
movq -0xfe30(%rbp), %r9
movl -0x14(%rbp), %eax
movl $0x2, %edi
xorl %esi, %esi
leaq 0x942c(%rip), %rdx      # 0x25716
movl %eax, (%rsp)
movb $0x0, %al
callq 0x216e0
movw $0x100, -0xfe24(%rbp)   # imm = 0x100
movw $0x0, -0xfe28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shll $0xc, %esi
addl $0xb5800c, %esi         # imm = 0xB5800C
movl $0x80000000, %edx       # imm = 0x80000000
callq 0x1bfd0
movw $0x0, -0xfe26(%rbp)
movswl -0xfe26(%rbp), %eax
cmpl $0x7f00, %eax           # imm = 0x7F00
jge 0x1c3f7
movq -0x10(%rbp), %rdi
movswl -0xfe24(%rbp), %esi
shll $0x2, %esi
addl $0xb58800, %esi         # imm = 0xB58800
movl -0x14(%rbp), %eax
shll $0xc, %eax
addl %eax, %esi
movswq -0xfe26(%rbp), %rax
movswl -0xfe20(%rbp,%rax,2), %edx
callq 0x1bfd0
movw -0xfe24(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xfe24(%rbp)
movswl -0xfe24(%rbp), %eax
movl $0x200, %ecx            # imm = 0x200
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1c3de
movw $0x0, -0xfe24(%rbp)
movw -0xfe28(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xfe28(%rbp)
movq 0x1dc24(%rip), %rax     # 0x39fd8
movq (%rax), %rdi
callq 0xd290
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shll $0xc, %esi
addl $0xb5800c, %esi         # imm = 0xB5800C
movswl -0xfe28(%rbp), %edx
addl $0x80000000, %edx       # imm = 0x80000000
callq 0x1bfd0
jmp 0x1c3e0
movw -0xfe26(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xfe26(%rbp)
jmp 0x1c329
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
shll $0xc, %esi
addl $0xb5800c, %esi         # imm = 0xB5800C
xorl %edx, %edx
callq 0x1bfd0
movq -0xfe38(%rbp), %rdi
callq 0xd0d0
cmpl $0x0, -0x14(%rbp)
je 0x1c429
movl $0x0, -0x4(%rbp)
jmp 0x1c450
leaq -0xfe20(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x13b90
movq -0xfe30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x13d80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xfe50, %rsp           # imm = 0xFE50
popq %rbp
retq
nopl (%rax)