// File: /workspace/github_cpp_makefile_star2_O2/Pyboon[P]sage/isi_sage.cpp
// Function: IsiSage::InitAoA(Eigen::Matrix<std::complex<double>, 1, -1, 1, 1, -1>, int)
void IsiSage::InitAoA(const RowVectorXcd tau_data, const int iL){
    Util::log("init AOA...");
    MatrixXcd Y(config.Rx, config.Tx);
    complex<double> cycle_data = 0;
    complex<double> temp = 0;
    for(int i_rx = 0; i_rx < config.Rx; ++i_rx){
        for(int i_tx = 0; i_tx < config.Tx; ++i_tx){
            cycle_data = 0;
            for(int i_cyc = 0; i_cyc < config.cycle_num; ++i_cyc){
                double t = (i_cyc * config.Tcy + i_tx * config.Tt + i_rx * config.Tr) * config.T; 
                temp.real(cos(2*PI* result.doppler(iL) * t));
                temp.imag(-sin(2*PI* result.doppler(iL) * t));
                cycle_data += temp * tau_data(i_cyc * config.subchannel_num + i_tx * config.Rx + i_rx);
            }
            Y(i_rx, i_tx) = cycle_data;
        }
    }
    double min_theta_rx = config.min_theta_rx;
    double max_theta_rx = config.max_theta_rx;
    double min_phi_rx = config.min_phi_rx;
    double max_phi_rx = config.max_phi_rx;
    double step = config.angle_step;
    int theta_size = (max_theta_rx - min_theta_rx)/step + 1;
    int phi_size = (max_phi_rx - min_phi_rx)/step + 1;
    MatrixXd aoa_data(theta_size, phi_size);
    aoa_data.setZero(theta_size, phi_size);
    Util::log("generating aoa_data...(waiting for a few time)");
    for(int i_theta = 0; i_theta < theta_size; ++i_theta){
        for(int i_phi = 0; i_phi < phi_size; ++i_phi){
                MatrixX2cd C2 = getAntennaResponse(min_theta_rx+i_theta*step, min_phi_rx+i_phi*step, 2);
                VectorXcd c_2_1 = C2.col(0) / (C2.col(0).norm());
                VectorXcd c_2_2 = C2.col(1) / (C2.col(1).norm());
                RowVectorXcd c_2_1_H = c_2_1.adjoint();
                RowVectorXcd c_2_2_H = c_2_2.adjoint();
            for(int i_tx = 0; i_tx < config.Tx; ++i_tx){
                VectorXcd y_m1 = Y.col(i_tx);
                complex<double> part1 = c_2_1_H * y_m1;
                complex<double> part2 = c_2_2_H * y_m1;
                double p1_norm = norm(part1);
                double p2_norm = norm(part2);
                RowVectorXcd y_m1_H = y_m1.adjoint();
                complex<double> part3 = y_m1_H * c_2_2 * c_2_1_H * y_m1 * c_2_2_H * c_2_1;
                aoa_data(i_theta, i_phi) += p1_norm + p2_norm - 2 * part3.real();
            }
        }
    }
    int i,j;
    aoa_data.maxCoeff(&i, &j);
    result.theta_rx(iL) = i * config.angle_step + min_theta_rx;
    result.phi_rx(iL) = j * config.angle_step + min_phi_rx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %edx, %r14d
movq %rsi, 0x28(%rsp)
movq %rdi, %rbx
leaq 0x1698a(%rip), %rsi     # 0x1d783
leaq 0x1f8(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x3b5e
leaq 0x1f8(%rsp), %rdi
callq 0x547e
leaq 0x1f8(%rsp), %rdi
callq 0x3100
leaq 0x8(%rbx), %rsi
leaq 0xc(%rbx), %rdx
leaq 0xf8(%rsp), %rdi
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
callq 0xabc2
leaq 0x1d0(%rbx), %rbp
movslq %r14d, %rax
movq %rax, 0x68(%rsp)
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rax
movapd %xmm0, (%rax)
xorl %r13d, %r13d
movq 0x68(%rsp), %r15
movq 0x20(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jge 0x6fc4
xorl %r12d, %r12d
movq 0x18(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r12
jge 0x6fbc
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
xorl %r14d, %r14d
cmpl 0x10(%rbx), %r14d
jge 0x6f97
movl 0xbc(%rbx), %eax
imull %r14d, %eax
movl 0xb4(%rbx), %ecx
imull %r12d, %ecx
addl %eax, %ecx
movl 0xb8(%rbx), %eax
imull %r13d, %eax
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0xa8(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x564e
movsd 0x164f7(%rip), %xmm1    # 0x1d3e8
movsd (%rax), %xmm0
mulsd %xmm1, %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x3470
movsd %xmm0, 0xc0(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x564e
movsd 0x164c8(%rip), %xmm0    # 0x1d3e8
movsd (%rax), %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
callq 0x3080
xorpd 0x164f1(%rip), %xmm0    # 0x1d430
movlpd %xmm0, 0xc8(%rsp)
movl 0xa0(%rbx), %eax
imull %r14d, %eax
movl 0x8(%rbx), %ecx
imull %r12d, %ecx
addl %r13d, %eax
addl %ecx, %eax
movslq %eax, %rsi
movq 0x28(%rsp), %rdi
callq 0xab8c
leaq 0xc0(%rsp), %rdi
movq %rax, %rsi
callq 0xab66
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movapd 0x30(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
incl %r14d
jmp 0x6ea0
leaq 0xf8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x54d6
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rax)
incq %r12
jmp 0x6e82
incq %r13
jmp 0x6e6e
movsd 0x100(%rbx), %xmm2
movsd 0x108(%rbx), %xmm0
movsd 0x110(%rbx), %xmm3
movsd 0x118(%rbx), %xmm1
movsd 0x128(%rbx), %xmm4
movsd %xmm2, 0x48(%rsp)
subsd %xmm2, %xmm0
divsd %xmm4, %xmm0
movsd 0x163d6(%rip), %xmm2    # 0x1d3d8
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
leaq 0x14(%rsp), %rsi
movl %eax, (%rsi)
movsd %xmm3, 0x50(%rsp)
subsd %xmm3, %xmm1
movsd %xmm4, 0x58(%rsp)
divsd %xmm4, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
leaq 0x10(%rsp), %rdx
movl %eax, (%rdx)
leaq 0xe0(%rsp), %rdi
callq 0xabfa
movslq 0x14(%rsp), %rsi
movslq 0x10(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
callq 0xac32
leaq 0x16730(%rip), %rsi     # 0x1d78f
leaq 0x1d8(%rsp), %rdi
leaq 0x140(%rsp), %rdx
callq 0x3b5e
leaq 0x1d8(%rsp), %rdi
callq 0x547e
leaq 0x1d8(%rsp), %rdi
callq 0x3100
xorl %ecx, %ecx
leaq 0xb0(%rsp), %rdi
leaq 0x140(%rsp), %r15
leaq 0x130(%rsp), %r12
movslq 0x14(%rsp), %rax
cmpq %rax, %rcx
jge 0x7444
movq %rcx, 0x60(%rsp)
cvtsi2sd %ecx, %xmm0
mulsd 0x58(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
xorl %ebp, %ebp
movslq 0x10(%rsp), %rax
cmpq %rax, %rbp
jge 0x7437
cvtsi2sd %ebp, %xmm1
mulsd 0x58(%rsp), %xmm1
addsd 0x50(%rsp), %xmm1
movq (%rbx), %rax
movq %rdi, %r13
movq %rbx, %rsi
movsd 0xd0(%rsp), %xmm0
pushq $0x2
popq %rdx
callq *0x20(%rax)
leaq 0x198(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xc424
leaq 0x250(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xc424
leaq 0x250(%rsp), %rdi
callq 0xaca6
movsd %xmm0, 0x218(%rsp)
movq %r15, %rdi
leaq 0x198(%rsp), %rsi
leaq 0x218(%rsp), %rdx
callq 0xac56
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0xc676
leaq 0x198(%rsp), %rdi
leaq 0xb0(%rsp), %r13
movq %r13, %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0xc424
leaq 0x250(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xc424
leaq 0x250(%rsp), %rdi
callq 0xaca6
movsd %xmm0, 0x218(%rsp)
movq %r15, %rdi
leaq 0x198(%rsp), %rsi
leaq 0x218(%rsp), %rdx
callq 0xac56
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0xc676
leaq 0xa0(%rsp), %rax
movq %rax, 0x140(%rsp)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0xc87c
leaq 0x90(%rsp), %rax
movq %rax, 0x140(%rsp)
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0xc87c
xorl %r13d, %r13d
movq 0x18(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jge 0x73e9
movq %r15, %rdi
leaq 0xf8(%rsp), %rsi
movq %r13, %rdx
callq 0xcae6
movq %r12, %rdi
movq %r15, %rsi
callq 0xcbc0
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0xacb2
movq %rax, 0x140(%rsp)
movq %rdx, 0x148(%rsp)
movq %r15, %rdi
callq 0xacd6
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0xacb2
movq %rax, 0x140(%rsp)
movq %rdx, 0x148(%rsp)
movq %r15, %rdi
callq 0xacd6
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %r12, 0x140(%rsp)
leaq 0x120(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0xc87c
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
callq 0xacb2
movq %rax, 0x110(%rsp)
movq %rdx, 0x118(%rsp)
leaq 0x218(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0xad5b
leaq 0x198(%rsp), %rdi
leaq 0x218(%rsp), %rsi
movq %r12, %rdx
callq 0xd108
leaq 0x250(%rsp), %rdi
leaq 0x198(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0xacfb
movq %r15, %rdi
leaq 0x250(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0xd108
movq %r15, %rdi
callq 0xadbc
movsd %xmm0, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq %rbp, %rdx
callq 0xade2
movsd 0x30(%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm2
movsd 0x28(%rsp), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0xd8(%rsp), %xmm0
addsd %xmm0, %xmm0
subsd %xmm0, %xmm1
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
movq 0x120(%rsp), %rdi
callq 0x32c0
movq 0x130(%rsp), %rdi
callq 0x32c0
incq %r13
jmp 0x721e
movq 0x70(%rsp), %rdi
callq 0x32c0
movq 0x80(%rsp), %rdi
callq 0x32c0
movq 0x90(%rsp), %rdi
callq 0x32c0
movq 0xa0(%rsp), %rdi
callq 0x32c0
movq 0xb0(%rsp), %rdi
callq 0x32c0
incq %rbp
leaq 0xb0(%rsp), %rdi
jmp 0x70d6
movq 0x60(%rsp), %rcx
incq %rcx
jmp 0x70a8
leaq 0xe0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x198(%rsp), %rdx
callq 0xae2c
movq 0x68(%rsp), %r14
movl 0x140(%rsp), %ebp
movsd 0x128(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x200(%rbx), %rdi
movq %r14, %rsi
callq 0x564e
cvtsi2sd %ebp, %xmm0
mulsd 0x8(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x198(%rsp), %ebp
movsd 0x128(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x210, %rbx            # imm = 0x210
movq %rbx, %rdi
movq %r14, %rsi
callq 0x564e
cvtsi2sd %ebp, %xmm0
mulsd 0x8(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0xe0(%rsp), %rdi
callq 0x32c0
movq 0xf8(%rsp), %rdi
callq 0x32c0
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x3100
jmp 0x75d3
jmp 0x7544
jmp 0x7544
jmp 0x7573
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x3100
jmp 0x75ed
movq %rax, %rbx
jmp 0x75ed
jmp 0x7544
movq %rax, %rbx
jmp 0x759f
movq %rax, %rbx
jmp 0x75d3
jmp 0x755c
movq %rax, %rbx
jmp 0x75ac
jmp 0x7557
jmp 0x7573
movq %rax, %rbx
jmp 0x75b9
movq %rax, %rbx
jmp 0x75c6
jmp 0x7567
jmp 0x7578
jmp 0x7567
movq %rax, %rbx
jmp 0x7588
movq %rax, %rbx
jmp 0x7595
jmp 0x7573
movq %rax, %rbx
jmp 0x75e0
movq %rax, %rbx
movq 0x120(%rsp), %rdi
callq 0x32c0
movq 0x130(%rsp), %rdi
callq 0x32c0
movq 0x70(%rsp), %rdi
callq 0x32c0
movq 0x80(%rsp), %rdi
callq 0x32c0
movq 0x90(%rsp), %rdi
callq 0x32c0
movq 0xa0(%rsp), %rdi
callq 0x32c0
movq 0xb0(%rsp), %rdi
callq 0x32c0
movq 0xe0(%rsp), %rdi
callq 0x32c0
movq 0xf8(%rsp), %rdi
callq 0x32c0
movq %rbx, %rdi
callq 0x3430
nop