// File: mattcha[P]sgd-svm/sgd_svm_train.cpp
// Function: main
int main(int argc, char** argv)
{
    Dataset dataset;
    Weight weight;
    Param param;

    if (argc != 5) {
        fprintf(stderr, 
                "Usage : %s iteration lambda trainname modelname\n", argv[0]);
        return 1;
    }

    param.iteration = atoi(argv[1]);
    param.lambda = atof(argv[2]);

    char *trainname = argv[3];
    char *modelname = argv[4];

    param.step = 0;

    int ret = load_data(trainname, dataset, weight);
    if (ret != 0) {
        fprintf(stderr, "load data [%s] fail\n", argv[1]);
        return -1;
    }

    ret = train(dataset, weight, param);
    if (ret != 0) {
        fprintf(stderr, "train fail\n");
        return -1;
    }

    ret = save_model(modelname, weight, param);
    if (ret != 0) {
        fprintf(stderr, "save model fail\n");
        return -1;
    }
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3130
leaq -0x40(%rbp), %rdi
callq 0x3150
cmpl $0x5, -0x8(%rbp)
je 0x2d13
movq 0x82f0(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x442f(%rip), %rsi      # 0x7128
movb $0x0, %al
callq 0x2220
movl $0x1, -0x4(%rbp)
movl $0x1, -0x7c(%rbp)
jmp 0x2ea4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2250
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x21e0
movsd %xmm0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x2460
movl %eax, -0xa8(%rbp)
jmp 0x2d76
movl -0xa8(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
je 0x2de7
movq 0x8246(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x43b5(%rip), %rsi      # 0x7159
movb $0x0, %al
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x7c(%rbp)
jmp 0x2ea4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3170
leaq -0x28(%rbp), %rdi
callq 0x3190
jmp 0x2ec2
leaq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2980
movl %eax, -0xac(%rbp)
jmp 0x2e00
movl -0xac(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
je 0x2e3d
movq 0x81bc(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x4348(%rip), %rsi      # 0x716e
movb $0x0, %al
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x7c(%rbp)
jmp 0x2ea4
movq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x2b60
movl %eax, -0xb0(%rbp)
jmp 0x2e59
movl -0xb0(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
je 0x2e96
movq 0x8163(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x42fb(%rip), %rsi      # 0x717a
movb $0x0, %al
callq 0x2220
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x7c(%rbp)
jmp 0x2ea4
movl $0x0, -0x4(%rbp)
movl $0x1, -0x7c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3170
leaq -0x28(%rbp), %rdi
callq 0x3190
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x2290
nop