// File: /workspace/github_cpp_makefile_star2_O2/Pyboon[P]sage/sage.cpp
// Function: Sage::ReadCIR()
void Sage::ReadCIR(){
    // generate ReCIR and ImCIR path
    string path = config.path_cir;
    char file_ReCIR[128] = "";
    char file_ImCIR[128] = "";
    sprintf(file_ReCIR, "%02d/fCIR_r_%02d_%04d", this->spot, this->spot, this->cycle_idx);
    sprintf(file_ImCIR, "%02d/fCIR_i_%02d_%04d", this->spot, this->spot, this->cycle_idx);
    string path_ReCIR = path + "/" + file_ReCIR;
    string path_ImCIR = path + "/" + file_ImCIR;
    cout<<path_ReCIR<<endl;
    cout<<path_ImCIR<<endl;
    ifstream fReCIR(path_ReCIR, ios::binary);
    ifstream fImCIR(path_ImCIR, ios::binary);
    if(!fReCIR || !fImCIR){
        cerr<<"ReCIR or ImCIR is not exist!"<<endl;
        abort();
    }
    if(!(CIR.rows())){
        InitCIR();
    }
    int rows = CIR.rows();
    int cols_one_cycle = config.subchannel_num;
    if(config.is_pg){
        cols_one_cycle = config.subchannel_withPG_num;
        Util::log("Protection-Guard in CIR!");
    }
    double real_point = 0.0;
    double imag_point = 0.0;
    // in matlab convert, fwrite is save in binary with column order
    // so here read from binary with columns order
    int real_col = 0;
    for(int k = 0; k<config.cycle_num; ++k){
        for(int j = 1; j<=cols_one_cycle; ++j){
                for(int i = 0; i<rows; ++i){
                    fReCIR.read((char*)&real_point, sizeof(double));
                    fImCIR.read((char*)&imag_point, sizeof(double));
                    if(config.is_pg && j%(config.Rx+1)==0){
                        continue; // only read but not write to CIR
                    }else{
                        CIR(i,real_col).real(real_point);
                        CIR(i,real_col).imag(imag_point);
                    }
                }
                if(!(config.is_pg && j%(config.Rx+1)==0)){
                    ++real_col;
                }
            }
    }
    
    fReCIR.close();
    fImCIR.close();
    // for(int i = 0; i<rows; ++i){
    //     for(int j = 0;j<1; ++j){
    //         cout<<i<<","<<j<<":"<<CIR(i,j)<<endl;
    //     }
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5b8, %rsp            # imm = 0x5B8
movq %rdi, %r12
leaq 0x68(%rdi), %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x3330
xorps %xmm0, %xmm0
leaq 0x330(%rsp), %rdi
movaps %xmm0, 0x70(%rdi)
movaps %xmm0, 0x60(%rdi)
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
leaq 0x2b0(%rsp), %r15
movaps %xmm0, 0x70(%r15)
movaps %xmm0, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movl 0x150(%r12), %ecx
movl 0x154(%r12), %r8d
leaq 0x17dc5(%rip), %rsi     # 0x1c1c3
movl %ecx, %edx
xorl %eax, %eax
callq 0x3060
movl 0x150(%r12), %ecx
movl 0x154(%r12), %r8d
leaq 0x17dbb(%rip), %rsi     # 0x1c1d9
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x3060
leaq 0x17c59(%rip), %rdx     # 0x1c08a
leaq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0x3b99
leaq 0x48(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x330(%rsp), %rdx
callq 0x545f
leaq 0xa8(%rsp), %rdi
callq 0x3100
leaq 0x17c1b(%rip), %rdx     # 0x1c08a
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3b99
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x2b0(%rsp), %rdx
callq 0x545f
leaq 0xa8(%rsp), %rdi
callq 0x3100
movq 0x35b16(%rip), %rdi     # 0x39fc8
leaq 0x48(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movq 0x35afd(%rip), %rdi     # 0x39fc8
leaq 0x28(%rsp), %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3110
leaq 0xa8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x33d0
leaq 0x3b0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x33d0
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc8(%rsp,%rax)
jne 0x4726
movq 0x3b0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x3d0(%rsp,%rax)
jne 0x4726
movq 0x140(%r12), %rax
movq %rax, %rbx
testq %rax, %rax
jne 0x455d
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
movq 0x140(%r12), %rbx
cmpb $0x1, 0x40(%r12)
jne 0x4599
movl 0xa4(%r12), %ebp
leaq 0x17c98(%rip), %rsi     # 0x1c20c
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3b5e
leaq 0x68(%rsp), %rdi
callq 0x547e
leaq 0x68(%rsp), %rdi
callq 0x3100
jmp 0x45a1
movl 0xa0(%r12), %ebp
leaq 0x138(%r12), %r14
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
leaq 0x20(%rsp), %rax
andq $0x0, (%rax)
xorl %ecx, %ecx
testl %ebx, %ebx
cmovlel %ecx, %ebx
testl %ebp, %ebp
movl $0x0, %eax
movq %rax, 0x8(%rsp)
cmovlel %ecx, %ebp
incl %ebp
movl %ebp, 0x1c(%rsp)
pushq $0x8
popq %rbp
xorl %eax, %eax
movl %eax, 0x18(%rsp)
cmpl 0x10(%r12), %eax
jge 0x46bf
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
cmpl 0x1c(%rsp), %eax
je 0x46b4
movslq 0x8(%rsp), %r13
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x4683
leaq 0xa8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0x32e0
leaq 0x3b0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x32e0
cmpb $0x1, 0x40(%r12)
jne 0x464d
movl 0x8(%r12), %ecx
incl %ecx
movl 0x4(%rsp), %eax
cltd
idivl %ecx
testl %edx, %edx
je 0x467e
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x54d6
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x54d6
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
incq %r15
jmp 0x4604
cmpb $0x0, 0x40(%r12)
je 0x469d
movl 0x8(%r12), %ecx
incl %ecx
movl 0x4(%rsp), %eax
cltd
idivl %ecx
testl %edx, %edx
je 0x46a9
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movl 0x4(%rsp), %eax
incl %eax
jmp 0x45ee
movl 0x18(%rsp), %eax
incl %eax
jmp 0x45dc
leaq 0xa8(%rsp), %rdi
callq 0x3070
leaq 0x3b0(%rsp), %rdi
callq 0x3070
leaq 0x3b0(%rsp), %rdi
callq 0x30a0
leaq 0xa8(%rsp), %rdi
callq 0x30a0
leaq 0x28(%rsp), %rdi
callq 0x3100
leaq 0x48(%rsp), %rdi
callq 0x3100
leaq 0x88(%rsp), %rdi
callq 0x3100
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x358c3(%rip), %rdi     # 0x39ff0
leaq 0x17abb(%rip), %rsi     # 0x1c1ef
callq 0x3250
movq %rax, %rdi
callq 0x3110
callq 0x3160
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3100
jmp 0x478e
jmp 0x478b
movq %rax, %rbx
jmp 0x479b
jmp 0x4786
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x47ad
movq %rax, %rbx
jmp 0x47b2
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x47b7
movq %rax, %rbx
jmp 0x47bc
jmp 0x478b
jmp 0x478b
movq %rax, %rbx
jmp 0x47a8
movq %rax, %rbx
leaq 0x3b0(%rsp), %rdi
callq 0x30a0
leaq 0xa8(%rsp), %rdi
callq 0x30a0
leaq 0x28(%rsp), %rdi
callq 0x3100
leaq 0x48(%rsp), %rdi
callq 0x3100
leaq 0x88(%rsp), %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3430
nop