// File: myudelson[P]hmm-scalable/FitBitSt.cpp
// Function: FitBitSt::FitBitSt(task*, double*, double*, int)
FitBitSt::FitBitSt(struct task *task, NUMBER* a_PARAM, NUMBER* a_GRAD, NCAT a_nPARAM) {
    this->nS = task->nS;
    this->nO = task->nO;
    this->nG = task->nG;
    this->nK = task->nK;
    this->tol = task->tol;
    this->tol_mode = task->tol_mode;
    this->nPARAM = a_nPARAM;
    this->PARAM = a_PARAM;
    this->PARAMm1 = NULL;
    this->PARAMm2 = NULL;
    this->GRAD = a_GRAD;
    this->GRADm1 = NULL;
    this->GRADcopy = NULL;
    this->PARAMcopy = NULL;
    this->DIR = NULL;
    this->DIRm1 = NULL;
    this->task = task;
    this->projecttosimplex = 1;
    this->Cslice = 0;
    this->tag = 0;
    
    this->fit_results = new FitResult[this->nK];
    for(NCAT k=0; k<this->nK; k++) {
        this->fit_results[k].iter = 0;
        this->fit_results[k].pO0_prefit = -1.0; // means never assigned
        this->fit_results[k].pO0  = 0.0;
        this->fit_results[k].pO   = 0.0;
        this->fit_results[k].conv = 0;
        this->fit_results[k].ndat = 0;
    }
    this->fit_result.iter = 0;
    this->fit_result.pO0_prefit = -1.0; // means never assigned
    this->fit_result.pO0  = 0.0;
    this->fit_result.pO   = 0.0;
    this->fit_result.conv = 0;
    this->fit_result.ndat = 0;

    this->sclsmplx_offsets = NULL;// start positions of the scaled vectors in the gradient and parameter arrays
    this->sclsmplx_sizes = NULL;// lengths of the scaled vectorsin the gradient and parameter arrays
    this->sclsmplx_bound_offsets = NULL;
    this->sclsmplx_blocks = NULL;
    this->param_blocks = NULL;
    this->sclsmplx_n = 0;

    this->PARAMm1 = init1D<NUMBER>(this->nPARAM);
    this->PARAMm2 = init1D<NUMBER>(this->nPARAM);
    
    if(this->task->solver==METHOD_GD || this->task->solver==METHOD_CGD || this->task->solver==METHOD_GBB || this->task->solver==METHOD_GDL) {
        toValue1D<NUMBER>(this->GRAD, this->nPARAM, 0); // init1D<NUMBER>(this->nPARAM);
    }
    if(this->task->solver==METHOD_CGD) {
        this->DIR = init1D<NUMBER>(this->nPARAM);
        this->DIRm1 = init1D<NUMBER>(this->nPARAM);
        this->GRADm1 = init1D<NUMBER>(this->nPARAM);
    }
    if(this->task->solver==METHOD_GBB) {
        this->GRADm1 = init1D<NUMBER>(this->nPARAM);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movb 0x900(%rcx), %cl
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rcx
movb 0x901(%rcx), %cl
movb %cl, (%rax)
movq -0x10(%rbp), %rcx
movl 0x904(%rcx), %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rcx
movl 0x908(%rcx), %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rcx
movsd 0x38(%rcx), %xmm0
movsd %xmm0, 0xc8(%rax)
movq -0x10(%rbp), %rcx
movb 0x40(%rcx), %cl
movb %cl, 0xd0(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq $0x0, 0x38(%rax)
movq $0x0, 0x40(%rax)
movq $0x0, 0x28(%rax)
movq $0x0, 0x48(%rax)
movq $0x0, 0x50(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x88(%rax)
movb $0x1, 0x90(%rax)
movb $0x0, 0x91(%rax)
movb $0x0, 0x92(%rax)
movslq 0x8(%rax), %rax
movl $0x28, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x58(%rax)
movl $0x0, -0x28(%rbp)
movq -0x30(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x8(%rcx), %eax
jge 0xac74
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl $0x0, (%rcx)
movq 0x58(%rax), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movsd 0x10e46(%rip), %xmm0    # 0x1ba50
movsd %xmm0, 0x8(%rcx)
movq 0x58(%rax), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rcx)
movq 0x58(%rax), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rcx)
movq 0x58(%rax), %rcx
movslq -0x28(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movb $0x0, 0x20(%rcx)
movq 0x58(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x24(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xabca
movq -0x30(%rbp), %rax
movl $0x0, 0x60(%rax)
movsd 0x10dc9(%rip), %xmm0    # 0x1ba50
movsd %xmm0, 0x68(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x78(%rax)
movb $0x0, 0x80(%rax)
movl $0x0, 0x84(%rax)
movq $0x0, 0x98(%rax)
movq $0x0, 0xa8(%rax)
movq $0x0, 0xa0(%rax)
movq $0x0, 0xb0(%rax)
movq $0x0, 0xb8(%rax)
movl $0x0, 0xc0(%rax)
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x2, %eax
je 0xad60
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x3, %eax
je 0xad60
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x5, %eax
je 0xad60
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x4, %eax
jne 0xad73
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movl 0xc(%rax), %esi
xorps %xmm0, %xmm0
callq 0xb870
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x3, %eax
jne 0xadc4
movq -0x30(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x4f(%rax), %eax
cmpl $0x5, %eax
jne 0xadef
movq -0x30(%rbp), %rax
movl 0xc(%rax), %edi
callq 0x9da0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)