// File: ATOMIC-LICHESS[P]ATOMKRAFT/search.cpp
// Function: Depth (anonymous namespace)::extension<((anonymous namespace)::NodeType)1>(Position const&, Move, bool, bool, bool*)
Depth extension(const Position& pos, Move m, bool captureOrPromotion,
                  bool moveIsCheck, bool* dangerous) {

    assert(m != MOVE_NONE);

    Depth result = DEPTH_ZERO;
    *dangerous = moveIsCheck;
    
    if (moveIsCheck && pos.see_sign(m) >= 0)
        result += CheckExtension[PvNode];

    if (pos.type_of_piece_on(move_from(m)) == PAWN)
    {
        Color c = pos.side_to_move();
        if (relative_rank(c, move_to(m)) == RANK_7)
        {
            result += PawnPushTo7thExtension[PvNode];
            *dangerous = true;
        }
        if (pos.pawn_is_passed(c, move_to(m)))
        {
            result += PassedPawnExtension[PvNode];
            *dangerous = true;
        }
    }

    if (   captureOrPromotion
        && pos.type_of_piece_on(move_to(m)) != PAWN
        && (  pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
            - pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
        && !move_is_special(m))
    {
        result += PawnEndgameExtension[PvNode];
        *dangerous = true;
    }

    return Min(result, ONE_PLY);
  }

// Assembly:
subq $0x58, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
andb $0x1, %cl
movb %cl, 0x4b(%rsp)
andb $0x1, %al
movb %al, 0x4a(%rsp)
movq %r8, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movb 0x4a(%rsp), %cl
movq 0x40(%rsp), %rax
andb $0x1, %cl
movb %cl, (%rax)
testb $0x1, 0x4a(%rsp)
je 0x48de3
movq 0x50(%rsp), %rdi
movl 0x4c(%rsp), %esi
callq 0x3d470
cmpl $0x0, %eax
jl 0x48de3
movl 0x3a289b(%rip), %esi    # 0x3eb674
leaq 0x3c(%rsp), %rdi
callq 0x4ea50
movq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x4c(%rsp), %edi
callq 0xf680
movq 0x30(%rsp), %rdi
movl %eax, %esi
callq 0x11f10
cmpl $0x1, %eax
jne 0x48e9d
movq 0x50(%rsp), %rdi
callq 0xf5d0
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x4c(%rsp), %edi
callq 0xf690
movl 0x2c(%rsp), %edi
movl %eax, %esi
callq 0x1b2c0
cmpl $0x6, %eax
jne 0x48e52
movl 0x3a2844(%rip), %esi    # 0x3eb684
leaq 0x3c(%rsp), %rdi
callq 0x4ea50
movq 0x40(%rsp), %rax
movb $0x1, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x4c(%rsp), %edi
callq 0xf690
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
movl %eax, %edx
callq 0x1b4b0
testb $0x1, %al
jne 0x48e83
jmp 0x48e9b
movl 0x3a2803(%rip), %esi    # 0x3eb68c
leaq 0x3c(%rsp), %rdi
callq 0x4ea50
movq 0x40(%rsp), %rax
movb $0x1, (%rax)
jmp 0x48e9d
testb $0x1, 0x4b(%rsp)
je 0x48f52
movq 0x50(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x4c(%rsp), %edi
callq 0xf690
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x11f10
cmpl $0x1, %eax
je 0x48f52
movq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x298e0
movl %eax, 0x4(%rsp)
movq 0x50(%rsp), %rdi
movl $0x1, %esi
callq 0x298e0
movl 0x4(%rsp), %edi
movl %eax, %esi
callq 0x1b320
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x4c(%rsp), %edi
callq 0xf690
movq 0x8(%rsp), %rdi
movl %eax, %esi
callq 0x347f0
movl 0x14(%rsp), %edi
movl %eax, %esi
callq 0x1b300
cmpl $0x0, %eax
jne 0x48f52
movl 0x4c(%rsp), %edi
callq 0x3e710
testb $0x1, %al
jne 0x48f52
movl 0x3a273c(%rip), %esi    # 0x3eb67c
leaq 0x3c(%rsp), %rdi
callq 0x4ea50
movq 0x40(%rsp), %rax
movb $0x1, (%rax)
cmpl $0x2, 0x3c(%rsp)
jge 0x48f62
movl 0x3c(%rsp), %eax
movl %eax, (%rsp)
jmp 0x48f6c
movl $0x2, %eax
movl %eax, (%rsp)
jmp 0x48f6c
movl (%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)