// File: /workspace/github_cpp_makefile_star2_O1/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 $0x5c8, %rsp            # imm = 0x5C8
movq %rdi, %rbx
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x68(%rdi), %rsi
movq 0x70(%rdi), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x434a
xorps %xmm0, %xmm0
leaq 0x340(%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 0x2c0(%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 0x1799e(%rip), %rsi     # 0x1c1bb
movl %ecx, %edx
xorl %eax, %eax
callq 0x3070
movl 0x150(%rbx), %ecx
movl 0x154(%rbx), %r8d
leaq 0x17997(%rip), %rsi     # 0x1c1d1
movq %r15, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x3070
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x434a
leaq 0x177fa(%rip), %rsi     # 0x1c06a
leaq 0xb8(%rsp), %rdi
callq 0x34b0
leaq 0xb8(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x34b0
leaq 0x28(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x48b9
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x48bf
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x20(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x48f4
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0xb8(%rsp), %rdi
movq %r15, (%rdi)
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
addq %rsi, %rdx
callq 0x434a
leaq 0x1774f(%rip), %rsi     # 0x1c06a
leaq 0xb8(%rsp), %rdi
callq 0x34b0
leaq 0xb8(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
callq 0x34b0
leaq 0x48(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4964
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x496a
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x499f
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x2a618(%rip), %rdi     # 0x2efc8
callq 0x32e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31c0
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x2a5d8(%rip), %rdi     # 0x2efc8
callq 0x32e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31c0
leaq 0xb8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movl $0x4, %edx
callq 0x3400
leaq 0x3c0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x4, %edx
callq 0x3400
movq 0xb8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xd8(%rsp,%rax)
jne 0x4d0f
movq 0x3c0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x3e0(%rsp,%rax)
jne 0x4d0f
cmpq $0x0, 0x140(%rbx)
jne 0x4a94
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq 0x140(%rbx), %rax
movq %rax, 0x60(%rsp)
cmpb $0x1, 0x40(%rbx)
jne 0x4b03
movl 0xa4(%rbx), %eax
movl %eax, 0xc(%rsp)
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x17741(%rip), %rsi     # 0x1c204
leaq 0x17752(%rip), %rdx     # 0x1c21c
leaq 0x98(%rsp), %rdi
callq 0x43da
leaq 0x98(%rsp), %rdi
callq 0x60e8
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x4b0d
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x4b0d
movl 0xa0(%rbx), %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movq %rax, 0x70(%rsp)
movq $0x0, 0x58(%rsp)
movq %rax, 0x68(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x4c50
movq 0x60(%rsp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r15d, %r15d
cmpl $0x0, 0xc(%rsp)
jle 0x4c3b
movl $0x1, %eax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x60(%rsp)
jle 0x4c0a
movslq %r15d, %r12
movl $0x8, %r13d
xorl %ebp, %ebp
movl $0x8, %edx
leaq 0xb8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3340
movl $0x8, %edx
leaq 0x3c0(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3340
cmpb $0x1, 0x40(%rbx)
jne 0x4bab
movl 0x8(%rbx), %ecx
incl %ecx
movq 0x10(%rsp), %rax
cltd
idivl %ecx
testl %edx, %edx
je 0x4bfa
testl %r15d, %r15d
js 0x4cf0
movq 0x140(%rbx), %rax
cmpq %rbp, %rax
jle 0x4cf0
cmpq %r12, 0x148(%rbx)
jle 0x4cf0
imulq %r12, %rax
shlq $0x4, %rax
addq 0x138(%rbx), %rax
movsd 0x70(%rsp), %xmm0
movsd %xmm0, -0x8(%r13,%rax)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, (%r13,%rax)
incq %rbp
addq $0x10, %r13
cmpq %rbp, %r14
jne 0x4b66
cmpb $0x0, 0x40(%rbx)
je 0x4c21
movl 0x8(%rbx), %ecx
incl %ecx
movq 0x10(%rsp), %rax
cltd
idivl %ecx
testl %edx, %edx
je 0x4c24
incl %r15d
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl 0xc(%rsp), %ecx
movq %rax, 0x10(%rsp)
jne 0x4b50
movq 0x58(%rsp), %rax
incl %eax
movq %rax, 0x58(%rsp)
cmpl 0x10(%rbx), %eax
jl 0x4b3b
leaq 0xb8(%rsp), %rdi
callq 0x3080
leaq 0x3c0(%rsp), %rdi
callq 0x3080
leaq 0x3c0(%rsp), %rdi
callq 0x30a0
leaq 0xb8(%rsp), %rdi
callq 0x30a0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x4ca0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x4cbc
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x4cde
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32b0
addq $0x5c8, %rsp            # imm = 0x5C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17cf0(%rip), %rdi     # 0x1c9e7
leaq 0x17d1e(%rip), %rsi     # 0x1ca1c
leaq 0x17d3a(%rip), %rcx     # 0x1ca3f
movl $0x16d, %edx            # imm = 0x16D
callq 0x31b0
movq 0x2a2da(%rip), %rdi     # 0x2eff0
leaq 0x174ca(%rip), %rsi     # 0x1c1e7
movl $0x1c, %edx
callq 0x32e0
movq 0x2a2c2(%rip), %rdi     # 0x2eff0
callq 0x3120
callq 0x3170
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x4db1
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x4db1
jmp 0x4dae
movq %rax, %rbx
jmp 0x4dbe
jmp 0x4da9
jmp 0x4d65
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4de7
movq 0xc8(%rsp), %rsi
jmp 0x4ddf
movq %rax, %rbx
jmp 0x4de7
jmp 0x4d86
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4e03
movq 0xc8(%rsp), %rsi
jmp 0x4dfb
movq %rax, %rbx
jmp 0x4e03
jmp 0x4dae
jmp 0x4dae
movq %rax, %rbx
jmp 0x4dcb
movq %rax, %rbx
leaq 0x3c0(%rsp), %rdi
callq 0x30a0
leaq 0xb8(%rsp), %rdi
callq 0x30a0
leaq 0x48(%rsp), %rax
movq 0x38(%rsp), %rdi
cmpq %rax, %rdi
je 0x4de7
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x28(%rsp), %rax
movq 0x18(%rsp), %rdi
cmpq %rax, %rdi
je 0x4e03
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x88(%rsp), %rax
movq 0x78(%rsp), %rdi
cmpq %rax, %rdi
je 0x4e25
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3460
nop