// File: Pyboon[P]sage/sage.cpp
// Function: Sage::getAntennaResponse(double, double, int)
MatrixX2cd Sage::getAntennaResponse(double theta, double phi, const int k){
    int theta_index = (int)((theta+90)/180 * 90);
    int phi_index = (int)((phi+180)/360 * 180);
    // k == 1 : tx antenna response 
    if(k==1){
        MatrixX2cd response(config.Tx, 2);
        for(int i = 0; i < config.Tx; ++i){
            response(i, 1) = TxArrayEphi[i](phi_index, theta_index);
            response(i, 0) = TxArrayEtheta[i](phi_index, theta_index);
        }
        return response;

    } else if(k ==2){ // k ==2 : rx antenna response
        MatrixX2cd response(config.Rx, 2);
        for(int i = 0; i < config.Rx; ++i){
            response(i, 1) = RxArrayEphi[i](phi_index, theta_index);
            response(i, 0) = RxArrayEtheta[i](phi_index, theta_index);
        }
        return response;
    } else {
        cerr<<"parameters error"<<endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x68(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movsd 0x5afad(%rip), %xmm0    # 0x6e278
addsd -0x18(%rbp), %xmm0
movsd 0x5af90(%rip), %xmm1    # 0x6e268
divsd %xmm1, %xmm0
movsd 0x5af94(%rip), %xmm1    # 0x6e278
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
movsd 0x5af71(%rip), %xmm0    # 0x6e268
addsd -0x20(%rbp), %xmm0
movsd 0x5af6c(%rip), %xmm1    # 0x6e270
divsd %xmm1, %xmm0
movsd 0x5af58(%rip), %xmm1    # 0x6e268
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x1344d
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rsi
movb $0x0, -0x2d(%rbp)
addq $0x8, %rsi
addq $0x4, %rsi
movl $0x2, -0x34(%rbp)
leaq -0x34(%rbp), %rdx
callq 0x13de0
movl $0x0, -0x38(%rbp)
movq -0x58(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0xc(%rcx), %eax
jge 0x13435
movq -0x58(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
movslq -0x38(%rbp), %rsi
callq 0x13dc0
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x13c40
movq %rax, -0x70(%rbp)
jmp 0x1338a
movq -0x68(%rbp), %rdi
movslq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x13e50
movq %rax, -0x78(%rbp)
jmp 0x133a2
movq -0x58(%rbp), %rdi
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%rax)
addq $0x178, %rdi            # imm = 0x178
movslq -0x38(%rbp), %rsi
callq 0x13dc0
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x13c40
movq %rax, -0x80(%rbp)
jmp 0x133da
movq -0x68(%rbp), %rdi
movslq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x13e50
movq %rax, -0x88(%rbp)
jmp 0x133f4
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x13350
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x13f10
jmp 0x135ba
movb $0x1, -0x2d(%rbp)
testb $0x1, -0x2d(%rbp)
jne 0x13448
movq -0x68(%rbp), %rdi
callq 0x13f10
jmp 0x135ad
cmpl $0x2, -0x24(%rbp)
jne 0x13587
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rsi
movb $0x0, -0x45(%rbp)
addq $0x8, %rsi
movl $0x2, -0x4c(%rbp)
leaq -0x4c(%rbp), %rdx
callq 0x13de0
movl $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rcx
movl -0x50(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0x13572
movq -0x58(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
movslq -0x50(%rbp), %rsi
callq 0x13dc0
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x13c40
movq %rax, -0x90(%rbp)
jmp 0x134bb
movq -0x68(%rbp), %rdi
movslq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x13e50
movq %rax, -0x98(%rbp)
jmp 0x134d6
movq -0x58(%rbp), %rdi
movq -0x98(%rbp), %rax
movq -0x90(%rbp), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%rax)
addq $0x1a8, %rdi            # imm = 0x1A8
movslq -0x50(%rbp), %rsi
callq 0x13dc0
movq %rax, %rdi
movslq -0x2c(%rbp), %rsi
movslq -0x28(%rbp), %rdx
callq 0x13c40
movq %rax, -0xa0(%rbp)
jmp 0x13517
movq -0x68(%rbp), %rdi
movslq -0x50(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x13e50
movq %rax, -0xa8(%rbp)
jmp 0x13531
movq -0xa8(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1347e
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x13f10
jmp 0x135ba
movb $0x1, -0x45(%rbp)
testb $0x1, -0x45(%rbp)
jne 0x13585
movq -0x68(%rbp), %rdi
callq 0x13f10
jmp 0x135ad
movq 0xa1a62(%rip), %rdi     # 0xb4ff0
leaq 0x5ae0a(%rip), %rsi     # 0x6e39f
callq 0x9790
movq %rax, %rdi
movq 0xa19ec(%rip), %rsi     # 0xb4f90
callq 0x97d0
jmp 0x135ab
ud2
movq -0x60(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x9dc0
nopw %cs:(%rax,%rax)