// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::Voronoi(gaps::R3Grid*)
void R3Grid::
Voronoi(R3Grid *squared_distance_grid)
{
  int dist;
  int* old_dist;
  int* new_dist;
  RNScalar value;
  RNScalar *old_value;
  RNScalar *new_value;
  R3Grid *dgrid;
  int res,square,tmp_dist,first;
  int x,y,z,s,t,i;

  // Allocate distance grid
  if (squared_distance_grid) dgrid = squared_distance_grid;
  else dgrid = new R3Grid(XResolution(), YResolution(), ZResolution());
  assert(dgrid);
  dgrid->SetWorldToGridTransformation(WorldToGridTransformation());

  // Allocate temporary buffers
  res = XResolution();
  if (res < YResolution()) res = YResolution();
  if (res < ZResolution()) res = ZResolution();
  old_dist = new int[res];
  new_dist = new int[res];
  old_value = new RNScalar[res];
  new_value = new RNScalar[res];
  assert(old_dist && new_dist && old_value && new_value);

  // Initalize distance grid values (0 if was set, max_value if not)
  RNScalar max_value = 3 * (res+1) * (res+1) * (res+1);
  for (i = 0; i < grid_size; i++) {
    if (grid_values[i] == 0.0) dgrid->grid_values[i] = max_value;
    else dgrid->grid_values[i] = 0.0;
  }

  // Scan along z axis
  for (x = 0; x < XResolution(); x++) {
    for (y = 0; y < YResolution(); y++) {
      first = 1;
      value = 0;
      dist = 0;
      for (z = 0; z < ZResolution(); z++) {
        if (dgrid->GridValue(x,y,z) == 0.0) {
          first=0;
          dist=0;
          value = GridValue(x,y,z);
          assert(value != 0);
        }
        else if (first == 0) {
          dist++;
          square = dist*dist;
          dgrid->SetGridValue(x, y, z, square);
          SetGridValue(x, y, z, value);
          assert(value != 0);
        }
      }
			
      // backward scan
      dist = 0;
      first = 1;
      for (z = ZResolution()-1; z >= 0; z--) {
        if (dgrid->GridValue(x,y,z) == 0.0){
          dist = 0;
          first = 0;
          value = GridValue(x,y,z);
          assert(value != 0);
        }
        else if (first == 0) {
          dist++;
          square = dist*dist;
          if (square < dgrid->GridValue(x, y, z)) {
            dgrid->SetGridValue(x, y, z, square);
            SetGridValue(x, y, z, value);
            assert(value != 0);
          }
        }
      }
    }
  } 

  // Scan along x axis
  for (z = 0; z < ZResolution(); z++) {
    for (y = 0; y < YResolution(); y++) {
      // Copy grid values
      for(x = 0; x < XResolution(); x++) {
        old_dist[x] = (int) (dgrid->GridValue(x, y, z) + 0.5);
        old_value[x] = GridValue(x, y, z);
      }
		
      // forward scan
      s = 0;
      for (x = 0; x < XResolution(); x++) {
        dist = old_dist[x];
        value = old_value[x];
        if (dist) {
          for(t = s; t <= x; t++) {
            tmp_dist = old_dist[t] + (x - t) * (x - t);
            if (tmp_dist <= dist) {
              dist = tmp_dist;
              value = old_value[t];
              s = t;
            }
          }
        }
        else {
          s = x;
        }
        new_dist[x] = dist;
        new_value[x] = value;
      }
			
      // backwards scan
      s = XResolution() - 1;
      for (x = XResolution()-1; x >= 0 ; x--) {
        dist = new_dist[x];
        value = new_value[x];
        if (dist) {
          for (t = s; t >= x; t--) {
            tmp_dist = old_dist[t] + (x - t) * (x - t);
            if (tmp_dist <= dist) {
              dist = tmp_dist;
              value = old_value[t];
              s = t;
            }
          }
          dgrid->SetGridValue(x, y, z, dist);
          SetGridValue(x, y, z, value);
        }
        else {
          s=x;
        }
      }
    }
  }
		
  // along y axis
  for (z = 0; z < ZResolution(); z++) {
    for (x = 0; x < XResolution(); x++) {
      // Copy grid values
      for (y = 0; y < YResolution(); y++) {
        old_dist[y] = (int) (dgrid->GridValue(x, y, z));
        old_value[y] = GridValue(x, y, z);
      }
			
      // forward scan
      s = 0;
      for (y = 0; y < YResolution(); y++) {
        dist = old_dist[y];
        value = old_value[y];
        if (dist) {
          for (t = s; t <= y ; t++) {
            tmp_dist = old_dist[t] + (y - t) * (y - t);
            if (tmp_dist <= dist){
              dist = tmp_dist;
              value = old_value[t];
              s = t;
            }
          }
        }
        else { 
          s = y;
        }
        new_dist[y] = dist;
        new_value[y] = value;
      }

      // backward scan
      s = YResolution() - 1;
      for(y = YResolution()-1; y >=0 ; y--) {
        dist = new_dist[y];
        value = new_value[y];
        if (dist) {
          for (t = s; t > y ; t--) {
            tmp_dist = old_dist[t] + (y - t) * (y - t);
            if (tmp_dist <= dist){
              dist = tmp_dist;
              value = old_value[t];
              s = t;
            }
          }
          dgrid->SetGridValue(x, y, z, dist);
          SetGridValue(x, y, z, value);
        }
        else { 
          s = y; 
        }
      }
    }
  }
	
  // Delete temporary buffers
  if (!squared_distance_grid) delete dgrid;
  delete[] old_dist;
  delete[] new_dist;
  delete[] old_value;
  delete[] new_value;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x108(%rsp)
je 0x5d397
movq 0x108(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x5d434
movl $0x250, %edi            # imm = 0x250
callq 0xf4c0
movq 0x88(%rsp), %rdi
movq %rax, 0x78(%rsp)
callq 0x138c0
movl %eax, 0x84(%rsp)
jmp 0x5d3bc
movq 0x88(%rsp), %rdi
callq 0x138e0
movl %eax, 0x74(%rsp)
jmp 0x5d3cf
movq 0x88(%rsp), %rdi
callq 0x13900
movl %eax, 0x70(%rsp)
jmp 0x5d3e2
movl 0x70(%rsp), %ecx
movl 0x74(%rsp), %edx
movl 0x84(%rsp), %esi
movq 0x78(%rsp), %rdi
callq 0x55680
jmp 0x5d3fd
movq 0x78(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x5d434
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
movl $0x250, %esi            # imm = 0x250
callq 0xf4d0
jmp 0x5e416
movq 0x88(%rsp), %rdi
movq 0xd0(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0x6bd10
movq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0x5e430
movq 0x88(%rsp), %rdi
callq 0x138c0
movq 0x88(%rsp), %rdi
movl %eax, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
movl %eax, 0x6c(%rsp)
callq 0x138e0
movl %eax, %ecx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5d4a5
movq 0x88(%rsp), %rdi
callq 0x138e0
movl %eax, 0xcc(%rsp)
movq 0x88(%rsp), %rdi
movl 0xcc(%rsp), %eax
movl %eax, 0x5c(%rsp)
callq 0x13900
movl %eax, %ecx
movl 0x5c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5d4db
movq 0x88(%rsp), %rdi
callq 0x13900
movl %eax, 0xcc(%rsp)
movslq 0xcc(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, 0xf8(%rsp)
movslq 0xcc(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, 0xf0(%rsp)
movslq 0xcc(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, 0xe0(%rsp)
movslq 0xcc(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, 0xd8(%rsp)
movl 0xcc(%rsp), %eax
addl $0x1, %eax
imull $0x3, %eax, %eax
movl 0xcc(%rsp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl 0xcc(%rsp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x90(%rsp)
movl $0x0, 0xa8(%rsp)
movq 0x88(%rsp), %rcx
movl 0xa8(%rsp), %eax
cmpl 0x24c(%rcx), %eax
jge 0x5d67e
movq 0x88(%rsp), %rax
movq 0x230(%rax), %rax
movslq 0xa8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5d647
jp 0x5d647
movsd 0x90(%rsp), %xmm0
movq 0xd0(%rsp), %rax
movq 0x230(%rax), %rax
movslq 0xa8(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x5d666
movq 0xd0(%rsp), %rax
movq 0x230(%rax), %rax
movslq 0xa8(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x5d668
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x5d5de
movl $0x0, 0xbc(%rsp)
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x58(%rsp)
callq 0x138c0
movl %eax, %ecx
movl 0x58(%rsp), %eax
cmpl %ecx, %eax
jge 0x5da09
movl $0x0, 0xb8(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb8(%rsp), %eax
movl %eax, 0x54(%rsp)
callq 0x138e0
movl %eax, %ecx
movl 0x54(%rsp), %eax
cmpl %ecx, %eax
jge 0x5d9f1
movl $0x1, 0xc0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xe8(%rsp)
movl $0x0, 0x104(%rsp)
movl $0x0, 0xb4(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, 0x50(%rsp)
callq 0x13900
movl %eax, %ecx
movl 0x50(%rsp), %eax
cmpl %ecx, %eax
jge 0x5d847
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5d7a6
jp 0x5d7a6
movq 0x88(%rsp), %rdi
movl $0x0, 0xc0(%rsp)
movl $0x0, 0x104(%rsp)
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movsd %xmm0, 0xe8(%rsp)
jmp 0x5d82f
cmpl $0x0, 0xc0(%rsp)
jne 0x5d82d
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %eax
imull 0x104(%rsp), %eax
movl %eax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
cvtsi2sdl 0xc8(%rsp), %xmm0
callq 0x6bc60
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
movsd 0xe8(%rsp), %xmm0
callq 0x6bc60
jmp 0x5d82f
jmp 0x5d831
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x5d70d
movq 0x88(%rsp), %rdi
movl $0x0, 0x104(%rsp)
movl $0x1, 0xc0(%rsp)
callq 0x13900
subl $0x1, %eax
movl %eax, 0xb4(%rsp)
cmpl $0x0, 0xb4(%rsp)
jl 0x5d9d9
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5d8f5
jp 0x5d8f5
movq 0x88(%rsp), %rdi
movl $0x0, 0x104(%rsp)
movl $0x0, 0xc0(%rsp)
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movsd %xmm0, 0xe8(%rsp)
jmp 0x5d9c1
cmpl $0x0, 0xc0(%rsp)
jne 0x5d9bf
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %eax
imull 0x104(%rsp), %eax
movl %eax, 0xc8(%rsp)
cvtsi2sdl 0xc8(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movsd 0x48(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5d9bd
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
cvtsi2sdl 0xc8(%rsp), %xmm0
callq 0x6bc60
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
movsd 0xe8(%rsp), %xmm0
callq 0x6bc60
jmp 0x5d9bf
jmp 0x5d9c1
jmp 0x5d9c3
movl 0xb4(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x5d874
jmp 0x5d9db
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x5d6ba
jmp 0x5d9f3
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x5d689
movl $0x0, 0xb4(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, 0x44(%rsp)
callq 0x13900
movl %eax, %ecx
movl 0x44(%rsp), %eax
cmpl %ecx, %eax
jge 0x5debc
movl $0x0, 0xb8(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb8(%rsp), %eax
movl %eax, 0x40(%rsp)
callq 0x138e0
movl %eax, %ecx
movl 0x40(%rsp), %eax
cmpl %ecx, %eax
jge 0x5dea4
movl $0x0, 0xbc(%rsp)
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x3c(%rsp)
callq 0x138c0
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5db2e
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movq 0x88(%rsp), %rdi
movsd 0xd5542(%rip), %xmm1    # 0x133010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq 0xf8(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movq 0xe0(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x5da76
movl $0x0, 0xb0(%rsp)
movl $0x0, 0xbc(%rsp)
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x38(%rsp)
callq 0x138c0
movl %eax, %ecx
movl 0x38(%rsp), %eax
cmpl %ecx, %eax
jge 0x5dccd
movq 0xf8(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
cmpl $0x0, 0x104(%rsp)
je 0x5dc71
movl 0xb0(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0xbc(%rsp), %eax
jg 0x5dc6f
movq 0xf8(%rsp), %rax
movslq 0xac(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl 0xbc(%rsp), %ecx
subl 0xac(%rsp), %ecx
movl 0xbc(%rsp), %edx
subl 0xac(%rsp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x104(%rsp), %eax
jg 0x5dc57
movl 0xc4(%rsp), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xac(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5dc59
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5dbbe
jmp 0x5dc7f
movl 0xbc(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl 0x104(%rsp), %edx
movq 0xf0(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movsd 0xe8(%rsp), %xmm0
movq 0xd8(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x5db44
movq 0x88(%rsp), %rdi
callq 0x138c0
movq 0x88(%rsp), %rdi
subl $0x1, %eax
movl %eax, 0xb0(%rsp)
callq 0x138c0
subl $0x1, %eax
movl %eax, 0xbc(%rsp)
cmpl $0x0, 0xbc(%rsp)
jl 0x5de8c
movq 0xf0(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x104(%rsp)
movq 0xd8(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
cmpl $0x0, 0x104(%rsp)
je 0x5de66
movl 0xb0(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0xbc(%rsp), %eax
jl 0x5de0e
movq 0xf8(%rsp), %rax
movslq 0xac(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl 0xbc(%rsp), %ecx
subl 0xac(%rsp), %ecx
movl 0xbc(%rsp), %edx
subl 0xac(%rsp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x104(%rsp), %eax
jg 0x5ddf6
movl 0xc4(%rsp), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xac(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5ddf8
movl 0xac(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5dd5d
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
cvtsi2sdl 0x104(%rsp), %xmm0
callq 0x6bc60
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
movsd 0xe8(%rsp), %xmm0
callq 0x6bc60
jmp 0x5de74
movl 0xbc(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5de76
movl 0xbc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x5dcfb
jmp 0x5de8e
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x5da45
jmp 0x5dea6
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x5da14
movl $0x0, 0xb4(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, 0x34(%rsp)
callq 0x13900
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x5e363
movl $0x0, 0xbc(%rsp)
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x30(%rsp)
callq 0x138c0
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jge 0x5e34b
movl $0x0, 0xb8(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb8(%rsp), %eax
movl %eax, 0x2c(%rsp)
callq 0x138e0
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5dfd5
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movq 0x88(%rsp), %rdi
cvttsd2si %xmm0, %edx
movq 0xf8(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
callq 0x6bad0
movq 0xe0(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x5df29
movl $0x0, 0xb0(%rsp)
movl $0x0, 0xb8(%rsp)
movq 0x88(%rsp), %rdi
movl 0xb8(%rsp), %eax
movl %eax, 0x28(%rsp)
callq 0x138e0
movl %eax, %ecx
movl 0x28(%rsp), %eax
cmpl %ecx, %eax
jge 0x5e174
movq 0xf8(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
cmpl $0x0, 0x104(%rsp)
je 0x5e118
movl 0xb0(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0xb8(%rsp), %eax
jg 0x5e116
movq 0xf8(%rsp), %rax
movslq 0xac(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl 0xb8(%rsp), %ecx
subl 0xac(%rsp), %ecx
movl 0xb8(%rsp), %edx
subl 0xac(%rsp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x104(%rsp), %eax
jg 0x5e0fe
movl 0xc4(%rsp), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xac(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5e100
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5e065
jmp 0x5e126
movl 0xb8(%rsp), %eax
movl %eax, 0xb0(%rsp)
movl 0x104(%rsp), %edx
movq 0xf0(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movsd 0xe8(%rsp), %xmm0
movq 0xd8(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x5dfeb
movq 0x88(%rsp), %rdi
callq 0x138e0
movq 0x88(%rsp), %rdi
subl $0x1, %eax
movl %eax, 0xb0(%rsp)
callq 0x138e0
subl $0x1, %eax
movl %eax, 0xb8(%rsp)
cmpl $0x0, 0xb8(%rsp)
jl 0x5e333
movq 0xf0(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x104(%rsp)
movq 0xd8(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
cmpl $0x0, 0x104(%rsp)
je 0x5e30d
movl 0xb0(%rsp), %eax
movl %eax, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0xb8(%rsp), %eax
jle 0x5e2b5
movq 0xf8(%rsp), %rax
movslq 0xac(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl 0xb8(%rsp), %ecx
subl 0xac(%rsp), %ecx
movl 0xb8(%rsp), %edx
subl 0xac(%rsp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x104(%rsp), %eax
jg 0x5e29d
movl 0xc4(%rsp), %eax
movl %eax, 0x104(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xac(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xe8(%rsp)
movl 0xac(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5e29f
movl 0xac(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5e204
movq 0xd0(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
cvtsi2sdl 0x104(%rsp), %xmm0
callq 0x6bc60
movq 0x88(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
movl 0xb4(%rsp), %ecx
movsd 0xe8(%rsp), %xmm0
callq 0x6bc60
jmp 0x5e31b
movl 0xb8(%rsp), %eax
movl %eax, 0xb0(%rsp)
jmp 0x5e31d
movl 0xb8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x5e1a2
jmp 0x5e335
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x5def8
jmp 0x5e34d
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x5dec7
cmpq $0x0, 0x108(%rsp)
jne 0x5e39c
movq 0xd0(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x5e39a
movq 0x20(%rsp), %rdi
callq 0x56960
movq 0x20(%rsp), %rdi
movl $0x250, %esi            # imm = 0x250
callq 0xf4d0
jmp 0x5e39c
movq 0xf8(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x5e3b9
movq 0x18(%rsp), %rdi
callq 0xf670
movq 0xf0(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x5e3d6
movq 0x10(%rsp), %rdi
callq 0xf670
movq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x5e3f3
movq 0x8(%rsp), %rdi
callq 0xf670
movq 0xd8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x5e40e
movq (%rsp), %rdi
callq 0xf670
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xa0(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)