// File: j-faria[P]kima/src/Data.cpp
// Function: Data::topslope() const
double Data::topslope() const
{
  if (datamulti) {
    double slope = 0.0;
    for(size_t j=0; j<number_instruments; j++)
    {
      vector<double> obsy, obst;
      for (size_t i=0; i<y.size(); ++i) {
        if (obsi[i] == j + 1) {
          obsy.push_back(y[i]);
          obst.push_back(t[i]);
        }
      }
      const auto miny = std::min_element(obsy.begin(), obsy.end());
      const auto maxy = std::max_element(obsy.begin(), obsy.end());
      const auto mint = std::min_element(obst.begin(), obst.end());
      const auto maxt = std::max_element(obst.begin(), obst.end());
      double this_obs_topslope = (*maxy - *miny) / (*maxt - *mint);
      if (this_obs_topslope > slope)
        slope = this_obs_topslope;
    }
    return slope;
  }

  else {
    return get_RV_span() / get_timespan();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
testb $0x1, 0xf4(%rax)
je 0x13d4b
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0xd8(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq 0xf8(%rcx), %rcx
cmpq %rcx, %rax
jae 0x13d3f
leaq -0x38(%rbp), %rdi
callq 0x77c0
leaq -0x50(%rbp), %rdi
callq 0x77c0
movq $0x0, -0x58(%rbp)
movq -0xd8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq %rax, -0xe0(%rbp)
addq $0x18, %rdi
callq 0x7c90
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jae 0x13b46
movq -0xd8(%rbp), %rdi
addq $0x48, %rdi
movq -0x58(%rbp), %rsi
callq 0x166f0
movslq (%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x13b33
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
movq -0x58(%rbp), %rsi
callq 0xa6a0
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x15700
jmp 0x13af0
movq -0xd8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xa6a0
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x15700
jmp 0x13b0e
jmp 0x13b33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x78f0
leaq -0x38(%rbp), %rdi
callq 0x78f0
jmp 0x13d8d
jmp 0x13b35
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x13a7c
leaq -0x38(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x7890
movq -0xf0(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x78c0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x16710
movq %rax, -0xe8(%rbp)
jmp 0x13b80
movq -0xe8(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x7890
movq -0x100(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0x78c0
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x16750
movq %rax, -0xf8(%rbp)
jmp 0x13bd1
movq -0xf8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x7890
movq -0x110(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x78c0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x16710
movq %rax, -0x108(%rbp)
jmp 0x13c25
movq -0x108(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x7890
movq -0x120(%rbp), %rdi
movq %rax, -0xc0(%rbp)
callq 0x78c0
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x16750
movq %rax, -0x118(%rbp)
jmp 0x13c79
movq -0x118(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x8970
movsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x8970
movsd -0x138(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x128(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x8970
movsd (%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x8970
movsd -0x130(%rbp), %xmm1
movsd -0x128(%rbp), %xmm0
subsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x13d1c
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x78f0
leaq -0x38(%rbp), %rdi
callq 0x78f0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x13a47
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13d7f
movq -0xd8(%rbp), %rdi
callq 0x13da0
movq -0xd8(%rbp), %rdi
movsd %xmm0, -0x140(%rbp)
callq 0x16790
movaps %xmm0, %xmm1
movsd -0x140(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x6830
nopw %cs:(%rax,%rax)