// File: /workspace/github_c_makefile_star2_O0/radforddc[P]icpc_siggen/icpc_fieldgen_opt.c
// Function: interpolate
int interpolate(MJD_Siggen_Setup *setup, MJD_Siggen_Setup *old_setup) {
  int    n, i, j, i2, j2, zmin, rmin, zmax, rmax;
  int    L  = lrint(old_setup->xtal_length/old_setup->xtal_grid)+3;
  int    R  = lrint(old_setup->xtal_radius/old_setup->xtal_grid)+3;
  int    L2 = lrint(setup->xtal_length/setup->xtal_grid)+3;
  int    R2 = lrint(setup->xtal_radius/setup->xtal_grid)+3;
  float  f, f1r, f1z, f2r, f2z;
  double ***v = setup->v, **ov = old_setup->v[1];

  /* the previous calculation was on a coarser grid...
     now copy/expand the potential to the new finer grid
  */
  n = (int) (old_setup->xtal_grid / setup->xtal_grid + 0.5);
  f = 1.0 / (float) n;
  printf("\ngrid %.4f -> %.4f; ratio = %d %.3f\n\n",
         old_setup->xtal_grid, setup->xtal_grid, n, f);
  for (i = i2 = 1; i < L-1; i++) {
    zmin = i2;
    zmax = i2 + n;
    if (zmax > L2-1) zmax = L2-1;
    for (j = j2 = 1; j < R-1; j++) {
      f1z = 0.0;
      rmin = j2;
      rmax = j2 + n;
      if (rmax > R2-1) rmax = R2-1;
      for (i2 = zmin; i2 < zmax; i2++) {
        f2z = 1.0 - f1z;
        f1r = 0.0;
        for (j2 = rmin; j2 < rmax; j2++) {
          f2r = 1.0 - f1r;
          v[0][i2][j2] = v[1][i2][j2] =      // linear interpolation
            f2z*f2r*ov[i][j  ] + f1z*f2r*ov[i+1][j  ] +
            f2z*f1r*ov[i][j+1] + f1z*f1r*ov[i+1][j+1];
          f1r += f;
        }
        f1z += f;
      }
      j2 = rmax;
    }
    i2 = zmax;
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x10(%rbp), %rax
divss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
addq $0x3, %rax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
divss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
addq $0x3, %rax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
divss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
addq $0x3, %rax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x8(%rbp), %rax
divss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10f0
addq $0x3, %rax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
addq $0x3e0, %rax            # imm = 0x3E0
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x3e8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movss 0x54(%rax), %xmm0
movq -0x8(%rbp), %rax
divss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x6685(%rip), %xmm1     # 0xd088
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x14(%rbp)
cvtsi2ssl -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6649(%rip), %xmm0     # 0xd068
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x8(%rbp), %rax
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movl -0x14(%rbp), %esi
movss -0x48(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x72a3(%rip), %rdi      # 0xdcfc
movb $0x3, %al
callq 0x10e0
movl $0x1, -0x20(%rbp)
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6ca3
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x6aa4
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6c8f
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x6af0
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x6c7b
movss -0x50(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6555(%rip), %xmm0     # 0xd068
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x6c5e
movss -0x4c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x651d(%rip), %xmm0     # 0xd068
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x58(%rbp), %xmm0
mulss -0x54(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x68(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movss -0x50(%rbp), %xmm1
mulss -0x54(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x68(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss -0x58(%rbp), %xmm1
mulss -0x4c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x68(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss -0x50(%rbp), %xmm0
mulss -0x4c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x68(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movss -0x48(%rbp), %xmm0
addss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6b2e
movss -0x48(%rbp), %xmm0
addss -0x50(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x6af6
movl -0x34(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6ab2
movl -0x30(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x6a6e
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)