// File: tetsuok[P]kernel-pa/learner.cc
// Function: kernel::Learner::Train(char const*, int)
bool Learner::Train(const char* filename, int iter) {
  vector<example> examples;
  size_t maxid = 0;
  if (!Read(filename, examples, &maxid)) {
    LOG(ERROR) << "cannot read training data " << filename;
    return false;
  }

  const std::size_t num_examples = examples.size();

  for (int t = 0; t < iter; ++t) {
    fprintf(stderr, "iter = %d\n", t+1);
    for (const auto e : examples) {
      const float m = Margin(e.first);
      const float loss = HingeLoss(m, e.second);
      if (loss >= 0.0) {
        const float rate = LearningRate(loss, e.first);
        UpdateIndex(e.first, static_cast<unsigned int>(alpha_.size()));
        UpdateAlpha(e.first, rate, e.second);
      }
    }
  }

  fprintf(stderr, "INFO: the number of support vectors = %lu\n",
          margin_.size());
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x5a60
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rcx
callq 0x42b0
movb %al, -0xad(%rbp)
jmp 0x489c
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x4a17
jmp 0x48ac
leaq -0x50(%rbp), %rdi
movl $0x2, %esi
callq 0x2e30
jmp 0x48bc
callq 0x2e60
movq %rax, -0xc8(%rbp)
jmp 0x48ca
movq -0xc8(%rbp), %rdi
leaq 0x6753(%rip), %rsi      # 0xb02b
callq 0x2150
movq %rax, -0xd0(%rbp)
jmp 0x48e6
movq -0xd0(%rbp), %rdi
leaq 0x673c(%rip), %rsi      # 0xb030
callq 0x2150
movq %rax, -0xd8(%rbp)
jmp 0x4902
movq -0xd8(%rbp), %rdi
leaq 0x6726(%rip), %rsi      # 0xb036
callq 0x2150
movq %rax, -0xe0(%rbp)
jmp 0x491e
movq -0xe0(%rbp), %rdi
leaq 0x67e8(%rip), %rsi      # 0xb114
callq 0x2150
movq %rax, -0xe8(%rbp)
jmp 0x493a
movq -0xe8(%rbp), %rdi
leaq 0x66e6(%rip), %rsi      # 0xb02e
callq 0x2150
movq %rax, -0xf0(%rbp)
jmp 0x4956
movq -0xf0(%rbp), %rdi
movl $0x2f, %esi
callq 0x22a0
movq %rax, -0xf8(%rbp)
jmp 0x4970
movq -0xf8(%rbp), %rdi
leaq 0x66d2(%rip), %rsi      # 0xb050
callq 0x2150
movq %rax, -0x100(%rbp)
jmp 0x498c
movq -0x100(%rbp), %rdi
leaq 0x6794(%rip), %rsi      # 0xb12e
callq 0x2150
movq %rax, -0x108(%rbp)
jmp 0x49a8
movq -0x108(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2150
movq %rax, -0x110(%rbp)
jmp 0x49c1
movq -0x110(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x2e50
jmp 0x49d3
leaq -0x50(%rbp), %rdi
callq 0x2e70
movb $0x0, -0x1(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x4c2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4c46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2e70
jmp 0x4c46
leaq -0x38(%rbp), %rdi
callq 0x5a80
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4beb
movq 0xc592(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
movl -0x64(%rbp), %edx
addl $0x1, %edx
leaq 0x66fb(%rip), %rsi      # 0xb149
movb $0x0, %al
callq 0x2210
leaq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x5aa0
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x5ad0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5b00
testb $0x1, %al
jne 0x4a8d
jmp 0x4bdb
leaq -0x78(%rbp), %rdi
callq 0x5b40
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x5b60
jmp 0x4aa7
movq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3050
movss %xmm0, -0x114(%rbp)
jmp 0x4ac4
movq -0xc0(%rbp), %rdi
movss -0x114(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movss -0xa4(%rbp), %xmm0
movswl -0x88(%rbp), %esi
callq 0x5ba0
movss %xmm0, -0x118(%rbp)
jmp 0x4af9
movss -0x118(%rbp), %xmm0
movss %xmm0, -0xa8(%rbp)
movss -0xa8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x4bc1
movq -0xc0(%rbp), %rdi
movss -0xa8(%rbp), %xmm0
leaq -0xa0(%rbp), %rsi
callq 0x5c10
movss %xmm0, -0x11c(%rbp)
jmp 0x4b47
movq -0xc0(%rbp), %rdi
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0xac(%rbp)
addq $0x10, %rdi
callq 0x3220
movq -0xc0(%rbp), %rdi
movl %eax, %edx
leaq -0xa0(%rbp), %rsi
callq 0x5c70
jmp 0x4b7e
movq -0xc0(%rbp), %rdi
movss -0xac(%rbp), %xmm0
movswl -0x88(%rbp), %edx
leaq -0xa0(%rbp), %rsi
callq 0x5d60
jmp 0x4ba2
jmp 0x4bc1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5a40
jmp 0x4c46
leaq -0xa0(%rbp), %rdi
callq 0x5a40
leaq -0x78(%rbp), %rdi
callq 0x5dd0
jmp 0x4a77
jmp 0x4bdd
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x4a2b
movq -0xc0(%rbp), %rdi
movq 0xc3d7(%rip), %rax      # 0x10fd0
movq (%rax), %rax
movq %rax, -0x128(%rbp)
addq $0x40, %rdi
callq 0x3220
movq -0x128(%rbp), %rdi
movq %rax, %rdx
leaq 0x6537(%rip), %rsi      # 0xb154
movb $0x0, %al
callq 0x2210
movb $0x1, -0x1(%rbp)
movl $0x1, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5df0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x5df0
movq -0x48(%rbp), %rdi
callq 0x22b0
nopl (%rax,%rax)