// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x68(%rdi), %rsi
movq 0x70(%rdi), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x4336
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(%rbx), %ecx
movl 0x154(%rbx), %r8d
leaq 0x179cd(%rip), %rsi     # 0x1c1db
movl %ecx, %edx
xorl %eax, %eax
callq 0x3070
movl 0x150(%rbx), %ecx
movl 0x154(%rbx), %r8d
leaq 0x179c6(%rip), %rsi     # 0x1c1f1
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x3070
leaq 0xb8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x4336
leaq 0x17829(%rip), %rsi     # 0x1c08a
leaq 0xa8(%rsp), %rdi
callq 0x34a0
leaq 0xa8(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x34a0
leaq 0x20(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x48aa
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x48b0
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x48e5
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32a0
leaq 0xa8(%rsp), %rdi
movq %r15, (%rdi)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
callq 0x4336
leaq 0x17781(%rip), %rsi     # 0x1c08a
leaq 0xa8(%rsp), %rdi
callq 0x34a0
leaq 0xa8(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x34a0
leaq 0x40(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4952
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x4958
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x498d
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32a0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2a62a(%rip), %rdi     # 0x2efc8
callq 0x32d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31c0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x2a5ea(%rip), %rdi     # 0x2efc8
callq 0x32d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31c0
leaq 0xa8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
callq 0x33f0
leaq 0x3b0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x4, %edx
callq 0x33f0
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc8(%rsp,%rax)
jne 0x4cf8
movq 0x3b0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x3d0(%rsp,%rax)
jne 0x4cf8
movq 0x140(%rbx), %rcx
movq %rcx, 0x8(%rsp)
testq %rcx, %rcx
jne 0x4a95
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq 0x140(%rbx), %rax
movq %rax, 0x8(%rsp)
cmpb $0x1, 0x40(%rbx)
jne 0x4af7
movl 0xa4(%rbx), %eax
movl %eax, (%rsp)
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1776d(%rip), %rsi     # 0x1c224
leaq 0x1777e(%rip), %rdx     # 0x1c23c
leaq 0x88(%rsp), %rdi
callq 0x43cc
leaq 0x88(%rsp), %rdi
callq 0x60be
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x4b00
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32a0
jmp 0x4b00
movl 0xa0(%rbx), %eax
movl %eax, (%rsp)
xorl %ecx, %ecx
movq %rcx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movl 0x10(%rbx), %eax
testl %eax, %eax
jle 0x4c3f
movq 0x8(%rsp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%rsp)
jle 0x4c35
movq %rcx, 0x80(%rsp)
movl $0x1, %ebp
cmpl $0x0, 0x8(%rsp)
jle 0x4c02
movslq 0x4(%rsp), %r12
movl $0x8, %r13d
xorl %r15d, %r15d
movl $0x8, %edx
leaq 0xa8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x3330
movl $0x8, %edx
leaq 0x3b0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3330
movb 0x40(%rbx), %cl
cmpb $0x1, %cl
jne 0x4b9f
movl 0x8(%rbx), %esi
incl %esi
movl %ebp, %eax
cltd
idivl %esi
testl %edx, %edx
je 0x4bf0
cmpl $0x0, 0x4(%rsp)
js 0x4cd9
movq 0x140(%rbx), %rax
cmpq %r15, %rax
jle 0x4cd9
cmpq %r12, 0x148(%rbx)
jle 0x4cd9
imulq %r12, %rax
shlq $0x4, %rax
addq 0x138(%rbx), %rax
movsd 0x58(%rsp), %xmm0
movsd %xmm0, -0x8(%r13,%rax)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%r13,%rax)
incq %r15
addq $0x10, %r13
cmpq %r15, %r14
jne 0x4b5b
jmp 0x4c05
movb 0x40(%rbx), %cl
testb $0x1, %cl
je 0x4c18
movl 0x8(%rbx), %ecx
incl %ecx
movl %ebp, %eax
cltd
idivl %ecx
testl %edx, %edx
je 0x4c1c
incl 0x4(%rsp)
leal 0x1(%rbp), %eax
cmpl (%rsp), %ebp
movl %eax, %ebp
jne 0x4b42
movl 0x10(%rbx), %eax
movq 0x80(%rsp), %rcx
incl %ecx
cmpl %eax, %ecx
jl 0x4b2b
leaq 0xa8(%rsp), %rdi
callq 0x3080
leaq 0x3b0(%rsp), %rdi
callq 0x3080
leaq 0x3b0(%rsp), %rdi
callq 0x30a0
leaq 0xa8(%rsp), %rdi
callq 0x30a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4c8f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x32a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4cab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x32a0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x4cc7
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32a0
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17d27(%rip), %rdi     # 0x1ca07
leaq 0x17d55(%rip), %rsi     # 0x1ca3c
leaq 0x17d71(%rip), %rcx     # 0x1ca5f
movl $0x16d, %edx            # imm = 0x16D
callq 0x31b0
movq 0x2a2f1(%rip), %rdi     # 0x2eff0
leaq 0x17501(%rip), %rsi     # 0x1c207
movl $0x1c, %edx
callq 0x32d0
movq 0x2a2d9(%rip), %rdi     # 0x2eff0
callq 0x3120
callq 0x3170
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x4d9a
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32a0
jmp 0x4d9a
jmp 0x4d97
movq %rax, %rbx
jmp 0x4da7
jmp 0x4d92
jmp 0x4d4e
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4dd0
movq 0xb8(%rsp), %rsi
jmp 0x4dc8
movq %rax, %rbx
jmp 0x4dd0
jmp 0x4d6f
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4dec
movq 0xb8(%rsp), %rsi
jmp 0x4de4
movq %rax, %rbx
jmp 0x4dec
jmp 0x4d97
jmp 0x4d97
movq %rax, %rbx
jmp 0x4db4
movq %rax, %rbx
leaq 0x3b0(%rsp), %rdi
callq 0x30a0
leaq 0xa8(%rsp), %rdi
callq 0x30a0
leaq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
cmpq %rax, %rdi
je 0x4dd0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x32a0
leaq 0x20(%rsp), %rax
movq 0x10(%rsp), %rdi
cmpq %rax, %rdi
je 0x4dec
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x32a0
leaq 0x70(%rsp), %rax
movq 0x60(%rsp), %rdi
cmpq %rax, %rdi
je 0x4e08
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32a0
movq %rbx, %rdi
callq 0x3450