// File: /workspace/github_cpp_makefile_star2_O1/ATOMIC-LICHESS[P]ATOMKRAFT/movegen.cpp
// Function: MoveStack* generate<(MoveType)5>(Position const&, MoveStack*)
MoveStack* generate(const Position& pos, MoveStack* mlist) {
  NEW assert(pos.piece_count(WHITE, KING) && pos.piece_count(BLACK, KING));
		
  assert(pos.is_ok());
  assert(!pos.in_check());
  
  STARTNEW
  if (pos.piece_count(pos.side_to_move(), KING) == 0) {
	  return mlist;
  }
  ENDNEW

  Color us = pos.side_to_move();
  Bitboard target;

  if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
      target = pos.pieces_of_color(opposite_color(us));
  else if (Type == MV_NON_CAPTURE)
      target = pos.empty_squares();
  else
      assert(false);

  if (Type == MV_NON_EVASION)
  {
      mlist = generate_piece_moves<PAWN, MV_CAPTURE>(pos, mlist, us, target);
      mlist = generate_piece_moves<PAWN, MV_NON_CAPTURE>(pos, mlist, us, pos.empty_squares());
      target |= pos.empty_squares();
  }
  else
      mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target);

  mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
  mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
  mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
  mlist = generate_piece_moves<QUEEN>(pos, mlist, us, target);
  OLD mlist = generate_piece_moves<KING>(pos, mlist, us, target);
  STARTNEW
  // captures by the king are not allowed
  if (Type != MV_CAPTURE) {
	  mlist = generate_piece_moves<KING>(pos, mlist, us, target);
  }
  ENDNEW

  if (Type != MV_CAPTURE)
  {
      if (pos.can_castle_kingside(us))
          mlist = generate_castle_moves<KING_SIDE>(pos, mlist, us);

      if (pos.can_castle_queenside(us))
          mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist, us);
  }

  return mlist;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movl 0x1090(%rdi), %ebx
