// File: /workspace/github_c_makefile_star2_O1/radforddc[P]icpc_siggen/icpc_fieldgen_opt.c
// Function: do_relax
int do_relax(MJD_Siggen_Setup *setup, int ev_calc) {
  int    old = 1, new = 0, iter, r, z;
  float  grid = setup->xtal_grid;
  int    L  = lrint(setup->xtal_length/grid)+2;
  int    R  = lrint(setup->xtal_radius/grid)+2;
  double eps_sum, v_sum, dif, sum_dif=0, max_dif;
  double ***v = setup->v, **eps_dr = setup->eps_dr, **eps_dz = setup->eps_dz;
  double ***dr = setup->dr, ***dz = setup->dz;
  double *s1 = setup->s1, *s2 = setup->s2;
  double e_over_E = 11.310; // e/epsilon; for 1 mm2, charge units 1e10 e/cm3, espilon = 16*epsilon0


  if (ev_calc) {
    // for field calculation, save impurity value along passivated surface
    for (r = 1; r < R; r++)
      setup->impurity[0][r] = setup->impurity[1][r];
  } else {
    // for WP calculation, clear all impurity values
    for (z = 0; z < L; z++) {
      for (r = 1; r < R; r++) {
        setup->impurity[z][r] = 0;
      }
    }
  }

  for (iter = 0; iter < setup->max_iterations; iter++) {

    /* the following definition of the factor for over-relaxation improves convergence
           time by a factor ~ 70-120 for a 2kg ICPC detector, grid = 0.1 mm
         OR_fact increases with increasing volxel count (L*R)
               and with increasing iteration number
         0.997 is maximum asymptote for very large pixel count and iteration number */
    double OR_fact;
    if (ev_calc)  OR_fact = (1.991 - 1500.0/(L*R));
    else          OR_fact = (1.992 - 1500.0/(L*R));
    if (OR_fact < 1.4) OR_fact = 1.4;
    // if (iter == 0) printf("OR_fact = %f\n", OR_fact);
    if (iter < 1) OR_fact = 1.0;

    old = new;
    new = 1 - new;
    sum_dif = 0;
    max_dif = 0;

    if (setup->vacuum_gap > 0) {   // modify impurity value along passivated surface
      for (r = 1; r < R; r++)      //   due to surface charge induced by capacitance
        setup->impurity[1][r] = setup->impurity[0][r] -
          v[old][1][r] * 5.52e-4 * e_over_E * grid / setup->vacuum_gap;
    }

    /* start from z=1 and r=1 so that (z,r)=0 can be
       used for reflection symmetry around r=0 or z=0 */
    for (z = 1; z < L; z++) {
      /* manage r=0 reflection symmetry */
      setup->v[old][z][0] = setup->v[new][z][0] = setup->v[old][z][2];

      for (r = 1; r < R; r++) {
        if (setup->point_type[z][r] < INSIDE) continue;   // HV or point contact

        if (setup->point_type[z][r] < DITCH) {       // normal bulk or passivated surface, no complications
          v_sum = (v[old][z+1][r] + v[old][z][r+1]*s1[r] +
                   v[new][z-1][r] + v[new][z][r-1]*s2[r]);
          if (r > 1) eps_sum = 4;
          else       eps_sum = 2 + s1[r] + s2[r];
        } else if (setup->point_type[z][r] == CONTACT_EDGE) {  // adjacent to the contact
          v_sum = (v[old][z+1][r]*dz[1][z][r] + v[old][z][r+1]*dr[1][z][r] +
                   v[new][z-1][r]*dz[0][z][r] + v[new][z][r-1]*dr[0][z][r]);
          eps_sum = dz[1][z][r] + dr[1][z][r] + dz[0][z][r] + dr[0][z][r];
        } else if (setup->point_type[z][r] >= DITCH) {  // in or adjacent to the ditch
          v_sum = (v[old][z+1][r]*eps_dz[z  ][r] + v[old][z][r+1]*eps_dr[z][r  ]*s1[r] +
                   v[new][z-1][r]*eps_dz[z-1][r] + v[new][z][r-1]*eps_dr[z][r-1]*s2[r]);
          eps_sum = (eps_dz[z][r]   + eps_dr[z][r]  *s1[r] +
                     eps_dz[z-1][r] + eps_dr[z][r-1]*s2[r]);
        }

        // calculate the interpolated mean potential and the effect of the space charge

        if ((ev_calc || (setup->vacuum_gap > 0 && z == 1)) &&
            setup->point_type[z][r] < CONTACT_EDGE && r > 1 && z > 1) {   // normal bulk, no complications
          v[new][z][r] = (1.0-OR_fact)*v[old][z][r] + OR_fact * (v_sum / eps_sum + setup->impurity[z][r]);
        } else if (ev_calc || (setup->vacuum_gap > 0 && z == 1)) {
          v[new][z][r] = v_sum / eps_sum + setup->impurity[z][r];
        } else if (setup->point_type[z][r] < CONTACT_EDGE && r > 1 && z > 1) {   // normal bulk, no complications
          v[new][z][r] = (1.0-OR_fact)*v[old][z][r] + OR_fact * v_sum / eps_sum;
        } else {                          // over-relaxation at the edges seems to make things worse
          v[new][z][r] = v_sum / eps_sum;
        }

        // calculate difference from last iteration, for convergence check
        dif = fabs(v[old][z][r] - v[new][z][r]);
        sum_dif += dif;
        if (max_dif < dif) max_dif = dif;
      }
    }

    // report results for some iterations
    if (iter < 10 || (iter < 600 && iter%100 == 0) || iter%1000 == 0) {
      if (0 && ev_calc) {
        printf("%5d %d %d %.10f %.10f\n", iter, old, new, max_dif, sum_dif/(L-2)/(R-2));
      } else {
        printf("%5d %d %d %.10f %.10f ; %.10f %.10f\n",
               iter, old, new, max_dif, sum_dif/(L-2)/(R-2),
               v[new][L/2][R/2], v[new][L/3][R/3]);
      }
    }
    // check for convergence
    if ( ev_calc && max_dif < 0.00000008) break;
    if ( ev_calc && max_dif < 0.0008) break;  // comment out if you want convergence at the numerical error level
    if (!ev_calc && max_dif < 0.0000000001) break;
    if (!ev_calc && max_dif < 0.000001) break;  // comment out if you want convergence at the numerical error level

    /* every 100 iterations, check that detector is really depleted*/
    if (ev_calc && iter > 190 && iter%100 == 0) {
      for (z = 1; z < L; z++) {
        setup->v[old][z][0] = setup->v[old][z][2];
        for (r = 1; r < R; r++) {
          if (setup->point_type[z][r] < INSIDE) continue;   // HV or point contact
          if (v[new][z][r] < 0 ||
              (v[new][z][r] < v[new][z][r] &&
               v[new][z][r] < v[new][z][r] &&
               v[new][z][r] < v[new][z][r] &&
               v[new][z][r] < v[new][z][r])) {
            printf("Detector may not be fully depleted. Switching to ev_relax_undep()\n");
            ev_relax_undep(setup);
            return 0;
          }
        }
      }

    }
  }

  printf(">> %d %.16f\n\n", iter, sum_dif);
  if (setup->vacuum_gap > 0) {   // restore impurity value along passivated surface
    for (r = 1; r < R; r++)
      setup->impurity[1][r] = setup->impurity[0][r];
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movss 0x4(%rdi), %xmm0
movss 0x54(%rdi), %xmm1
movss %xmm1, 0x30(%rsp)
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
movq %rax, 0x48(%rsp)
leal 0x2(%rax), %r15d
movss 0x8(%rbx), %xmm0
divss 0x30(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1100
leal 0x2(%rax), %edx
movq 0x3f8(%rbx), %rcx
movq %rcx, 0xa0(%rsp)
movq 0x400(%rbx), %rcx
movq %rcx, 0x98(%rsp)
movq 0x418(%rbx), %r12
movq 0x420(%rbx), %r14
movl %edx, 0x14(%rsp)
movl %edx, %r13d
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
movq %rax, 0x20(%rsp)
movl %r15d, 0x50(%rsp)
je 0x6528
cmpl $0x7ffffffd, %eax       # imm = 0x7FFFFFFD
ja 0x657d
movq 0x408(%rbx), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rcx
movl $0x1, %edx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %r13
jne 0x6514
jmp 0x657d
testl %r15d, %r15d
jle 0x657d
leaq 0x8(,%rax,8), %rcx
movabsq $0x7fffffff8, %rdx      # imm = 0x7FFFFFFF8
andq %rcx, %rdx
movq %rdx, 0x28(%rsp)
movl 0x50(%rsp), %ebp
xorl %r15d, %r15d
cmpl $0x7ffffffd, %eax       # imm = 0x7FFFFFFD
ja 0x6575
movq 0x408(%rbx), %rax
movq (%rax,%r15,8), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movq 0x28(%rsp), %rdx
callq 0x1110
movq 0x20(%rsp), %rax
incq %r15
cmpq %r15, %rbp
jne 0x654e
cmpl $0x0, 0x78(%rbx)
jle 0x6da1
xorl %esi, %esi
cmpl $0x0, 0xc(%rsp)
setne %sil
movl 0x14(%rsp), %edi
movl %edi, %ecx
movl 0x50(%rsp), %r8d
imull %r8d, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x2b38(%rip), %xmm0     # 0x90e8
divsd %xmm1, %xmm0
cvtss2sd 0x30(%rsp), %xmm11
xorps %xmm1, %xmm1
cvtsi2sdl 0x48(%rsp), %xmm1
movsd %xmm1, 0x90(%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x88(%rsp)
movl %r8d, %ecx
shrl $0x1f, %ecx
addl %r8d, %ecx
sarl %ecx
movslq %ecx, %rcx
movq %rcx, 0x80(%rsp)
movl %edi, %ecx
shrl $0x1f, %ecx
addl %edi, %ecx
sarl %ecx
movslq %ecx, %rcx
movq %rcx, 0x78(%rsp)
movslq %r8d, %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movslq %ecx, %rcx
movq %rcx, 0x70(%rsp)
movslq %edi, %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leaq 0x2b1f(%rip), %rdx      # 0x9160
addsd (%rdx,%rsi,8), %xmm0
movslq %ecx, %rcx
movq %rcx, 0x68(%rsp)
movsd 0x2a9a(%rip), %xmm1     # 0x90f0
maxsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movl %r8d, %ecx
movq %rcx, 0x28(%rsp)
xorl %edi, %edi
movsd 0x2a4e(%rip), %xmm4     # 0x90c0
movsd 0x2a1e(%rip), %xmm5     # 0x9098
movsd 0x2a45(%rip), %xmm13    # 0x90c8
movsd 0x2a44(%rip), %xmm14    # 0x90d0
movapd 0x2abb(%rip), %xmm15    # 0x9150
xorl %esi, %esi
movsd %xmm11, 0x40(%rsp)
movsd 0x29b2(%rip), %xmm1     # 0x9058
testl %esi, %esi
je 0x66b0
movsd 0x60(%rsp), %xmm1
movl %esi, 0x1c(%rsp)
movss 0x50(%rbx), %xmm0
movss %xmm0, 0x14(%rsp)
ucomiss 0x2a5a(%rip), %xmm0     # 0x9120
jbe 0x6721
cmpl $0x7ffffffd, %eax       # imm = 0x7FFFFFFD
ja 0x6721
movq 0x408(%rbx), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movl %edi, %edx
movq 0x3e0(%rbx,%rdx,8), %rdx
movq 0x8(%rdx), %rdx
xorps %xmm2, %xmm2
cvtss2sd 0x14(%rsp), %xmm2
movl $0x1, %esi
movsd (%rdx,%rsi,8), %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm11, %xmm3
divsd %xmm2, %xmm3
addsd (%rax,%rsi,8), %xmm3
movsd %xmm3, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %r13
jne 0x66f9
movl $0x1, %eax
movl %edi, 0x18(%rsp)
subl %edi, %eax
movl %eax, 0x10(%rsp)
xorpd %xmm12, %xmm12
xorps %xmm0, %xmm0
cmpl $0x7ffffffd, 0x48(%rsp) # imm = 0x7FFFFFFD
ja 0x6ade
movl 0x18(%rsp), %eax
movq 0x3e0(%rbx,%rax,8), %rcx
movq %rcx, 0x30(%rsp)
movl 0x10(%rsp), %edx
movq 0x3e0(%rbx,%rdx,8), %rcx
movq %rcx, 0x50(%rsp)
movsd 0x28e8(%rip), %xmm2     # 0x9058
subsd %xmm1, %xmm2
movl $0x1, %edi
movq 0x30(%rsp), %rcx
movq (%rcx,%rdi,8), %r8
movsd 0x10(%r8), %xmm3
movq 0x50(%rsp), %rcx
movq (%rcx,%rdi,8), %r9
movsd %xmm3, (%r9)
movsd %xmm3, (%r8)
cmpl $0x7ffffffd, 0x20(%rsp) # imm = 0x7FFFFFFD
ja 0x6ad0
movss 0x14(%rsp), %xmm3
ucomiss 0x296a(%rip), %xmm3     # 0x9120
seta %r10b
cmpl $0x0, 0xc(%rsp)
setne %r11b
movq 0x430(%rbx), %r8
movq (%r8,%rdi,8), %r8
cmpq $0x1, %rdi
sete %r9b
andb %r10b, %r9b
orb %r11b, %r9b
movl $0x1, %r10d
movb (%r8,%r10), %r11b
cmpb $0x2, %r11b
jl 0x6ac4
cmpb $0x4, %r11b
jg 0x685e
movq 0x3e0(%rbx,%rax,8), %r15
movq (%r15,%rdi,8), %rcx
movq 0x8(%r15,%rdi,8), %r15
movsd (%r12,%r10,8), %xmm3
movsd 0x8(%rcx,%r10,8), %xmm6
mulsd %xmm3, %xmm6
addsd (%r15,%r10,8), %xmm6
movq 0x3e0(%rbx,%rdx,8), %rcx
movq -0x8(%rcx,%rdi,8), %r15
movq (%rcx,%rdi,8), %rcx
addsd (%r15,%r10,8), %xmm6
movsd (%r14,%r10,8), %xmm5
movsd -0x8(%rcx,%r10,8), %xmm4
mulsd %xmm5, %xmm4
addsd %xmm6, %xmm4
cmpq $0x1, %r10
jbe 0x691a
movapd %xmm13, %xmm3
jmp 0x69e6
cmpb $0x7, %r11b
jne 0x6924
movq 0x3e0(%rbx,%rax,8), %rcx
movq (%rcx,%rdi,8), %r15
movq 0x8(%rcx,%rdi,8), %rcx
movq 0x1468(%rbx), %rsi
movq (%rsi,%rdi,8), %rsi
movsd (%rsi,%r10,8), %xmm3
movq 0x1450(%rbx), %rsi
movq 0x1458(%rbx), %rbp
movq (%rbp,%rdi,8), %rbp
movsd (%rbp,%r10,8), %xmm5
movsd 0x8(%r15,%r10,8), %xmm4
mulsd %xmm5, %xmm4
movsd (%rcx,%r10,8), %xmm6
mulsd %xmm3, %xmm6
addsd %xmm4, %xmm6
movq 0x3e0(%rbx,%rdx,8), %rcx
movq 0x1460(%rbx), %r15
movq (%r15,%rdi,8), %r15
movsd (%r15,%r10,8), %xmm7
movq -0x8(%rcx,%rdi,8), %r15
movq (%rcx,%rdi,8), %rcx
movsd (%r15,%r10,8), %xmm8
mulsd %xmm7, %xmm8
addsd %xmm6, %xmm8
movq (%rsi,%rdi,8), %rsi
movsd (%rsi,%r10,8), %xmm6
movsd -0x8(%rcx,%r10,8), %xmm4
mulsd %xmm6, %xmm4
addsd %xmm8, %xmm4
addsd %xmm5, %xmm3
addsd %xmm7, %xmm3
addsd %xmm6, %xmm3
jmp 0x69e6
addsd %xmm14, %xmm3
jmp 0x69e2
movq 0x3e0(%rbx,%rax,8), %rcx
movq (%rcx,%rdi,8), %rsi
movq 0x8(%rcx,%rdi,8), %rcx
movq 0x98(%rsp), %rbp
movq -0x8(%rbp,%rdi,8), %r15
movq (%rbp,%rdi,8), %rbp
movsd (%rbp,%r10,8), %xmm6
movq 0xa0(%rsp), %rbp
movq (%rbp,%rdi,8), %rbp
movsd -0x8(%rbp,%r10,8), %xmm3
movsd (%rbp,%r10,8), %xmm5
movsd 0x8(%rsi,%r10,8), %xmm4
mulsd %xmm5, %xmm4
movsd (%r12,%r10,8), %xmm7
mulsd %xmm7, %xmm4
movsd (%rcx,%r10,8), %xmm8
mulsd %xmm6, %xmm8
addsd %xmm4, %xmm8
movq 0x3e0(%rbx,%rdx,8), %rcx
movsd (%r15,%r10,8), %xmm9
movq -0x8(%rcx,%rdi,8), %rsi
movq (%rcx,%rdi,8), %rcx
movsd (%rsi,%r10,8), %xmm10
mulsd %xmm9, %xmm10
addsd %xmm8, %xmm10
movsd -0x8(%rcx,%r10,8), %xmm4
mulsd %xmm3, %xmm4
movsd (%r14,%r10,8), %xmm8
mulsd %xmm8, %xmm4
addsd %xmm10, %xmm4
mulsd %xmm7, %xmm5
addsd %xmm6, %xmm5
addsd %xmm9, %xmm5
mulsd %xmm8, %xmm3
addsd %xmm5, %xmm3
testb %r9b, %r9b
je 0x6a24
cmpq $0x2, %rdi
jb 0x6a24
cmpq $0x2, %r10
jb 0x6a24
cmpb $0x6, %r11b
jg 0x6a24
movq 0x3e0(%rbx,%rax,8), %rcx
movq (%rcx,%rdi,8), %rcx
divsd %xmm3, %xmm4
movq 0x408(%rbx), %rsi
movq (%rsi,%rdi,8), %rsi
addsd (%rsi,%r10,8), %xmm4
mulsd %xmm1, %xmm4
jmp 0x6a66
testb %r9b, %r9b
je 0x6a40
divsd %xmm3, %xmm4
movq 0x408(%rbx), %rcx
movq (%rcx,%rdi,8), %rcx
addsd (%rcx,%r10,8), %xmm4
jmp 0x6a7a
cmpq $0x2, %rdi
jb 0x6a76
cmpq $0x2, %r10
jb 0x6a76
cmpb $0x6, %r11b
jg 0x6a76
movq 0x3e0(%rbx,%rax,8), %rcx
movq (%rcx,%rdi,8), %rcx
mulsd %xmm1, %xmm4
divsd %xmm3, %xmm4
movsd (%rcx,%r10,8), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm3, %xmm4
jmp 0x6a7a
divsd %xmm3, %xmm4
movq 0x3e0(%rbx,%rdx,8), %rcx
movq (%rcx,%rdi,8), %rcx
movsd %xmm4, (%rcx,%r10,8)
movq 0x3e0(%rbx,%rax,8), %rcx
movq (%rcx,%rdi,8), %rcx
movsd (%rcx,%r10,8), %xmm3
movq 0x3e0(%rbx,%rdx,8), %rcx
movq (%rcx,%rdi,8), %rcx
subsd (%rcx,%r10,8), %xmm3
andpd %xmm15, %xmm3
addsd %xmm3, %xmm12
ucomisd %xmm0, %xmm3
jbe 0x6ac4
movapd %xmm3, %xmm0
incq %r10
cmpq %r10, %r13
jne 0x67e2
incq %rdi
cmpq 0x28(%rsp), %rdi
jne 0x6779
movl 0x1c(%rsp), %esi
cmpl $0xa, %esi
jae 0x6b89
movapd %xmm12, %xmm1
divsd 0x90(%rsp), %xmm1
divsd 0x88(%rsp), %xmm1
movl 0x10(%rsp), %r8d
movl %r8d, %eax
movq 0x3e0(%rbx,%rax,8), %rax
movq 0x80(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x78(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm2
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm3
leaq 0x319d(%rip), %rdi      # 0x9cdf
movl 0x18(%rsp), %edx
movl %r8d, %ecx
movb $0x4, %al
movapd %xmm12, 0x30(%rsp)
movaps %xmm0, 0x50(%rsp)
callq 0x10f0
movaps 0x50(%rsp), %xmm0
movapd 0x30(%rsp), %xmm12
movapd 0x25df(%rip), %xmm15    # 0x9150
movsd 0x2556(%rip), %xmm14    # 0x90d0
movsd 0x2545(%rip), %xmm13    # 0x90c8
movl 0x1c(%rsp), %esi
jmp 0x6bc1
cmpl $0x258, %esi            # imm = 0x258
setb %al
imull $0xc28f5c29, %esi, %ecx # imm = 0xC28F5C29
rorl $0x2, %ecx
cmpl $0x28f5c29, %ecx        # imm = 0x28F5C29
setb %cl
imull $0x26e978d5, %esi, %edx # imm = 0x26E978D5
rorl $0x3, %edx
cmpl $0x418938, %edx         # imm = 0x418938
jb 0x6aeb
andb %cl, %al
jne 0x6aeb
movl $0xb, %r10d
cmpl $0x0, 0xc(%rsp)
je 0x6c1e
movapd %xmm0, %xmm3
movsd 0x251e(%rip), %xmm1     # 0x90f8
cmpltpd %xmm1, %xmm3
movapd %xmm0, %xmm1
movsd 0x24f5(%rip), %xmm2     # 0x90e0
cmpltpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movd %xmm1, %ecx
testb $0x1, %cl
je 0x6c1e
movq 0x20(%rsp), %rax
movsd 0x40(%rsp), %xmm11
movsd 0x24af(%rip), %xmm4     # 0x90c0
movsd 0x247f(%rip), %xmm5     # 0x9098
jmp 0x6d83
cmpl $0x0, 0xc(%rsp)
movq 0x20(%rsp), %rax
movsd 0x40(%rsp), %xmm11
movsd 0x2489(%rip), %xmm4     # 0x90c0
movsd 0x2459(%rip), %xmm5     # 0x9098
jne 0x6c70
movapd %xmm0, %xmm2
movsd 0x24b3(%rip), %xmm1     # 0x9100
cmpltpd %xmm1, %xmm2
movsd 0x247e(%rip), %xmm1     # 0x90d8
cmpltpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movd %xmm0, %ecx
testb $0x1, %cl
jne 0x6d83
xorl %r10d, %r10d
cmpl $0x0, 0xc(%rsp)
je 0x6d83
cmpl $0xbf, %esi
jb 0x6d83
movl %esi, %ecx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
shrq $0x25, %rcx
imull $0x64, %ecx, %ecx
movl %esi, %edx
subl %ecx, %edx
jne 0x6d83
cmpl $0x7ffffffd, 0x48(%rsp) # imm = 0x7FFFFFFD
ja 0x6d83
movl 0x18(%rsp), %ecx
movq 0x3e0(%rbx,%rcx,8), %rcx
movl 0x10(%rsp), %edx
movl $0x1, %r11d
xorpd %xmm1, %xmm1
movq (%rcx,%r11,8), %rdi
movsd 0x10(%rdi), %xmm0
movsd %xmm0, (%rdi)
cmpl $0x7ffffffd, %eax       # imm = 0x7FFFFFFD
ja 0x6d14
movq 0x430(%rbx), %rdi
movq (%rdi,%r11,8), %rdi
movl $0x1, %r8d
cmpb $0x2, (%rdi,%r8)
jl 0x6d0c
movq 0x3e0(%rbx,%rdx,8), %r9
movq (%r9,%r11,8), %r9
ucomisd (%r9,%r8,8), %xmm1
ja 0x6d20
incq %r8
cmpq %r8, %r13
jne 0x6cf1
incq %r11
cmpq 0x28(%rsp), %r11
jne 0x6ccc
jmp 0x6d83
leaq 0x33e6(%rip), %rdi      # 0xa10d
movapd %xmm12, 0x30(%rsp)
callq 0x1070
movq %rbx, %rdi
callq 0x5a9a
movapd 0x30(%rsp), %xmm12
movapd 0x2405(%rip), %xmm15    # 0x9150
movsd 0x237c(%rip), %xmm14    # 0x90d0
movsd 0x236b(%rip), %xmm13    # 0x90c8
movsd 0x2333(%rip), %xmm5     # 0x9098
movsd 0x2353(%rip), %xmm4     # 0x90c0
movl 0x1c(%rsp), %esi
movsd 0x40(%rsp), %xmm11
movq 0x20(%rsp), %rax
movl $0x1, %r10d
testl %r10d, %r10d
jne 0x6d99
incl %esi
movl 0x10(%rsp), %edi
cmpl 0x78(%rbx), %esi
jl 0x669e
jmp 0x6da8
cmpl $0xb, %r10d
je 0x6da8
jmp 0x6dfa
xorpd %xmm12, %xmm12
xorl %esi, %esi
leaq 0x2f22(%rip), %rdi      # 0x9cd1
movapd %xmm12, %xmm0
movb $0x1, %al
callq 0x10f0
movq 0x20(%rsp), %rax
movss 0x50(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x6dfa
cmpl $0x7ffffffd, %eax       # imm = 0x7FFFFFFD
ja 0x6dfa
movq 0x408(%rbx), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movl $0x1, %edx
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %r13
jne 0x6de8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq