// File: mattcha[P]sgd-svm/sgd_svm.cpp
// Function: load_line(char const*, Instance&, unsigned int&)
int load_line(
        const char* line,
        Instance &instance,
        uint32_t &max_feature)
{
    double label;
    uint32_t fea_idx;
    double fea_val;

    stringstream ss(line);
    string field;
    if (getline(ss, field, ' ')) 
        label = atof(field.c_str());    
    else {
        fprintf(stderr, "read label fail [%s]\n",
                field.c_str());
        return -1;
    }
    instance.y_label = label;
    //cout << label << " ";

    while (true) {
        if (getline(ss, field, ':')) {
            fea_idx = atoi(field.c_str());
            //cout << fea_idx << ":";
        }
        else
            break;

        if (fea_idx > max_feature)
            max_feature = fea_idx;

        if (getline(ss, field, ' ')) {
            fea_val = atof(field.c_str());
            //cout << fea_val << " ";
        }
        else
            break;

        Feature fea;
        fea.idx = fea_idx;
        fea.val = fea_val;
        instance.f_vec.push_back(fea);
    }

    //cout << endl;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x240(%rbp)
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x22a0
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x5ef0
jmp 0x5c01
movl $0x10, %edi
movl $0x8, %esi
callq 0x5fa0
movl %eax, -0x244(%rbp)
jmp 0x5c18
movl -0x244(%rbp), %edx
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x2260
jmp 0x5c33
leaq -0x1e0(%rbp), %rdi
callq 0x20b0
leaq -0x1e1(%rbp), %rdi
callq 0x2180
leaq -0x218(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x2210
movq -0x258(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
movl $0x20, %edx
callq 0x22c0
movq %rax, -0x250(%rbp)
jmp 0x5c7f
movq -0x250(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21f0
movb %al, -0x259(%rbp)
jmp 0x5c9d
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x5cac
jmp 0x5d3c
leaq -0x218(%rbp), %rdi
callq 0x2080
movq %rax, %rdi
callq 0x21e0
movsd %xmm0, -0x28(%rbp)
jmp 0x5d87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
jmp 0x5cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x20b0
leaq -0x1e1(%rbp), %rdi
callq 0x2180
jmp 0x5ee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x20b0
leaq -0x1c0(%rbp), %rdi
callq 0x20e0
jmp 0x5ee1
movq 0x5295(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, -0x268(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x2080
movq -0x268(%rbp), %rdi
movq %rax, %rdx
leaq 0x143b(%rip), %rsi      # 0x71a5
movb $0x0, %al
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x21c(%rbp)
jmp 0x5ebd
movsd -0x28(%rbp), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x5d96
leaq -0x1c0(%rbp), %rdi
leaq -0x218(%rbp), %rsi
movl $0x3a, %edx
callq 0x22c0
movq %rax, -0x270(%rbp)
jmp 0x5db7
movq -0x270(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21f0
movb %al, -0x271(%rbp)
jmp 0x5dd5
movb -0x271(%rbp), %al
testb $0x1, %al
jne 0x5de1
jmp 0x5dfa
leaq -0x218(%rbp), %rdi
callq 0x2080
movq %rax, %rdi
callq 0x2250
movl %eax, -0x2c(%rbp)
jmp 0x5dff
jmp 0x5eac
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x5e13
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
leaq -0x1c0(%rbp), %rdi
leaq -0x218(%rbp), %rsi
movl $0x20, %edx
callq 0x22c0
movq %rax, -0x280(%rbp)
jmp 0x5e34
movq -0x280(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21f0
movb %al, -0x281(%rbp)
jmp 0x5e52
movb -0x281(%rbp), %al
testb $0x1, %al
jne 0x5e5e
jmp 0x5e79
leaq -0x218(%rbp), %rdi
callq 0x2080
movq %rax, %rdi
callq 0x21e0
movsd %xmm0, -0x38(%rbp)
jmp 0x5e7b
jmp 0x5eac
movl -0x2c(%rbp), %eax
movl %eax, -0x230(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x228(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
leaq -0x230(%rbp), %rsi
callq 0x5fc0
jmp 0x5ea7
jmp 0x5d94
movl $0x0, -0x4(%rbp)
movl $0x1, -0x21c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x20b0
leaq -0x1c0(%rbp), %rdi
callq 0x20e0
movl -0x4(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x1f0(%rbp), %rdi
callq 0x2290
nopl (%rax)