movq %rbx, %rax
shlq $0x5, %rax
cmpl $0x0, 0x168(%rdi,%rax)
je 0x1b12a
movq %rdi, %r14
movq %rbx, %rax
xorq $0x1, %rax
movq 0x140(%rdi,%rax,8), %r12
movq %r15, %rsi
movq %r12, %rdx
testq %rbx, %rbx
je 0x1ad93
callq 0x1a2b7
jmp 0x1ad98
callq 0x1a14d
movq 0x100(%r14), %rdx
notq %rdx
movq %r14, %rdi
movq %rax, %rsi
testl %ebx, %ebx
je 0x1adb3
callq 0x1a535
jmp 0x1adb8
callq 0x1a41a
movq %rax, %r15
movq 0x100(%r14), %rax
notq %rax
orq %rax, %r12
leaq 0x190(%r14), %rax
movq %rax, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
shlq $0x9, %rbx
cmpl $0x40, 0x210(%r14,%rbx)
movq %rbx, 0x10(%rsp)
je 0x1ae40
leaq (%r14,%rbx), %rbp
addq $0x210, %rbp            # imm = 0x210
leaq 0x8(%rsp), %r13
movslq (%rbp), %rbx
leaq 0xfd948(%rip), %rax     # 0x118750
movq 0x400(%rax,%rbx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1ae36
shll $0x6, %ebx
movq %r13, %rdi
callq 0x7d37
orl %ebx, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1ae1d
cmpl $0x40, 0x4(%rbp)
leaq 0x4(%rbp), %rbp
jne 0x1adfd
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpl $0x40, 0xc0(%rax,%rcx)
je 0x1aeef
leaq (%rax,%rcx), %rbx
addq $0xc0, %rbx
leaq 0x8(%rsp), %r13
movslq (%rbx), %rbp
leaq 0xf2c2e(%rip), %rax     # 0x10daa0
movq (%rax,%rbp,8), %rax
andq 0x100(%r14), %rax
leaq 0x134bc(%rip), %rcx     # 0x2e340
movq (%rcx,%rbp,8), %rdx
movl %edx, %ecx
imull %eax, %ecx
shrq $0x20, %rax
shrq $0x20, %rdx
imull %eax, %edx
xorl %ecx, %edx
leaq 0x1389f(%rip), %rax     # 0x2e740
movb (%rax,%rbp,4), %cl
shrl %cl, %edx
leaq 0xf2df3(%rip), %rax     # 0x10dca0
addl (%rax,%rbp,4), %edx
leaq 0xf2ee9(%rip), %rax     # 0x10dda0
movq (%rax,%rdx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1aee1
shll $0x6, %ebp
movq %r13, %rdi
callq 0x7d37
orl %ebp, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1aec8
cmpl $0x40, 0x4(%rbx)
leaq 0x4(%rbx), %rbx
jne 0x1ae68
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpl $0x40, 0x100(%rax,%rcx)
je 0x1af9e
leaq (%rax,%rcx), %rbx
addq $0x100, %rbx            # imm = 0x100
leaq 0x8(%rsp), %r13
movslq (%rbx), %rbp
leaq 0x2a87f(%rip), %rax     # 0x457a0
movq (%rax,%rbp,8), %rax
andq 0x100(%r14), %rax
leaq 0x1360d(%rip), %rcx     # 0x2e540
movq (%rcx,%rbp,8), %rdx
movl %edx, %ecx
imull %eax, %ecx
shrq $0x20, %rax
shrq $0x20, %rdx
imull %eax, %edx
xorl %ecx, %edx
leaq 0x138f0(%rip), %rax     # 0x2e840
movb (%rax,%rbp,4), %cl
shrl %cl, %edx
leaq 0x2aa44(%rip), %rax     # 0x459a0
addl (%rax,%rbp,4), %edx
leaq 0x2ab3a(%rip), %rax     # 0x45aa0
movq (%rax,%rdx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1af90
shll $0x6, %ebp
movq %r13, %rdi
callq 0x7d37
orl %ebp, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1af77
cmpl $0x40, 0x4(%rbx)
leaq 0x4(%rbx), %rbx
jne 0x1af17
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpl $0x40, 0x140(%rax,%rcx)
je 0x1b09a
leaq (%rax,%rcx), %rbp
addq $0x140, %rbp            # imm = 0x140
leaq 0x8(%rsp), %r13
movslq (%rbp), %rbx
movq 0x100(%r14), %rcx
leaq 0x2a7c8(%rip), %rax     # 0x457a0
movq (%rax,%rbx,8), %rdx
andq %rcx, %rdx
leaq 0x1355a(%rip), %rax     # 0x2e540
movq (%rax,%rbx,8), %rax
movl %eax, %esi
imull %edx, %esi
shrq $0x20, %rdx
shrq $0x20, %rax
imull %edx, %eax
leaq 0xf2a9f(%rip), %rdx     # 0x10daa0
andq (%rdx,%rbx,8), %rcx
xorl %esi, %eax
leaq 0x13332(%rip), %rdx     # 0x2e340
movq (%rdx,%rbx,8), %rdx
movl %edx, %esi
imull %ecx, %esi
shrq $0x20, %rcx
shrq $0x20, %rdx
imull %ecx, %edx
leaq 0x13817(%rip), %rcx     # 0x2e840
movb (%rcx,%rbx,4), %cl
shrl %cl, %eax
xorl %esi, %edx
leaq 0x2a969(%rip), %rcx     # 0x459a0
addl (%rcx,%rbx,4), %eax
leaq 0x136ff(%rip), %rcx     # 0x2e740
movb (%rcx,%rbx,4), %cl
shrl %cl, %edx
leaq 0xf2c53(%rip), %rcx     # 0x10dca0
addl (%rcx,%rbx,4), %edx
leaq 0xf2d49(%rip), %rcx     # 0x10dda0
movq (%rcx,%rdx,8), %rcx
leaq 0x2aa3e(%rip), %rdx     # 0x45aa0
orq (%rdx,%rax,8), %rcx
andq %r12, %rcx
movq %rcx, 0x8(%rsp)
je 0x1b08c
shll $0x6, %ebx
movq %r13, %rdi
callq 0x7d37
orl %ebx, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b073
cmpl $0x40, 0x4(%rbp)
leaq 0x4(%rbp), %rbp
jne 0x1afc6
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movslq 0x180(%rax,%rcx), %rbx
leaq 0xfd69d(%rip), %rax     # 0x118750
andq 0xc00(%rax,%rbx,8), %r12
movq %r12, 0x8(%rsp)
je 0x1b0e3
shll $0x6, %ebx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x7d37
orl %ebx, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b0ca
movq 0x1938(%r14), %rax
movq 0x20(%rsp), %rbx
leal 0x1(%rbx), %ecx
testl %ecx, 0x10(%rax)
je 0x1b107
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x18648
movq %rax, %r15
movq 0x1938(%r14), %rax
leal 0x4(,%rbx,4), %ecx
testl %ecx, 0x10(%rax)
je 0x1b12a
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x188d8
movq %rax, %r15
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq