// File: shuimu[P]logistic-regression/lr.cpp
// Function: load_data()
int load_data() {
    FILE * tfp, * pfp;
    int line = 0, sz = 0; 
    char buffer[LINE_LEN];
    char ** str_array = NULL;
 
    // load train file
    if((tfp = fopen(train_file, "r")) == NULL) {
        fprintf(stderr, "train file is not valid\n");
        return -1;
    }
    M = 0;
    while(fgets(buffer, LINE_LEN, tfp) != NULL) {
        vector<double> tmp;
        str_array = split(buffer, '\t', &sz);
        D = sz - 2;
        train_instances.push_back(str_array[0]);
        for(int i = 1; i < sz-1; i++) {
            tmp.push_back(atof(str_array[i]));
        }
        train_features.push_back(tmp);
        labels.push_back(atof(str_array[sz-1]));
        M++;
    }
    fclose(tfp);

    // load predict data
    if((pfp = fopen(predict_file, "r")) == NULL) {
        fprintf(stderr, "load predict file failed");
        return -1;
    }
    while(fgets(buffer, LINE_LEN, pfp) != NULL) {
        vector<double> tmp;
        str_array = split(buffer, '\t', &sz);
        predict_instances.push_back(str_array[0]);
        for(int i = 1; i < sz; i++) {
            tmp.push_back(atof(str_array[i]));
        }
        predict_features.push_back(tmp);
    }
    fclose(pfp);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq $0x0, -0x128(%rbp)
movq 0x73f5(%rip), %rdi      # 0x9110
leaq 0x34af(%rip), %rsi      # 0x51d1
callq 0x10d0
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x1d55
movq 0x72a0(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3491(%rip), %rsi      # 0x51d3
movb $0x0, %al
callq 0x1110
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x200f
movl $0x0, 0x7389(%rip)      # 0x90e8
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x1150
cmpq $0x0, %rax
je 0x1eb5
leaq -0x140(%rbp), %rdi
callq 0x2410
leaq -0x120(%rbp), %rdi
movl $0x9, %esi
leaq -0x20(%rbp), %rdx
callq 0x1ba0
movq %rax, -0x128(%rbp)
movl -0x20(%rbp), %eax
addl $-0x2, %eax
movl %eax, 0x733a(%rip)      # 0x90ec
movq -0x128(%rbp), %rsi
leaq 0x73b0(%rip), %rdi      # 0x9170
callq 0x2550
jmp 0x1dc7
movl $0x1, -0x150(%rbp)
movl -0x150(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1e4b
movq -0x128(%rbp), %rax
movslq -0x150(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10e0
movsd %xmm0, -0x158(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x25c0
jmp 0x1e15
jmp 0x1e17
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x1dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x2430
jmp 0x201b
leaq 0x72d6(%rip), %rdi      # 0x9128
leaq -0x140(%rbp), %rsi
callq 0x25f0
jmp 0x1e60
movq -0x128(%rbp), %rax
movl -0x20(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10e0
movsd %xmm0, -0x160(%rbp)
leaq 0x72d1(%rip), %rdi      # 0x9158
leaq -0x160(%rbp), %rsi
callq 0x25c0
jmp 0x1e95
movl 0x724d(%rip), %eax      # 0x90e8
addl $0x1, %eax
movl %eax, 0x7244(%rip)      # 0x90e8
leaq -0x140(%rbp), %rdi
callq 0x2430
jmp 0x1d5f
movq -0x10(%rbp), %rdi
callq 0x10a0
movq 0x7253(%rip), %rdi      # 0x9118
leaq 0x3305(%rip), %rsi      # 0x51d1
callq 0x10d0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x1eff
movq 0x70f6(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x3300(%rip), %rsi      # 0x51ec
movb $0x0, %al
callq 0x1110
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x200f
jmp 0x1f01
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x1150
cmpq $0x0, %rax
je 0x1fff
leaq -0x178(%rbp), %rdi
callq 0x2410
leaq -0x120(%rbp), %rdi
movl $0x9, %esi
leaq -0x20(%rbp), %rdx
callq 0x1ba0
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rsi
leaq 0x7232(%rip), %rdi      # 0x9188
callq 0x2550
jmp 0x1f5d
movl $0x1, -0x17c(%rbp)
movl -0x17c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1fd9
movq -0x128(%rbp), %rax
movslq -0x17c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10e0
movsd %xmm0, -0x188(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x25c0
jmp 0x1fa6
jmp 0x1fa8
movl -0x17c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17c(%rbp)
jmp 0x1f67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2430
jmp 0x201b
leaq 0x7160(%rip), %rdi      # 0x9140
leaq -0x178(%rbp), %rsi
callq 0x25f0
jmp 0x1fee
leaq -0x178(%rbp), %rdi
callq 0x2430
jmp 0x1f01
movq -0x18(%rbp), %rdi
callq 0x10a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x1180
nopw (%rax,%rax)