// File: bowbowbow[P]CollaborativeFiltering/recommender.cpp
// Function: main
int main(int argc, const char * argv[]) {
    if(argc!=3) {
        cout << "Please follow this format. recommender.exe [base file name] [test file name]";
        return 0;
    }
    
    string baseFileName(argv[1]);
    string testFileName(argv[2]);
    
    InputReader baseInputReader(baseFileName);
    
    MAT userToItem = baseInputReader.getUserToItem();
    CF cf(userToItem);
    cf.run();
    
    InputReader testInputReader(testFileName);
    vector<inputTuple> test = testInputReader.getInput();
    
    OutputPrinter outputPrinter(testFileName.substr(0, 2)+".base_prediction.txt");
    
    double RSME = 0.0;
    
    for(int i=0;i<test.size();i++) {
        int user = test[i].user;
        int item = test[i].item;
        int rating = test[i].rating;
        
        double predict = cf.predict(user, item);
        
        RSME += (predict-rating)*(predict-rating);
        outputPrinter.addLine(user, item, predict);
    }
    
    RSME /= (double)test.size();
    RSME = sqrt(RSME);
    cout << "RSME :" << RSME << endl;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x880, %rsp            # imm = 0x880
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x241e
movq 0xabd2(%rip), %rdi      # 0xcfd8
leaq 0x5c43(%rip), %rsi      # 0x8050
callq 0x2150
movl $0x0, -0x4(%rbp)
jmp 0x29ac
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x848(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x840(%rbp)
callq 0x2260
movq -0x848(%rbp), %rsi
movq -0x840(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x21c0
jmp 0x2456
leaq -0x31(%rbp), %rdi
callq 0x2190
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x858(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x850(%rbp)
callq 0x2260
movq -0x858(%rbp), %rsi
movq -0x850(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x21c0
jmp 0x2497
leaq -0x69(%rbp), %rdi
callq 0x2190
leaq -0x2c8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2080
jmp 0x24b2
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x29d0
jmp 0x24c7
leaq -0x2c8(%rbp), %rdi
callq 0x20e0
leaq -0x2e0(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x2ad0
jmp 0x24e8
leaq -0x348(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x2b10
jmp 0x24fd
leaq -0x330(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x2c00
jmp 0x2512
leaq -0x348(%rbp), %rdi
callq 0x2d40
leaq -0x330(%rbp), %rdi
callq 0x2da0
jmp 0x252c
leaq -0x5a0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2080
jmp 0x253e
leaq -0x580(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x29d0
jmp 0x2553
leaq -0x5a0(%rbp), %rdi
callq 0x20e0
leaq -0x5b8(%rbp), %rdi
leaq -0x580(%rbp), %rsi
callq 0x2dc0
jmp 0x2574
xorl %eax, %eax
movl %eax, %edx
leaq -0x818(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x2, %ecx
callq 0x2170
jmp 0x258f
leaq 0x5b07(%rip), %rdx      # 0x809d
leaq -0x7f8(%rbp), %rdi
leaq -0x818(%rbp), %rsi
callq 0x2e00
jmp 0x25ab
leaq -0x7d8(%rbp), %rdi
leaq -0x7f8(%rbp), %rsi
callq 0x2e50
jmp 0x25c0
leaq -0x7f8(%rbp), %rdi
callq 0x20e0
leaq -0x818(%rbp), %rdi
callq 0x20e0
xorps %xmm0, %xmm0
movsd %xmm0, -0x820(%rbp)
movl $0x0, -0x824(%rbp)
movslq -0x824(%rbp), %rax
movq %rax, -0x860(%rbp)
leaq -0x5b8(%rbp), %rdi
callq 0x2f30
movq %rax, %rcx
movq -0x860(%rbp), %rax
cmpq %rcx, %rax
jae 0x284f
movslq -0x824(%rbp), %rsi
leaq -0x5b8(%rbp), %rdi
movq %rdi, -0x870(%rbp)
callq 0x2f60
movq -0x870(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x828(%rbp)
movslq -0x824(%rbp), %rsi
callq 0x2f60
movq -0x870(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x82c(%rbp)
movslq -0x824(%rbp), %rsi
callq 0x2f60
movl 0x8(%rax), %eax
movl %eax, -0x830(%rbp)
movl -0x828(%rbp), %esi
movl -0x82c(%rbp), %edx
leaq -0x330(%rbp), %rdi
callq 0x2f80
movl %eax, -0x864(%rbp)
jmp 0x2694
movl -0x864(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x838(%rbp)
movsd -0x838(%rbp), %xmm0
cvtsi2sdl -0x830(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd -0x820(%rbp), %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x820(%rbp)
movl -0x828(%rbp), %esi
movl -0x82c(%rbp), %edx
movsd -0x838(%rbp), %xmm0
leaq -0x7d8(%rbp), %rdi
callq 0x30f0
jmp 0x26f4
jmp 0x26f6
movl -0x824(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x824(%rbp)
jmp 0x25ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x2190
jmp 0x29b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x2190
jmp 0x29a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2998
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x20e0
jmp 0x2998
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x298c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x348(%rbp), %rdi
callq 0x2d40
jmp 0x2980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x5a0(%rbp), %rdi
callq 0x20e0
jmp 0x2974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x295c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2821
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x7f8(%rbp), %rdi
callq 0x20e0
leaq -0x818(%rbp), %rdi
callq 0x20e0
jmp 0x295c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x7d8(%rbp), %rdi
callq 0x3160
jmp 0x295c
leaq -0x5b8(%rbp), %rdi
callq 0x2f30
movq %rax, %xmm1
movaps 0x57a9(%rip), %xmm0     # 0x8010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x57ad(%rip), %xmm0     # 0x8020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd -0x820(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x820(%rbp)
movsd -0x820(%rbp), %xmm0
callq 0x2100
movsd %xmm0, -0x820(%rbp)
movq 0xa726(%rip), %rdi      # 0xcfd8
leaq 0x57f9(%rip), %rsi      # 0x80b2
callq 0x2150
movq %rax, -0x878(%rbp)
jmp 0x28c7
movq -0x878(%rbp), %rdi
movsd -0x820(%rbp), %xmm0
callq 0x2280
movq %rax, -0x880(%rbp)
jmp 0x28e4
movq -0x880(%rbp), %rdi
movq 0xa6d6(%rip), %rsi      # 0xcfc8
callq 0x2180
jmp 0x28f9
movl $0x0, -0x4(%rbp)
leaq -0x7d8(%rbp), %rdi
callq 0x3160
leaq -0x5b8(%rbp), %rdi
callq 0x3190
leaq -0x580(%rbp), %rdi
callq 0x31f0
leaq -0x330(%rbp), %rdi
callq 0x3230
leaq -0x2e0(%rbp), %rdi
callq 0x2d40
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x68(%rbp), %rdi
callq 0x20e0
leaq -0x30(%rbp), %rdi
callq 0x20e0
jmp 0x29ac
leaq -0x5b8(%rbp), %rdi
callq 0x3190
leaq -0x580(%rbp), %rdi
callq 0x31f0
leaq -0x330(%rbp), %rdi
callq 0x3230
leaq -0x2e0(%rbp), %rdi
callq 0x2d40
leaq -0x2a8(%rbp), %rdi
callq 0x31f0
leaq -0x68(%rbp), %rdi
callq 0x20e0
leaq -0x30(%rbp), %rdi
callq 0x20e0
jmp 0x29b8
movl -0x4(%rbp), %eax
addq $0x880, %rsp            # imm = 0x880
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x2250
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)