// File: ATOMIC-LICHESS[P]ATOMKRAFT/evaluate.cpp
// Function: Value (anonymous namespace)::do_evaluate<false, true>(Position const&, Value&, bool*)
Value do_evaluate(const Position& pos, Value& margin, bool* expl_threat) {

  NEW *expl_threat = false;
  
  
  
  EvalInfo ei;
  Value margins[2];
  Score score, mobilityWhite, mobilityBlack;

  assert(pos.is_ok());
  assert(pos.thread() >= 0 && pos.thread() < MAX_THREADS);
  assert(!pos.in_check());

  // Initialize score by reading the incrementally updated scores included
  // in the position object (material + piece square tables).
  score = pos.value();

  // margins[] store the uncertainty estimation of position's evaluation
  // that typically is used by the search for pruning decisions.
  margins[WHITE] = margins[BLACK] = VALUE_ZERO;

  // Probe the material hash table
  ei.mi = Threads[pos.thread()].materialTable.get_material_info(pos);
  score += ei.mi->material_value();
  
  STARTNEW
  // in the endgame just the difference in material count is important
  //Color us = pos.side_to_move();
  //Color them = opposite_color(us);
  int mat_dif;
  
  if (HasPopCnt) {
	  mat_dif = 
			  count_1s<CNT_POPCNT>(pos.pieces_of_color(WHITE))
			- count_1s<CNT_POPCNT>(pos.pieces_of_color(BLACK));
  } else {
	  mat_dif = 
			  pos.piece_count(WHITE, PAWN)     + pos.piece_count(WHITE, KNIGHT)
			+ pos.piece_count(WHITE, BISHOP)   + pos.piece_count(WHITE, ROOK)
			+ pos.piece_count(WHITE, QUEEN)
			- pos.piece_count(BLACK, PAWN)     - pos.piece_count(BLACK, KNIGHT)
			- pos.piece_count(BLACK, BISHOP)   - pos.piece_count(BLACK, ROOK)
			- pos.piece_count(BLACK, QUEEN);
  }
  
  //if (useImprovements) {
	//  score += make_score(mat_dif * PawnValueMidgame / 3, mat_dif * 2 * PawnValueMidgame);
  //} else {
	  score += make_score(mat_dif * matDifFactor / 4, mat_dif * matDifFactor);
  //}

  ENDNEW

  NEW // material evaluation recognizes some endgame patterns for chess
  
  // If we have a specialized evaluation function for the current material
  // configuration, call it and return.
  if (ei.mi->specialized_eval_exists())
  {
      margin = VALUE_ZERO;
      OLD return ei.mi->evaluate(pos);
      
      STARTNEW
      Value special_eval = ei.mi->evaluate(pos);
      if (special_eval != VALUE_NONE) {
    	  // some new special evaluations may return VALUE_NONE if 
    	  // the outcome of the game is not clear
    	  return special_eval;
      }
      ENDNEW
  }
  

  // Probe the pawn hash table
  ei.pi = Threads[pos.thread()].pawnTable.get_pawn_info(pos);
  score += ei.pi->pawns_value();

  // Initialize attack and king safety bitboards
  init_eval_info<WHITE, HasPopCnt>(pos, ei);
  init_eval_info<BLACK, HasPopCnt>(pos, ei);

  // Evaluate pieces and mobility
  score +=  evaluate_pieces_of_color<WHITE, HasPopCnt, Trace>(pos, ei, mobilityWhite)
          - evaluate_pieces_of_color<BLACK, HasPopCnt, Trace>(pos, ei, mobilityBlack);
  
  STARTNEW
  // evaluate_pieces_of_color fills the attackedBy arrays
  
  // create a shortcut if we can explode opponents king
  Color us_aux = pos.side_to_move();
  Color them_aux = opposite_color(us_aux);
  Bitboard expl_threat_squares
  	  = ei.attackedBy[us_aux][0] & ei.attackedBy[them_aux][KING] & pos.pieces_of_color(them_aux);

  if (expl_threat_squares) {
	  return VALUE_KNOWN_WIN;
  }
  
  // compute the explosion thread
  expl_threat_squares
  	  = ei.attackedBy[them_aux][0] & ei.attackedBy[us_aux][KING] & pos.pieces_of_color(us_aux);
  *expl_threat = (expl_threat_squares != 0ULL);
  ENDNEW

  score += apply_weight(mobilityWhite - mobilityBlack, Weights[Mobility]);

  // Evaluate kings after all other pieces because we need complete attack
  // information when computing the king safety evaluation.
  score +=  evaluate_king<WHITE, HasPopCnt, Trace>(pos, ei, margins)
          - evaluate_king<BLACK, HasPopCnt, Trace>(pos, ei, margins);

  // Evaluate tactical threats, we need full attack information including king
  score +=  evaluate_threats<WHITE>(pos, ei)
          - evaluate_threats<BLACK>(pos, ei);

  // Evaluate passed pawns, we need full attack information including king
  score +=  evaluate_passed_pawns<WHITE>(pos, ei)
          - evaluate_passed_pawns<BLACK>(pos, ei);

  // If one side has only a king, check whether exists any unstoppable passed pawn
  if (!pos.non_pawn_material(WHITE) || !pos.non_pawn_material(BLACK))
      score += evaluate_unstoppable_pawns<HasPopCnt>(pos, ei);

  // Evaluate space for both sides, only in middle-game.
  if (ei.mi->space_weight())
  {
      int s = evaluate_space<WHITE, HasPopCnt>(pos, ei) - evaluate_space<BLACK, HasPopCnt>(pos, ei);
      score += apply_weight(make_score(s * ei.mi->space_weight(), 0), Weights[Space]);
  }

  // Scale winning side if position is more drawish that what it appears
  NEW // this cannot be trusted
  //NEW ScaleFactor sf = SCALE_FACTOR_NORMAL;
  //OLD ScaleFactor sf = eg_value(score) > VALUE_DRAW ? ei.mi->scale_factor(pos, WHITE)
                                                //: ei.mi->scale_factor(pos, BLACK);
  
  
  STARTNEW
  ScaleFactor sf = SCALE_FACTOR_NORMAL;
  
  sf = eg_value(score) > VALUE_DRAW ? ei.mi->scale_factor(pos, WHITE)
		  : ei.mi->scale_factor(pos, BLACK);

  // if there is no material difference the game is drawish
  // calculated here because we already have mat_dif
  if (   ei.mi->game_phase() < PHASE_MIDGAME 
		  && sf == SCALE_FACTOR_NORMAL
		  && mat_dif == 0) {

	  if (eg_value(score) > VALUE_DRAW) {
		  if (pos.non_pawn_material(WHITE) <= RookValueMidgame) {
			  sf = ScaleFactor(32);
		  } else if (pos.non_pawn_material(WHITE) <= KnightValueMidgame) {
			  sf = ScaleFactor(16);
		  }
	  } else {
		  if (pos.non_pawn_material(BLACK) <= RookValueMidgame) {
			  sf = ScaleFactor(32);
		  } else if (pos.non_pawn_material(BLACK) <= KnightValueMidgame) {
			  sf = ScaleFactor(16);
		  }
	  } 
  }
  
  // adjacent kings make the game hard to win
  static const float KING_DIST_SF[] = {0.0f, 0.5f, 0.7f, 0.8f, 0.9f, 1.0f, 1.0f, 1.0f};
  
  int k_dist = square_dist(pos.king_square(WHITE), pos.king_square(BLACK));
  if (ei.mi->game_phase() == PHASE_ENDGAME) {
	  sf = ScaleFactor(int(float(sf) * KING_DIST_SF[k_dist]));
  }
  
  ENDNEW
  
  // If we don't already have an unusual scale factor, check for opposite
  // colored bishop endgames, and use a lower scale for those.
  NEW // this cannot be trusted
  STARTOLD
  if (   ei.mi->game_phase() < PHASE_MIDGAME
      && pos.opposite_colored_bishops()
      && sf == SCALE_FACTOR_NORMAL)
  {
      // Only the two bishops ?
      if (   pos.non_pawn_material(WHITE) == BishopValueMidgame
          && pos.non_pawn_material(BLACK) == BishopValueMidgame)
      {
          // Check for KBP vs KB with only a single pawn that is almost
          // certainly a draw or at least two pawns.
          bool one_pawn = (pos.piece_count(WHITE, PAWN) + pos.piece_count(BLACK, PAWN) == 1);
          sf = one_pawn ? ScaleFactor(8) : ScaleFactor(32);
      }
      else
          // Endgame with opposite-colored bishops, but also other pieces. Still
          // a bit drawish, but not as drawish as with only the two bishops.
           sf = ScaleFactor(50);
  }
  ENDOLD

  // Interpolate between the middle game and the endgame score
  margin = margins[pos.side_to_move()];
  Value v = scale_by_game_phase(score, ei.mi->game_phase(), sf);
  

  
  STARTNEW
  // if we are bad in the endgame maybe we can force a draw by touching the opposite king
  
  ENDNEW

  // In case of tracing add all single evaluation contributions for both white and black
  if (Trace)
  {
      trace_add(PST, pos.value());
      trace_add(IMBALANCE, ei.mi->material_value());
      trace_add(PAWN, ei.pi->pawns_value());
      trace_add(MOBILITY, apply_weight(mobilityWhite, Weights[Mobility]), apply_weight(mobilityBlack, Weights[Mobility]));
      trace_add(THREAT, evaluate_threats<WHITE>(pos, ei), evaluate_threats<BLACK>(pos, ei));
      trace_add(PASSED, evaluate_passed_pawns<WHITE>(pos, ei), evaluate_passed_pawns<BLACK>(pos, ei));
      trace_add(UNSTOPPABLE, evaluate_unstoppable_pawns<false>(pos, ei));
      Score w = make_score(ei.mi->space_weight() * evaluate_space<WHITE, false>(pos, ei), 0);
      Score b = make_score(ei.mi->space_weight() * evaluate_space<BLACK, false>(pos, ei), 0);
      trace_add(SPACE, apply_weight(w, Weights[Space]), apply_weight(b, Weights[Space]));
      trace_add(TOTAL, score);
      TraceStream << "\nUncertainty margin: White: " << to_cp(margins[WHITE])
                  << ", Black: " << to_cp(margins[BLACK])
                  << "\nScaling: " << std::noshowpos
                  << std::setw(6) << 100.0 * ei.mi->game_phase() / 128.0 << "% MG, "
                  << std::setw(6) << 100.0 * (1.0 - ei.mi->game_phase() / 128.0) << "% * "
                  << std::setw(6) << (100.0 * sf) / SCALE_FACTOR_NORMAL << "% EG.\n"
                  << "Total evaluation: " << to_cp(v);
  }

  return pos.side_to_move() == WHITE ? v : -v;
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1d8(%rsp)
movq %rsi, 0x1d0(%rsp)
movq %rdx, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rax
movb $0x0, (%rax)
movq 0x1d8(%rsp), %rdi
callq 0x297a0
movl %eax, 0xfc(%rsp)
movl $0x0, 0x104(%rsp)
movl $0x0, 0x100(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x297f0
movl %eax, %esi
leaq 0x3d1ca6(%rip), %rdi    # 0x3f0c40
callq 0x297c0
movq %rax, %rdi
movq 0x1d8(%rsp), %rsi
callq 0x2a870
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rdi
callq 0x29840
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x164c0
movl %eax, 0x90(%rsp)
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x164c0
movl %eax, %ecx
movl 0x90(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x94(%rsp)
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x164c0
movl %eax, %ecx
movl 0x94(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x98(%rsp)
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x164c0
movl %eax, %ecx
movl 0x98(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x9c(%rsp)
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x164c0
movl %eax, %ecx
movl 0x9c(%rsp), %eax
addl %ecx, %eax
movl %eax, 0xa0(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x164c0
movl %eax, %ecx
movl 0xa0(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xa4(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x164c0
movl %eax, %ecx
movl 0xa4(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xa8(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
movl $0x3, %edx
callq 0x164c0
movl %eax, %ecx
movl 0xa8(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xac(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
movl $0x4, %edx
callq 0x164c0
movl %eax, %ecx
movl 0xac(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xb0(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
movl $0x5, %edx
callq 0x164c0
movl %eax, %ecx
movl 0xb0(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xf0(%rsp)
movl 0xf0(%rsp), %eax
imull 0x4d3f2(%rip), %eax     # 0x6c550
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %edi
movl 0xf0(%rsp), %esi
imull 0x4d3da(%rip), %esi     # 0x6c550
callq 0x27f40
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x108(%rsp), %rdi
callq 0x29860
testb $0x1, %al
jne 0x1f19d
jmp 0x1f1e9
movq 0x1d0(%rsp), %rax
movl $0x0, (%rax)
movq 0x108(%rsp), %rdi
movq 0x1d8(%rsp), %rsi
callq 0x29880
movl %eax, 0xec(%rsp)
cmpl $0x7532, 0xec(%rsp) # imm = 0x7532
je 0x1f1e7
movl 0xec(%rsp), %eax
movl %eax, 0x1e4(%rsp)
jmp 0x1fc0b
jmp 0x1f1e9
movq 0x1d8(%rsp), %rdi
callq 0x297f0
movl %eax, %esi
leaq 0x3d1a41(%rip), %rdi    # 0x3f0c40
callq 0x297c0
movq %rax, %rdi
addq $0x18, %rdi
movq 0x1d8(%rsp), %rsi
callq 0x349d0
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rdi
callq 0x298b0
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x200f0
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x20330
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x24c10
movl %eax, 0x84(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xf4(%rsp), %rdx
callq 0x24d30
movl 0x84(%rsp), %edi
movl %eax, %esi
callq 0x29740
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
callq 0xf5d0
movl %eax, 0xe8(%rsp)
movl 0xe8(%rsp), %edi
callq 0x122b0
movl %eax, 0xe4(%rsp)
leaq 0x108(%rsp), %rax
addq $0x10, %rax
movl 0xe8(%rsp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq (%rax), %rax
leaq 0x108(%rsp), %rcx
addq $0x10, %rcx
movl 0xe4(%rsp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
andq 0x30(%rcx), %rax
movq %rax, 0x88(%rsp)
movq 0x1d8(%rsp), %rdi
movl 0xe4(%rsp), %esi
callq 0x298c0
movq %rax, %rcx
movq 0x88(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xd8(%rsp)
cmpq $0x0, 0xd8(%rsp)
je 0x1f373
movl $0x3a98, 0x1e4(%rsp) # imm = 0x3A98
jmp 0x1fc0b
leaq 0x108(%rsp), %rax
addq $0x10, %rax
movl 0xe4(%rsp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq (%rax), %rax
leaq 0x108(%rsp), %rcx
addq $0x10, %rcx
movl 0xe8(%rsp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
andq 0x30(%rcx), %rax
movq %rax, 0x70(%rsp)
movq 0x1d8(%rsp), %rdi
movl 0xe8(%rsp), %esi
callq 0x298c0
movq %rax, %rcx
movq 0x70(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xd8(%rsp)
cmpq $0x0, 0xd8(%rsp)
setne %cl
movq 0x1c8(%rsp), %rax
andb $0x1, %cl
movb %cl, (%rax)
movl 0xf8(%rsp), %edi
movl 0xf4(%rsp), %esi
callq 0x29740
movl %eax, %edi
movl 0x3c3622(%rip), %esi    # 0x3e2a30
callq 0x20050
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
leaq 0x100(%rsp), %rdx
leaq 0x108(%rsp), %rsi
callq 0x24e50
movl %eax, 0x78(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x100(%rsp), %rdx
leaq 0x108(%rsp), %rsi
callq 0x258b0
movl 0x78(%rsp), %edi
movl %eax, %esi
callq 0x29740
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c50
movl %eax, 0x7c(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c60
movl 0x7c(%rsp), %edi
movl %eax, %esi
callq 0x29740
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c70
movl %eax, 0x80(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22050
movl 0x80(%rsp), %edi
movl %eax, %esi
callq 0x29740
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
callq 0x298e0
cmpl $0x0, %eax
je 0x1f53b
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
callq 0x298e0
cmpl $0x0, %eax
jne 0x1f55f
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22430
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movq 0x108(%rsp), %rdi
callq 0x29900
cmpl $0x0, %eax
je 0x1f5f0
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22e90
movl %eax, 0x68(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22ea0
movl %eax, %ecx
movl 0x68(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x108(%rsp), %rdi
callq 0x29900
movl 0x6c(%rsp), %edi
imull %eax, %edi
xorl %esi, %esi
callq 0x27f40
movl %eax, %edi
movl 0x3c345c(%rip), %esi    # 0x3e2a38
callq 0x20050
movl %eax, %esi
leaq 0xfc(%rsp), %rdi
callq 0x29810
movl $0x40, 0xd0(%rsp)
movl 0xfc(%rsp), %edi
callq 0x281f0
cmpl $0x0, %eax
jle 0x1f629
movq 0x108(%rsp), %rdi
movq 0x1d8(%rsp), %rsi
xorl %edx, %edx
callq 0x29910
movl %eax, 0x64(%rsp)
jmp 0x1f647
movq 0x108(%rsp), %rdi
movq 0x1d8(%rsp), %rsi
movl $0x1, %edx
callq 0x29910
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0xd0(%rsp)
movq 0x108(%rsp), %rdi
callq 0x299a0
cmpl $0x80, %eax
jge 0x1f73f
cmpl $0x40, 0xd0(%rsp)
jne 0x1f73f
cmpl $0x0, 0xf0(%rsp)
jne 0x1f73f
movl 0xfc(%rsp), %edi
callq 0x281f0
cmpl $0x0, %eax
jle 0x1f6e7
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
callq 0x298e0
leaq 0x4cec3(%rip), %rcx     # 0x6c570
cmpl (%rcx), %eax
jg 0x1f6be
movl $0x20, 0xd0(%rsp)
jmp 0x1f6e5
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
callq 0x298e0
leaq 0x4ce8c(%rip), %rcx     # 0x6c560
cmpl (%rcx), %eax
jg 0x1f6e3
movl $0x10, 0xd0(%rsp)
jmp 0x1f6e5
jmp 0x1f73d
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
callq 0x298e0
leaq 0x4ce70(%rip), %rcx     # 0x6c570
cmpl (%rcx), %eax
jg 0x1f711
movl $0x20, 0xd0(%rsp)
jmp 0x1f73b
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
callq 0x298e0
leaq 0x4ce36(%rip), %rcx     # 0x6c560
cmpl (%rcx), %eax
jg 0x1f739
movl $0x10, 0xd0(%rsp)
jmp 0x1f73b
jmp 0x1f73d
jmp 0x1f73f
movq 0x1d8(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0x60(%rsp)
movq 0x1d8(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movl 0x60(%rsp), %edi
movl %eax, %esi
callq 0x1b280
movl %eax, 0xcc(%rsp)
movq 0x108(%rsp), %rdi
callq 0x299a0
cmpl $0x0, %eax
jne 0x1f7b3
movl 0xd0(%rsp), %eax
cvtsi2ss %rax, %xmm0
movslq 0xcc(%rsp), %rcx
leaq 0x3aafd(%rip), %rax     # 0x5a2a0
mulss (%rax,%rcx,4), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0xd0(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0xf5d0
movl %eax, %eax
movl 0x100(%rsp,%rax,4), %ecx
movq 0x1d0(%rsp), %rax
movl %ecx, (%rax)
movq 0x108(%rsp), %rdi
callq 0x299a0
movl %eax, %esi
movl 0xd0(%rsp), %edx
leaq 0xfc(%rsp), %rdi
callq 0x22eb0
movl %eax, 0xc8(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x297a0
movl %eax, %esi
movl $0x8, %edi
xorl %edx, %edx
callq 0x26300
movq 0x108(%rsp), %rdi
callq 0x29840
movl %eax, %esi
movl $0x9, %edi
xorl %edx, %edx
callq 0x26300
movq 0x110(%rsp), %rdi
callq 0x298b0
movl %eax, %esi
movl $0x1, %edi
xorl %edx, %edx
callq 0x26300
movl 0xf8(%rsp), %edi
movl 0x3c31d5(%rip), %esi    # 0x3e2a30
callq 0x20050
movl %eax, 0x8(%rsp)
movl 0xf4(%rsp), %edi
movl 0x3c31bf(%rip), %esi    # 0x3e2a30
callq 0x20050
movl 0x8(%rsp), %esi
movl %eax, %edx
movl $0xa, %edi
callq 0x26300
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c50
movl %eax, 0xc(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c60
movl 0xc(%rsp), %esi
movl %eax, %edx
movl $0xb, %edi
callq 0x26300
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21c70
movl %eax, 0x10(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22050
movl 0x10(%rsp), %esi
movl %eax, %edx
movl $0xc, %edi
callq 0x26300
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22430
movl %eax, %esi
movl $0xd, %edi
xorl %edx, %edx
callq 0x26300
movq 0x108(%rsp), %rdi
callq 0x29900
movl %eax, 0x14(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22e90
movl 0x14(%rsp), %edi
imull %eax, %edi
xorl %esi, %esi
callq 0x27f40
movl %eax, 0xc4(%rsp)
movq 0x108(%rsp), %rdi
callq 0x29900
movl %eax, 0x18(%rsp)
movq 0x1d8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x22ea0
movl 0x18(%rsp), %edi
imull %eax, %edi
xorl %esi, %esi
callq 0x27f40
movl %eax, 0xc0(%rsp)
movl 0xc4(%rsp), %edi
movl 0x3c3090(%rip), %esi    # 0x3e2a38
callq 0x20050
movl %eax, 0x1c(%rsp)
movl 0xc0(%rsp), %edi
movl 0x3c307a(%rip), %esi    # 0x3e2a38
callq 0x20050
movl 0x1c(%rsp), %esi
movl %eax, %edx
movl $0xe, %edi
callq 0x26300
movl 0xfc(%rsp), %esi
movl $0xf, %edi
xorl %edx, %edx
callq 0x26300
leaq 0x3c2eb3(%rip), %rdi    # 0x3e28a0
addq $0x10, %rdi
leaq 0x3a58c(%rip), %rsi     # 0x59f84
callq 0x64b0
movq %rax, 0x20(%rsp)
movl 0x100(%rsp), %edi
callq 0x200d0
movq 0x20(%rsp), %rdi
callq 0x6a10
movq %rax, %rdi
leaq 0x3a57f(%rip), %rsi     # 0x59fa1
callq 0x64b0
movq %rax, 0x28(%rsp)
movl 0x104(%rsp), %edi
callq 0x200d0
movq 0x28(%rsp), %rdi
callq 0x6a10
movq %rax, %rdi
leaq 0x3a55f(%rip), %rsi     # 0x59fab
callq 0x64b0
movq %rax, %rdi
leaq 0x9cc5(%rip), %rsi      # 0x29720
callq 0x6170
movq %rax, 0x30(%rsp)
movl $0x6, %edi
callq 0x28160
movq 0x30(%rsp), %rdi
movl %eax, 0xbc(%rsp)
movl 0xbc(%rsp), %esi
callq 0x65a0
movq %rax, 0x38(%rsp)
movq 0x108(%rsp), %rdi
callq 0x299a0
movq 0x38(%rsp), %rdi
cvtsi2sd %eax, %xmm1
movsd 0x3a2be(%rip), %xmm0    # 0x59d68
mulsd %xmm1, %xmm0
movsd 0x3a2c2(%rip), %xmm1    # 0x59d78
divsd %xmm1, %xmm0
callq 0x6a10
movq %rax, %rdi
leaq 0x3a4ed(%rip), %rsi     # 0x59fb6
callq 0x64b0
movq %rax, 0x40(%rsp)
movl $0x6, %edi
callq 0x28160
movq 0x40(%rsp), %rdi
movl %eax, 0xb8(%rsp)
movl 0xb8(%rsp), %esi
callq 0x65a0
movq %rax, 0x48(%rsp)
movq 0x108(%rsp), %rdi
callq 0x299a0
movq 0x48(%rsp), %rdi
cvtsi2sd %eax, %xmm0
movsd 0x3a260(%rip), %xmm1    # 0x59d78
divsd %xmm1, %xmm0
movsd 0x3a24c(%rip), %xmm1    # 0x59d70
subsd %xmm0, %xmm1
movsd 0x3a238(%rip), %xmm0    # 0x59d68
mulsd %xmm1, %xmm0
callq 0x6a10
movq %rax, %rdi
leaq 0x3a47a(%rip), %rsi     # 0x59fbd
callq 0x64b0
movq %rax, 0x50(%rsp)
movl $0x6, %edi
callq 0x28160
movq 0x50(%rsp), %rdi
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %esi
callq 0x65a0
movq %rax, %rdi
cvtsi2sdl 0xd0(%rsp), %xmm1
movsd 0x3a1e5(%rip), %xmm0    # 0x59d68
mulsd %xmm1, %xmm0
movsd 0x3a1d1(%rip), %xmm1    # 0x59d60
divsd %xmm1, %xmm0
callq 0x6a10
movq %rax, %rdi
leaq 0x3a420(%rip), %rsi     # 0x59fc2
callq 0x64b0
movq %rax, %rdi
leaq 0x3a418(%rip), %rsi     # 0x59fc9
callq 0x64b0
movq %rax, 0x58(%rsp)
movl 0xc8(%rsp), %edi
callq 0x200d0
movq 0x58(%rsp), %rdi
callq 0x6a10
movq 0x1d8(%rsp), %rdi
callq 0xf5d0
cmpl $0x0, %eax
jne 0x1fbf0
movl 0xc8(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x1fc00
movl 0xc8(%rsp), %edi
callq 0x1b2b0
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x1e4(%rsp)
movl 0x1e4(%rsp), %eax
addq $0x1e8, %rsp            # imm = 0x1E8
retq
nopw (%rax,%rax)