// File: /workspace/github_cpp_makefile_star2_O3/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 0x1b651
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 0x1b2b4
callq 0x1a7a9
movq 0x100(%r14), %rdx
notq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x1aa24
jmp 0x1b2ce
callq 0x1a63f
movq 0x100(%r14), %rdx
notq %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x1a90c
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
movl 0x210(%r14,%rbx), %ebp
cmpl $0x40, %ebp
movq %rbx, 0x10(%rsp)
je 0x1b358
addq %r14, %rbx
addq $0x210, %rbx            # imm = 0x210
leaq 0x8(%rsp), %r13
movslq %ebp, %rax
leaq 0xfe432(%rip), %rcx     # 0x119750
movq 0x400(%rcx,%rax,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1b34c
shll $0x6, %ebp
movq %r13, %rdi
callq 0x827b
orl %ebp, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b333
movl 0x4(%rbx), %ebp
addq $0x4, %rbx
cmpl $0x40, %ebp
jne 0x1b314
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movl 0xc0(%rax,%rcx), %ebp
cmpl $0x40, %ebp
je 0x1b40b
leaq (%rax,%rcx), %rbx
addq $0xc0, %rbx
leaq 0x8(%rsp), %r13
movslq %ebp, %rax
leaq 0xf3714(%rip), %rcx     # 0x10eaa0
movq (%rcx,%rax,8), %rcx
andq 0x100(%r14), %rcx
leaq 0x14022(%rip), %rdx     # 0x2f3c0
movq (%rdx,%rax,8), %rdx
movl %edx, %esi
imull %ecx, %esi
shrq $0x20, %rcx
shrq $0x20, %rdx
imull %ecx, %edx
xorl %esi, %edx
leaq 0x14405(%rip), %rcx     # 0x2f7c0
movb (%rcx,%rax,4), %cl
shrl %cl, %edx
leaq 0xf38d9(%rip), %rcx     # 0x10eca0
addl (%rcx,%rax,4), %edx
leaq 0xf39cf(%rip), %rax     # 0x10eda0
movq (%rax,%rdx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1b3fb
shll $0x6, %ebp
movq %r13, %rdi
callq 0x827b
orl %ebp, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b3e2
movl 0x4(%rbx), %ebp
addq $0x4, %rbx
cmpl $0x40, %ebp
jne 0x1b382
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movl 0x100(%rax,%rcx), %ebp
cmpl $0x40, %ebp
je 0x1b4be
leaq (%rax,%rcx), %rbx
addq $0x100, %rbx            # imm = 0x100
leaq 0x8(%rsp), %r13
movslq %ebp, %rax
leaq 0x2b361(%rip), %rcx     # 0x467a0
movq (%rcx,%rax,8), %rcx
andq 0x100(%r14), %rcx
leaq 0x1416f(%rip), %rdx     # 0x2f5c0
movq (%rdx,%rax,8), %rdx
movl %edx, %esi
imull %ecx, %esi
shrq $0x20, %rcx
shrq $0x20, %rdx
imull %ecx, %edx
xorl %esi, %edx
leaq 0x14452(%rip), %rcx     # 0x2f8c0
movb (%rcx,%rax,4), %cl
shrl %cl, %edx
leaq 0x2b526(%rip), %rcx     # 0x469a0
addl (%rcx,%rax,4), %edx
leaq 0x2b61c(%rip), %rax     # 0x46aa0
movq (%rax,%rdx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1b4ae
shll $0x6, %ebp
movq %r13, %rdi
callq 0x827b
orl %ebp, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b495
movl 0x4(%rbx), %ebp
addq $0x4, %rbx
cmpl $0x40, %ebp
jne 0x1b435
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movl 0x140(%rax,%rcx), %ebx
cmpl $0x40, %ebx
je 0x1b5bd
leaq (%rax,%rcx), %rbp
addq $0x140, %rbp            # imm = 0x140
leaq 0x8(%rsp), %r13
movq 0x100(%r14), %rcx
movslq %ebx, %rax
leaq 0x2b2a7(%rip), %rdx     # 0x467a0
movq (%rdx,%rax,8), %rsi
andq %rcx, %rsi
leaq 0x140b9(%rip), %rdx     # 0x2f5c0
movq (%rdx,%rax,8), %rdx
movl %edx, %edi
imull %esi, %edi
shrq $0x20, %rsi
shrq $0x20, %rdx
imull %esi, %edx
leaq 0xf357e(%rip), %rsi     # 0x10eaa0
andq (%rsi,%rax,8), %rcx
xorl %edi, %edx
leaq 0x13e91(%rip), %rsi     # 0x2f3c0
movq (%rsi,%rax,8), %rsi
movl %esi, %edi
imull %ecx, %edi
shrq $0x20, %rcx
shrq $0x20, %rsi
imull %ecx, %esi
leaq 0x14376(%rip), %rcx     # 0x2f8c0
movb (%rcx,%rax,4), %cl
shrl %cl, %edx
xorl %edi, %esi
leaq 0x2b448(%rip), %rcx     # 0x469a0
addl (%rcx,%rax,4), %edx
leaq 0x1425e(%rip), %rcx     # 0x2f7c0
movb (%rcx,%rax,4), %cl
shrl %cl, %esi
leaq 0xf3732(%rip), %rcx     # 0x10eca0
addl (%rcx,%rax,4), %esi
leaq 0xf3828(%rip), %rax     # 0x10eda0
movq (%rax,%rsi,8), %rax
leaq 0x2b51d(%rip), %rcx     # 0x46aa0
orq (%rcx,%rdx,8), %rax
andq %r12, %rax
movq %rax, 0x8(%rsp)
je 0x1b5ad
shll $0x6, %ebx
movq %r13, %rdi
callq 0x827b
orl %ebx, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b594
movl 0x4(%rbp), %ebx
addq $0x4, %rbp
cmpl $0x40, %ebx
jne 0x1b4e8
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movslq 0x180(%rax,%rcx), %rbx
leaq 0xfe17a(%rip), %rax     # 0x119750
andq 0xc00(%rax,%rbx,8), %r12
movq %r12, 0x8(%rsp)
je 0x1b606
shll $0x6, %ebx
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x827b
orl %ebx, %eax
movl %eax, (%r15)
addq $0x8, %r15
cmpq $0x0, 0x8(%rsp)
jne 0x1b5ed
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
movq 0x20(%rsp), %rbx
leal 0x1(%rbx), %ecx
testl %ecx, %eax
je 0x1b636
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x18b8c
movq %rax, %r15
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
leal 0x4(,%rbx,4), %ecx
testl %ecx, %eax
je 0x1b651
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x18e1a
movq %rax, %r15
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop