// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/confchange.c
// Function: Lasso_confchange_fit
int Lasso_confchange_fit(struct Tors *Diff, struct Normal_Mode *NM,
			 struct bond *bonds, atom *atoms, int natoms,
			 struct Reference Ref, float *coord_1, float *coord_2,
			 char *nameout)
{
  char out[100]; sprintf(out, "%s_Lasso.dat", nameout);
  printf("Writing %s\n", out);
  FILE *file_out=fopen(out, "w");
  
  float c[NM->N]; double c2_sum=0, sum_c1=0; int i;
  for (i=0; i<NM->N; i++){
    c[i]=Scalar_product_weighted(Diff->Cart, NM->Cart[i],
				 Ref.mass_coord, Ref.N_Cart);
    c2_sum+=c[i]*c[i]; sum_c1+=fabs(c[i]);
  }
  sum_c1/=NM->N; // average projection
  fprintf(file_out, "# %d modes 
=%.4g\n#lambda rmsd(conf,str2)\n",
	  NM->N, sum_c1);

  float cnew[NM->N], coord_new[3*Ref.N_ref], coord_all[3*natoms];
  double d_phi[NM->N_axes];

  float x[3], y[3], lambda=sum_c1, lambda_step=lambda*0.2;
  y[1]=-RMSD_Lasso_confchange(0, cnew, d_phi, coord_all, coord_new,
			      c,c2_sum,NM,bonds,atoms,natoms,Ref,coord_2);
  fprintf(file_out, "%.3f %.3f\n", 0.0, -y[1]);
  x[1]=lambda;
  y[1]=-RMSD_Lasso_confchange(lambda, cnew, d_phi, coord_all, coord_new,
			      c,c2_sum,NM,bonds,atoms,natoms,Ref,coord_2);
  fprintf(file_out, "%.3f %.3f\n", x[1], -y[1]);
  int n_down=0; float score_opt=y[1], lambda_opt=lambda;
  
  for(int iter=0; iter<100; iter++){
    if(n_down==1)break;
    x[0]=x[1]-lambda_step; if(x[0]<0)x[0]=0;
    x[2]=x[1]+lambda_step;
    for(i=0; i<=2; i+=2){
      y[i]=-RMSD_Lasso_confchange(x[i], cnew, d_phi, coord_all, coord_new,
				  c,c2_sum,NM,bonds,atoms,natoms,Ref,coord_2);
      fprintf(file_out, "%.3f %.3f\n", x[i], -y[i]);
    }
    lambda=Find_max_quad(x[0],x[1],x[2],y[0],y[1],y[2],0,100);
    float yy=-RMSD_Lasso_confchange(lambda, cnew, d_phi, coord_all, coord_new,
				    c,c2_sum,NM,bonds,atoms,natoms,Ref,coord_2);
    x[1]=lambda; y[1]=yy;
    fprintf(file_out, "%.3f %.3f\n", x[1], -y[1]);
    if(yy>score_opt){
      lambda_opt=lambda;
      if(fabs(score_opt-yy)<0.01)break;
      score_opt=yy; n_down=0;
    }else{
      n_down++;
    }
  }

  RMSD_Lasso_confchange(lambda_opt, cnew, d_phi, coord_all, coord_new,
			c,c2_sum,NM,bonds,atoms,natoms,Ref,coord_2);
  for(i=0; i<NM->N_axes; i++)Diff->Tors[i]=d_phi[i];

  fclose(file_out);
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0x158(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movq %r9, -0x40(%rbp)
movq 0x48(%rbp), %rdx
leaq 0x37c1c(%rip), %rsi     # 0x80010
xorl %eax, %eax
movb %al, -0x149(%rbp)
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x1200
movq -0x148(%rbp), %rsi
movb -0x149(%rbp), %al
leaq 0x2f0cb(%rip), %rdi     # 0x774ee
callq 0x10d0
movq -0x148(%rbp), %rdi
leaq 0x33f3c(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq %rsp, %rcx
movq %rcx, -0xc0(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x140(%rbp)
movq %rcx, %rsp
movq %rax, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd8(%rbp)
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x48553
movq -0x158(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rcx
movq 0x38(%rcx), %rcx
movslq -0xdc(%rbp), %rdx
movq (%rcx,%rdx,8), %rsi
movq 0x18(%rax), %rdx
movl 0x4(%rax), %ecx
callq 0x15510
movq -0x140(%rbp), %rax
movslq -0xdc(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movslq -0xdc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movslq -0xdc(%rbp), %rcx
mulss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movslq -0xdc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movaps 0x33f65(%rip), %xmm1    # 0x7c490
pand %xmm1, %xmm0
addsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x48495
movq -0x20(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
movsd -0xd8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %edx
movsd -0xd8(%rbp), %xmm0
leaq 0x37a92(%rip), %rsi     # 0x8001d
movb $0x1, %al
callq 0x1150
movq -0x140(%rbp), %r8
movq -0x158(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rdi
subq %rdx, %rdi
movq %rdi, -0x178(%rbp)
movq %rdi, %rsp
movq %rcx, -0xe8(%rbp)
movl (%rax), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, %edx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rcx
subq %rsi, %rcx
movq %rcx, -0x160(%rbp)
movq %rcx, %rsp
movq %rdx, -0xf0(%rbp)
movl -0x34(%rbp), %esi
movl %esi, %edx
leal (%rdx,%rdx,2), %edx
movl %edx, %esi
leaq 0xf(,%rsi,4), %r9
andq $-0x10, %r9
movq %rsp, %rdx
subq %r9, %rdx
movq %rdx, -0x168(%rbp)
movq %rdx, %rsp
movq %rsi, -0xf8(%rbp)
movq -0x20(%rbp), %rsi
movl 0x8(%rsi), %esi
movl %esi, %r9d
leaq 0xf(,%r9,8), %r10
andq $-0x10, %r10
movq %rsp, %rsi
subq %r10, %rsi
movq %rsi, -0x170(%rbp)
movq %rsi, %rsp
movq %r9, -0x100(%rbp)
movsd -0xd8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x11c(%rbp)
movss -0x11c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2d9a1(%rip), %xmm1    # 0x76018
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x120(%rbp)
movsd -0xd0(%rbp), %xmm1
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %ebx
movq 0x40(%rbp), %r14
subq $0x50, %rsp
movups (%rax), %xmm0
movups 0x10(%rax), %xmm2
movups 0x20(%rax), %xmm3
movq %rsp, %rax
movups %xmm3, 0x38(%rax)
movups %xmm2, 0x28(%rax)
movups %xmm0, 0x18(%rax)
movq %r14, 0x48(%rax)
movl %ebx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
xorps %xmm0, %xmm0
callq 0x48c80
addq $0x50, %rsp
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x114(%rbp)
movq -0xb8(%rbp), %rdi
movss -0x114(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm1
leaq 0x388ba(%rip), %rsi     # 0x80fd0
xorps %xmm0, %xmm0
movb $0x2, %al
callq 0x1150
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
movq -0x160(%rbp), %rcx
movq -0x140(%rbp), %r8
movq -0x158(%rbp), %rax
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x108(%rbp)
movss -0x11c(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %ebx
movq 0x40(%rbp), %r14
subq $0x50, %rsp
movups (%rax), %xmm2
movups 0x10(%rax), %xmm3
movups 0x20(%rax), %xmm4
movq %rsp, %rax
movups %xmm4, 0x38(%rax)
movups %xmm3, 0x28(%rax)
movups %xmm2, 0x18(%rax)
movq %r14, 0x48(%rax)
movl %ebx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0x48c80
addq $0x50, %rsp
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x114(%rbp)
movq -0xb8(%rbp), %rdi
movss -0x108(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x114(%rbp), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x387d6(%rip), %rsi     # 0x80fd0
movb $0x2, %al
callq 0x1150
movl $0x0, -0x124(%rbp)
movss -0x114(%rbp), %xmm0
movss %xmm0, -0x128(%rbp)
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x12c(%rbp)
movl $0x0, -0x130(%rbp)
cmpl $0x64, -0x130(%rbp)
jge 0x48b7e
cmpl $0x1, -0x124(%rbp)
jne 0x48850
jmp 0x48b7e
movss -0x108(%rbp), %xmm0
subss -0x120(%rbp), %xmm0
movss %xmm0, -0x10c(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x10c(%rbp), %xmm0
jbe 0x4887f
xorps %xmm0, %xmm0
movss %xmm0, -0x10c(%rbp)
movss -0x108(%rbp), %xmm0
addss -0x120(%rbp), %xmm0
movss %xmm0, -0x104(%rbp)
movl $0x0, -0xdc(%rbp)
cmpl $0x2, -0xdc(%rbp)
jg 0x489b4
movq -0x140(%rbp), %r8
movq -0x160(%rbp), %rcx
movq -0x168(%rbp), %rdx
movq -0x170(%rbp), %rsi
movq -0x178(%rbp), %rdi
movq -0x158(%rbp), %rax
movslq -0xdc(%rbp), %r9
movss -0x10c(%rbp,%r9,4), %xmm0
movsd -0xd0(%rbp), %xmm1
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %ebx
movq 0x40(%rbp), %r14
subq $0x50, %rsp
movups (%rax), %xmm2
movups 0x10(%rax), %xmm3
movups 0x20(%rax), %xmm4
movq %rsp, %rax
movups %xmm4, 0x38(%rax)
movups %xmm3, 0x28(%rax)
movups %xmm2, 0x18(%rax)
movq %r14, 0x48(%rax)
movl %ebx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0x48c80
addq $0x50, %rsp
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movslq -0xdc(%rbp), %rax
movss %xmm0, -0x118(%rbp,%rax,4)
movq -0xb8(%rbp), %rdi
movslq -0xdc(%rbp), %rax
movss -0x10c(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0xdc(%rbp), %rax
movss -0x118(%rbp,%rax,4), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x38637(%rip), %rsi     # 0x80fd0
movb $0x2, %al
callq 0x1150
movl -0xdc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xdc(%rbp)
jmp 0x488a1
movss -0x10c(%rbp), %xmm0
movss -0x108(%rbp), %xmm1
movss -0x104(%rbp), %xmm2
movss -0x118(%rbp), %xmm3
movss -0x114(%rbp), %xmm4
movss -0x110(%rbp), %xmm5
xorps %xmm6, %xmm6
movss 0x2d6c1(%rip), %xmm7    # 0x760b0
callq 0x5cf00
movq -0x158(%rbp), %rax
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
movq -0x160(%rbp), %rcx
movq -0x140(%rbp), %r8
movss %xmm0, -0x11c(%rbp)
movss -0x11c(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %ebx
movq 0x40(%rbp), %r14
subq $0x50, %rsp
movups (%rax), %xmm2
movups 0x10(%rax), %xmm3
movups 0x20(%rax), %xmm4
movq %rsp, %rax
movups %xmm4, 0x38(%rax)
movups %xmm3, 0x28(%rax)
movups %xmm2, 0x18(%rax)
movq %r14, 0x48(%rax)
movl %ebx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0x48c80
addq $0x50, %rsp
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x134(%rbp)
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x108(%rbp)
movss -0x134(%rbp), %xmm0
movss %xmm0, -0x114(%rbp)
movq -0xb8(%rbp), %rdi
movss -0x108(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x114(%rbp), %xmm1
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x384ea(%rip), %rsi     # 0x80fd0
movb $0x2, %al
callq 0x1150
movss -0x134(%rbp), %xmm0
ucomiss -0x128(%rbp), %xmm0
jbe 0x48b59
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x12c(%rbp)
movss -0x128(%rbp), %xmm0
subss -0x134(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movaps 0x33967(%rip), %xmm0    # 0x7c490
pand %xmm0, %xmm1
movsd 0x338eb(%rip), %xmm0    # 0x7c420
ucomisd %xmm1, %xmm0
jbe 0x48b3d
jmp 0x48b7e
movss -0x134(%rbp), %xmm0
movss %xmm0, -0x128(%rbp)
movl $0x0, -0x124(%rbp)
jmp 0x48b68
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x48b6a
movl -0x130(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x130(%rbp)
jmp 0x48835
movq -0x140(%rbp), %r8
movq -0x160(%rbp), %rcx
movq -0x168(%rbp), %rdx
movq -0x170(%rbp), %rsi
movq -0x178(%rbp), %rdi
movq -0x158(%rbp), %rax
movss -0x12c(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %r10
movq -0x30(%rbp), %r11
movl -0x34(%rbp), %ebx
movq 0x40(%rbp), %r14
subq $0x50, %rsp
movups (%rax), %xmm2
movups 0x10(%rax), %xmm3
movups 0x20(%rax), %xmm4
movq %rsp, %rax
movups %xmm4, 0x38(%rax)
movups %xmm3, 0x28(%rax)
movups %xmm2, 0x18(%rax)
movq %r14, 0x48(%rax)
movl %ebx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0x48c80
addq $0x50, %rsp
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x48c55
movq -0x170(%rbp), %rax
movslq -0xdc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xdc(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x48c0a
movq -0xb8(%rbp), %rdi
callq 0x10a0
movq -0xc0(%rbp), %rax
movq %rax, %rsp
xorl %eax, %eax
leaq -0x10(%rbp), %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)