// File: 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
movq %rsp, %rbp
subq $0x6a0, %rsp            # imm = 0x6A0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x638(%rbp)
addq $0x68, %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0x628(%rbp)
callq 0x92c0
movq -0x638(%rbp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0x650(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
movaps %xmm0, -0x120(%rbp)
movaps %xmm0, -0x130(%rbp)
movl 0x150(%rax), %ecx
movl 0x154(%rax), %r8d
leaq 0x5c2af(%rip), %rsi     # 0x6e2a3
xorl %eax, %eax
movb %al, -0x629(%rbp)
leaq -0xb0(%rbp), %rdi
movl %ecx, %edx
callq 0x9130
movq -0x638(%rbp), %rdx
movb -0x629(%rbp), %al
movl 0x150(%rdx), %ecx
movl 0x154(%rdx), %r8d
leaq 0x5c28e(%rip), %rsi     # 0x6e2b9
leaq -0x130(%rbp), %rdi
movl %ecx, %edx
callq 0x9130
movq -0x628(%rbp), %rsi
leaq 0x5c033(%rip), %rdx     # 0x6e07a
leaq -0x170(%rbp), %rdi
callq 0xb3d0
jmp 0x12055
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x13b30
jmp 0x12071
leaq -0x170(%rbp), %rdi
callq 0x9470
leaq 0x5bff6(%rip), %rdx     # 0x6e07a
leaq -0x1c0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb3d0
jmp 0x12096
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x13b30
jmp 0x120b2
leaq -0x1c0(%rbp), %rdi
callq 0x9470
movq 0xa2f03(%rip), %rdi     # 0xb4fc8
leaq -0x150(%rbp), %rsi
callq 0x9700
movq %rax, -0x658(%rbp)
jmp 0x120da
movq -0x658(%rbp), %rdi
movq 0xa2ea8(%rip), %rsi     # 0xb4f90
callq 0x97d0
jmp 0x120ef
movq 0xa2ed2(%rip), %rdi     # 0xb4fc8
leaq -0x1a0(%rbp), %rsi
callq 0x9700
movq %rax, -0x660(%rbp)
jmp 0x1210b
movq -0x660(%rbp), %rdi
movq 0xa2e77(%rip), %rsi     # 0xb4f90
callq 0x97d0
jmp 0x12120
leaq -0x3c8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movl $0x4, %edx
callq 0x9c70
jmp 0x1213a
leaq -0x5d0(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
movl $0x4, %edx
callq 0x9c70
jmp 0x12154
movq -0x3c8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x3c8(%rbp,%rax), %rdi
callq 0x9310
movb %al, -0x661(%rbp)
jmp 0x12174
movb -0x661(%rbp), %al
testb $0x1, %al
jne 0x121af
jmp 0x12180
movq -0x5d0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x5d0(%rbp,%rax), %rdi
callq 0x9310
movb %al, -0x662(%rbp)
jmp 0x121a0
movb -0x662(%rbp), %al
testb $0x1, %al
jne 0x121af
jmp 0x1229e
movq 0xa2e3a(%rip), %rdi     # 0xb4ff0
leaq 0x5c112(%rip), %rsi     # 0x6e2cf
callq 0x9790
movq %rax, -0x670(%rbp)
jmp 0x121cb
movq -0x670(%rbp), %rdi
movq 0xa2db7(%rip), %rsi     # 0xb4f90
callq 0x97d0
jmp 0x121e0
callq 0x93b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x12630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x9470
jmp 0x12630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x12624
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x9470
jmp 0x12624
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x12618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x1260c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x12600
movq -0x638(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
callq 0x13af0
movq %rax, -0x678(%rbp)
jmp 0x122ba
movq -0x678(%rbp), %rax
cmpq $0x0, %rax
jne 0x122db
movq -0x638(%rbp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x122d9
jmp 0x122db
movq -0x638(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
callq 0x13af0
movq %rax, -0x680(%rbp)
jmp 0x122f7
movq -0x638(%rbp), %rax
movq -0x680(%rbp), %rcx
movl %ecx, -0x5d4(%rbp)
movl 0xa0(%rax), %ecx
movl %ecx, -0x5d8(%rbp)
testb $0x1, 0x40(%rax)
je 0x123ce
movq -0x638(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0x5d8(%rbp)
leaq -0x5f9(%rbp), %rdi
movq %rdi, -0x688(%rbp)
callq 0x9dd0
movq -0x688(%rbp), %rdx
leaq 0x5bf97(%rip), %rsi     # 0x6e2ec
leaq -0x5f8(%rbp), %rdi
callq 0xb320
jmp 0x12363
leaq -0x5f8(%rbp), %rdi
callq 0x13b80
jmp 0x12371
leaq -0x5f8(%rbp), %rdi
callq 0x9470
leaq -0x5f9(%rbp), %rdi
callq 0x9840
jmp 0x123ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x123bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x5f8(%rbp), %rdi
callq 0x9470
leaq -0x5f9(%rbp), %rdi
callq 0x9840
jmp 0x12600
xorps %xmm0, %xmm0
movsd %xmm0, -0x608(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x610(%rbp)
movl $0x0, -0x614(%rbp)
movl $0x0, -0x618(%rbp)
movq -0x638(%rbp), %rcx
movl -0x618(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x125a2
movl $0x1, -0x61c(%rbp)
movl -0x61c(%rbp), %eax
cmpl -0x5d8(%rbp), %eax
jg 0x1258c
movl $0x0, -0x620(%rbp)
movl -0x620(%rbp), %eax
cmpl -0x5d4(%rbp), %eax
jge 0x1253f
leaq -0x3c8(%rbp), %rdi
leaq -0x608(%rbp), %rsi
movl $0x8, %edx
callq 0x99b0
jmp 0x12460
leaq -0x5d0(%rbp), %rdi
leaq -0x610(%rbp), %rsi
movl $0x8, %edx
callq 0x99b0
jmp 0x1247a
movq -0x638(%rbp), %rax
testb $0x1, 0x40(%rax)
je 0x124a7
movq -0x638(%rbp), %rcx
movl -0x61c(%rbp), %eax
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x124a7
jmp 0x1252b
movq -0x638(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movslq -0x620(%rbp), %rsi
movslq -0x614(%rbp), %rdx
callq 0x13c40
movq %rax, -0x690(%rbp)
jmp 0x124d1
movq -0x690(%rbp), %rdi
movsd -0x608(%rbp), %xmm0
callq 0x13d00
jmp 0x124e7
movq -0x638(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movslq -0x620(%rbp), %rsi
movslq -0x614(%rbp), %rdx
callq 0x13c40
movq %rax, -0x698(%rbp)
jmp 0x12511
movq -0x698(%rbp), %rdi
movsd -0x610(%rbp), %xmm0
callq 0x13d20
jmp 0x12527
jmp 0x12529
jmp 0x1252b
movl -0x620(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x620(%rbp)
jmp 0x12434
movq -0x638(%rbp), %rax
testb $0x1, 0x40(%rax)
je 0x12567
movq -0x638(%rbp), %rcx
movl -0x61c(%rbp), %eax
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x12576
movl -0x614(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x614(%rbp)
jmp 0x12578
movl -0x61c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x61c(%rbp)
jmp 0x12418
jmp 0x1258e
movl -0x618(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x618(%rbp)
jmp 0x123f8
leaq -0x3c8(%rbp), %rdi
callq 0x9160
jmp 0x125b0
leaq -0x5d0(%rbp), %rdi
callq 0x9160
jmp 0x125be
leaq -0x5d0(%rbp), %rdi
callq 0x91d0
leaq -0x3c8(%rbp), %rdi
callq 0x91d0
leaq -0x1a0(%rbp), %rdi
callq 0x9470
leaq -0x150(%rbp), %rdi
callq 0x9470
leaq -0x28(%rbp), %rdi
callq 0x9470
addq $0x6a0, %rsp            # imm = 0x6A0
popq %rbp
retq
leaq -0x5d0(%rbp), %rdi
callq 0x91d0
leaq -0x3c8(%rbp), %rdi
callq 0x91d0
leaq -0x1a0(%rbp), %rdi
callq 0x9470
leaq -0x150(%rbp), %rdi
callq 0x9470
leaq -0x28(%rbp), %rdi
callq 0x9470
movq -0x178(%rbp), %rdi
callq 0x9dc0
nopw %cs:(%rax,%rax)