// File: ATOMIC-LICHESS[P]ATOMKRAFT/evaluate.cpp
// Function: Score (anonymous namespace)::evaluate_king<(Color)0, false, true>(Position const&, (anonymous namespace)::EvalInfo&, Value*)
Score evaluate_king(const Position& pos, EvalInfo& ei, Value margins[]) {

    const BitCountType Max15 = HasPopCnt ? CNT_POPCNT : CpuIs64Bit ? CNT64_MAX15 : CNT32_MAX15;
    const Color Them = (Us == WHITE ? BLACK : WHITE);

    Bitboard undefended, b, b1, b2, safe;
    int attackUnits;
    const Square ksq = pos.king_square(Us);
    
    
    // King shelter
    Score score = ei.pi->king_shelter<Us>(pos, ksq);
    
    STARTNEW
    //if (useImprovements) {
		// penalty for every own piece adjacent to the king
		Bitboard adjacent_bb = pos.attacks_from(WK, ksq) & pos.pieces_of_color(Us);
		if (adjacent_bb) {
			int penalty = count_1s<Max15>(adjacent_bb) * 2 * AdjacencyPenalty;
			score += make_score(penalty, penalty);
		}
    //}
    ENDNEW
    
    // King safety. This is quite complicated, and is almost certainly far
    // from optimally tuned.
    OLD     if (   ei.kingAttackersCount[Them] >= 2
            && ei.kingAdjacentZoneAttacksCount[Them]) {}
    
    NEW if (   ei.kingAttackersCount[Them] >= 1
        && ei.kingAdjacentZoneAttacksCount[Them])
    {
        // Find the attacked squares around the king which has no defenders
        // apart from the king itself
        undefended = ei.attackedBy[Them][0] & ei.attackedBy[Us][KING];
        
        
        NEW // in atomic there is no defense of squares near the king
        OLD undefended &= ~(  ei.attackedBy[Us][PAWN]   | ei.attackedBy[Us][KNIGHT]
                        | ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK]
                        | ei.attackedBy[Us][QUEEN]);

        // Initialize the 'attackUnits' variable, which is used later on as an
        // index to the KingDangerTable[] array. The initial value is based on
        // the number and types of the enemy's attacking pieces, the number of
        // attacked and undefended squares around our king, the square of the
        // king, and the quality of the pawn shelter.
        attackUnits =  Min(25, (ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) / 2)
                     + 3 * (ei.kingAdjacentZoneAttacksCount[Them] + count_1s<Max15>(undefended))
                     + InitKingDanger[relative_square(Us, ksq)]
                     - mg_value(ei.pi->king_shelter<Us>(pos, ksq)) / 32;

        // Analyse enemy's safe queen contact checks. First find undefended
        // squares around the king attacked by enemy queen...
        b = undefended & ei.attackedBy[Them][QUEEN] & ~pos.pieces_of_color(Them);
        if (b)
        {
        	NEW // this is not correct since the we are the side to move and can prevent this
        	//NEW // contact check by a queen almost always ends in checkmate
        	//NEW score -= make_score(QueenValueMidgame, QueenValueEndgame);
        	
            STARTOLD
        	// ...then remove squares not supported by another enemy piece
            b &= (  ei.attackedBy[Them][PAWN]   | ei.attackedBy[Them][KNIGHT]
                  | ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK]);
        	ENDOLD
        	
        	
            if (b) {
                attackUnits +=  QueenContactCheckBonus
                              * count_1s<Max15>(b)
                              * (Them == pos.side_to_move() ? 2 : 1);
                
                STARTNEW
                //if (useImprovements) {
                	
				// if opponent can contact check we are almost lost,
				// we are not if we can explode opponents king
				if (Them == pos.side_to_move()) {
					Bitboard is_expl_threat = ei.attackedBy[Us][0] 
											& ei.attackedBy[Them][KING] 
											& pos.pieces_of_color(Them);
					if (   !is_expl_threat 
						&&  square_dist(pos.king_square(Us), pos.king_square(Them)) > 1) {
						score -= make_score(QueenValueMidgame, QueenValueMidgame);
					}
				}
                //}
                ENDNEW
            }
            
        }

        // Analyse enemy's safe rook contact checks. First find undefended
        // squares around the king attacked by enemy rooks...
        b = undefended & ei.attackedBy[Them][ROOK] & ~pos.pieces_of_color(Them);

        // Consider only squares where the enemy rook gives check
        b &= RookPseudoAttacks[ksq];

        if (b)
        {
        	//NEW // contact check by a rook almost always ends in at least stalemate
        	//NEW score -= make_score(RookValueMidgame, RookValueEndgame);
        	
        	STARTOLD
        	// ...then remove squares not supported by another enemy piece
        	b &= (  ei.attackedBy[Them][PAWN]   | ei.attackedBy[Them][KNIGHT]
                  | ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][QUEEN]);
        	ENDOLD
            if (b) {
                attackUnits +=  RookContactCheckBonus
                              * count_1s<Max15>(b)
                              * (Them == pos.side_to_move() ? 2 : 1);
                
                STARTNEW
                //if (useImprovements) {
                
				// if opponent can contact check we are almost lost,
				// we are not if we can explode opponents king
				if (Them == pos.side_to_move()) {
					Bitboard is_expl_threat = ei.attackedBy[Us][0] 
											& ei.attackedBy[Them][KING] 
											& pos.pieces_of_color(Them);
					if (   !is_expl_threat 
						&&  square_dist(pos.king_square(Us), pos.king_square(Them)) > 1) {
						score -= make_score(RookValueMidgame, RookValueMidgame);
					}
				}
                //}
                ENDNEW
            }
            
        }

        // Analyse enemy's safe distance checks for sliders and knights
        safe = ~(pos.pieces_of_color(Them) | ei.attackedBy[Us][0]);

        b1 = pos.attacks_from<ROOK>(ksq) & safe;
        b2 = pos.attacks_from<BISHOP>(ksq) & safe;

        // Enemy queen safe checks
        b = (b1 | b2) & ei.attackedBy[Them][QUEEN];
        if (b)
            attackUnits += QueenCheckBonus * count_1s<Max15>(b);

        // Enemy rooks safe checks
        b = b1 & ei.attackedBy[Them][ROOK];
        if (b)
            attackUnits += RookCheckBonus * count_1s<Max15>(b);

        // Enemy bishops safe checks
        b = b2 & ei.attackedBy[Them][BISHOP];
        if (b)
            attackUnits += BishopCheckBonus * count_1s<Max15>(b);

        // Enemy knights safe checks
        b = pos.attacks_from<KNIGHT>(ksq) & ei.attackedBy[Them][KNIGHT] & safe;
        if (b)
            attackUnits += KnightCheckBonus * count_1s<Max15>(b);

        // To index KingDangerTable[] attackUnits must be in [0, 99] range
        attackUnits = Min(99, Max(0, attackUnits));

        // Finally, extract the king danger score from the KingDangerTable[]
        // array and subtract the score from evaluation. Set also margins[]
        // value that will be used for pruning because this value can sometimes
        // be very big, and so capturing a single attacking piece can therefore
        // result in a score change far bigger than the value of the captured piece.
        score -= KingDangerTable[Us][attackUnits];
        margins[Us] += mg_value(KingDangerTable[Us][attackUnits]);
    } 
    
    STARTNEW
    // even in the endgame we may still need to calculate some king safety
    // unfortunately the code here is redundant
    else {
    	undefended = ei.attackedBy[Us][KING];
    	
        // Analyse enemy's safe queen contact checks. First find undefended
        // squares around the king attacked by enemy queen...
        b = undefended & ei.attackedBy[Them][QUEEN] & ~pos.pieces_of_color(Them);
        if (b) {
        	// if opponent can contact check we are almost lost,
        	// we are not if we can explode opponents king
        	if (Them == pos.side_to_move()) {
        		Bitboard is_expl_threat = ei.attackedBy[Us][0] 
        		                        & ei.attackedBy[Them][KING] 
        		                        & pos.pieces_of_color(Them);
				if (   !is_expl_threat 
					&&  square_dist(pos.king_square(Us), pos.king_square(Them)) > 1) {
        			score -= make_score(QueenValueMidgame, QueenValueMidgame);
        		}
        	}
        }

        // Analyse enemy's safe rook contact checks. First find undefended
        // squares around the king attacked by enemy rooks...
        b = undefended & ei.attackedBy[Them][ROOK] & ~pos.pieces_of_color(Them);

        // Consider only squares where the enemy rook gives check
        b &= RookPseudoAttacks[ksq];

        if (b) {
        	// if opponent can contact check we are almost lost,
        	// we are not if we can explode opponents king
        	if (Them == pos.side_to_move()) {
        		Bitboard is_expl_threat = ei.attackedBy[Us][0] 
        		                        & ei.attackedBy[Them][KING] 
        		                        & pos.pieces_of_color(Them);
				if (   !is_expl_threat 
					&&  square_dist(pos.king_square(Us), pos.king_square(Them)) > 1) {
        			score -= make_score(RookValueMidgame, RookValueMidgame);
        		}
        	}
        }
    }
    ENDNEW

    if (Trace)
        TracedScores[Us][KING] = score;

    return score;
  }

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq %rdx, 0x110(%rsp)
movl $0x3, 0x10c(%rsp)
movl $0x1, 0x108(%rsp)
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0xd8(%rsp)
movq 0x118(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x120(%rsp), %rsi
movl 0xd8(%rsp), %edx
callq 0x29d70
movl %eax, 0xd4(%rsp)
movq 0x120(%rsp), %rdi
movl 0xd8(%rsp), %edx
movl $0x6, %esi
callq 0x38b30
movq %rax, 0x98(%rsp)
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x98(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xc8(%rsp)
cmpq $0x0, 0xc8(%rsp)
je 0x24f4e
movq 0xc8(%rsp), %rdi
callq 0x29a00
shll %eax
imull $-0x5, %eax, %eax
movl %eax, 0xc4(%rsp)
movl 0xc4(%rsp), %edi
movl 0xc4(%rsp), %esi
callq 0x27f40
movl %eax, %esi
leaq 0xd4(%rsp), %rdi
callq 0x29810
movq 0x118(%rsp), %rax
cmpl $0x1, 0xa4(%rax)
jl 0x2561b
movq 0x118(%rsp), %rax
cmpl $0x0, 0xb4(%rax)
je 0x2561b
movq 0x118(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x118(%rsp), %rcx
andq 0x40(%rcx), %rax
movq %rax, 0x100(%rsp)
movq 0x118(%rsp), %rax
movl 0xa4(%rax), %eax
movq 0x118(%rsp), %rcx
imull 0xac(%rcx), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0x19, %eax
cmpl %ecx, %eax
jge 0x24fd6
movl $0x19, %eax
movl %eax, 0x94(%rsp)
jmp 0x25002
movq 0x118(%rsp), %rax
movl 0xa4(%rax), %eax
movq 0x118(%rsp), %rcx
imull 0xac(%rcx), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x94(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x118(%rsp), %rax
movl 0xb4(%rax), %eax
movl %eax, 0x78(%rsp)
movq 0x100(%rsp), %rdi
callq 0x29a00
movl 0x78(%rsp), %ecx
movl %eax, %edx
movl 0x7c(%rsp), %eax
addl %edx, %ecx
imull $0x3, %ecx, %ecx
addl %ecx, %eax
movl %eax, 0x80(%rsp)
movl 0xd8(%rsp), %esi
xorl %edi, %edi
callq 0x1b380
movl %eax, %ecx
movl 0x80(%rsp), %eax
movslq %ecx, %rdx
leaq 0x3513b(%rip), %rcx     # 0x5a1a0
addl (%rcx,%rdx,4), %eax
movl %eax, 0x84(%rsp)
movq 0x118(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x120(%rsp), %rsi
movl 0xd8(%rsp), %edx
callq 0x29d70
movl %eax, %edi
callq 0x281d0
movl %eax, %edi
movl $0x20, %esi
callq 0x281b0
movl %eax, %ecx
movl 0x84(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xdc(%rsp)
movq 0x100(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x78(%rcx), %rax
movq %rax, 0x88(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x88(%rsp), %rax
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x2522e
cmpq $0x0, 0xf8(%rsp)
je 0x2522c
movq 0xf8(%rsp), %rdi
callq 0x29a00
imull $0xc, %eax, %eax
movl %eax, 0x74(%rsp)
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %esi
movl 0x74(%rsp), %eax
movl $0x1, %ecx
movl $0x2, %edx
cmpl %esi, %ecx
cmovel %edx, %ecx
imull %ecx, %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x2522a
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x118(%rsp), %rcx
andq 0x80(%rcx), %rax
movq %rax, 0x68(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x68(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0x25228
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0x64(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movl 0x64(%rsp), %edi
movl %eax, %esi
callq 0x1b280
cmpl $0x1, %eax
jle 0x25228
leaq 0x4736f(%rip), %rax     # 0x6c578
movl (%rax), %edi
leaq 0x47366(%rip), %rax     # 0x6c578
movl (%rax), %esi
callq 0x27f40
movl %eax, %esi
leaq 0xd4(%rsp), %rdi
callq 0x29ae0
jmp 0x2522a
jmp 0x2522c
jmp 0x2522e
movq 0x100(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x70(%rcx), %rax
movq %rax, 0x58(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x58(%rsp), %rax
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, 0xf8(%rsp)
movslq 0xd8(%rsp), %rcx
leaq 0x12e3e1(%rip), %rax    # 0x153660
movq (%rax,%rcx,8), %rax
andq 0xf8(%rsp), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x253c5
cmpq $0x0, 0xf8(%rsp)
je 0x253c3
movq 0xf8(%rsp), %rdi
callq 0x29a00
shll $0x3, %eax
movl %eax, 0x54(%rsp)
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %esi
movl 0x54(%rsp), %eax
movl $0x1, %ecx
movl $0x2, %edx
cmpl %esi, %ecx
cmovel %edx, %ecx
imull %ecx, %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x253c1
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x118(%rsp), %rcx
andq 0x80(%rcx), %rax
movq %rax, 0x48(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x48(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
jne 0x253bf
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0x44(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movl 0x44(%rsp), %edi
movl %eax, %esi
callq 0x1b280
cmpl $0x1, %eax
jle 0x253bf
leaq 0x471d0(%rip), %rax     # 0x6c570
movl (%rax), %edi
leaq 0x471c7(%rip), %rax     # 0x6c570
movl (%rax), %esi
callq 0x27f40
movl %eax, %esi
leaq 0xd4(%rsp), %rdi
callq 0x29ae0
jmp 0x253c1
jmp 0x253c3
jmp 0x253c5
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq 0x118(%rsp), %rcx
orq 0x10(%rcx), %rax
xorq $-0x1, %rax
movq %rax, 0xe0(%rsp)
movq 0x120(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x29d40
andq 0xe0(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0x120(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x1b550
andq 0xe0(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
orq 0xe8(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x78(%rcx), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x25484
movq 0xf8(%rsp), %rdi
callq 0x29a00
imull $0x3, %eax, %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0xf0(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x70(%rcx), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x254c8
movq 0xf8(%rsp), %rdi
callq 0x29a00
shll %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0xe8(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x68(%rcx), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x2550d
movq 0xf8(%rsp), %rdi
callq 0x29a00
shll $0x0, %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0x120(%rsp), %rdi
movl 0xd8(%rsp), %esi
callq 0x29aa0
movq 0x118(%rsp), %rcx
andq 0x60(%rcx), %rax
andq 0xe0(%rsp), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x25566
movq 0xf8(%rsp), %rdi
callq 0x29a00
shll $0x0, %eax
addl 0xdc(%rsp), %eax
movl %eax, 0xdc(%rsp)
xorl %eax, %eax
cmpl 0xdc(%rsp), %eax
jge 0x2557e
movl 0xdc(%rsp), %eax
movl %eax, 0x40(%rsp)
jmp 0x25586
xorl %eax, %eax
movl %eax, 0x40(%rsp)
jmp 0x25586
movl 0x40(%rsp), %ecx
movl $0x63, %eax
cmpl %ecx, %eax
jge 0x2559e
movl $0x63, %eax
movl %eax, 0x3c(%rsp)
jmp 0x255c6
xorl %eax, %eax
cmpl 0xdc(%rsp), %eax
jge 0x255b6
movl 0xdc(%rsp), %eax
movl %eax, 0x38(%rsp)
jmp 0x255be
xorl %eax, %eax
movl %eax, 0x38(%rsp)
jmp 0x255be
movl 0x38(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0xdc(%rsp)
movslq 0xdc(%rsp), %rcx
leaq 0x3bd4f0(%rip), %rax    # 0x3e2ad0
movl (%rax,%rcx,4), %esi
leaq 0xd4(%rsp), %rdi
callq 0x29ae0
movslq 0xdc(%rsp), %rcx
leaq 0x3bd4d1(%rip), %rax    # 0x3e2ad0
movl (%rax,%rcx,4), %edi
callq 0x281d0
movl %eax, %esi
movq 0x110(%rsp), %rdi
callq 0x29dd0
jmp 0x2588c
movq 0x118(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x78(%rcx), %rax
movq %rax, 0x30(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x30(%rsp), %rax
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x2574b
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x25749
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x118(%rsp), %rcx
andq 0x80(%rcx), %rax
movq %rax, 0x28(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x28(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xa8(%rsp)
jne 0x25747
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0x24(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movl 0x24(%rsp), %edi
movl %eax, %esi
callq 0x1b280
cmpl $0x1, %eax
jle 0x25747
leaq 0x46e50(%rip), %rax     # 0x6c578
movl (%rax), %edi
leaq 0x46e47(%rip), %rax     # 0x6c578
movl (%rax), %esi
callq 0x27f40
movl %eax, %esi
leaq 0xd4(%rsp), %rdi
callq 0x29ae0
jmp 0x25749
jmp 0x2574b
movq 0x100(%rsp), %rax
movq 0x118(%rsp), %rcx
andq 0x70(%rcx), %rax
movq %rax, 0x18(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, 0xf8(%rsp)
movslq 0xd8(%rsp), %rcx
leaq 0x12dec4(%rip), %rax    # 0x153660
movq (%rax,%rcx,8), %rax
andq 0xf8(%rsp), %rax
movq %rax, 0xf8(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x2588a
movq 0x120(%rsp), %rdi
callq 0xf5d0
movl %eax, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x25888
movq 0x118(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x118(%rsp), %rcx
andq 0x80(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x298c0
movq %rax, %rcx
movq 0x10(%rsp), %rax
andq %rcx, %rax
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0xa0(%rsp)
jne 0x25886
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1b250
movl %eax, 0xc(%rsp)
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1b250
movl 0xc(%rsp), %edi
movl %eax, %esi
callq 0x1b280
cmpl $0x1, %eax
jle 0x25886
leaq 0x46d09(%rip), %rax     # 0x6c570
movl (%rax), %edi
leaq 0x46d00(%rip), %rax     # 0x6c570
movl (%rax), %esi
callq 0x27f40
movl %eax, %esi
leaq 0xd4(%rsp), %rdi
callq 0x29ae0
jmp 0x25888
jmp 0x2588a
jmp 0x2588c
movl 0xd4(%rsp), %eax
movl %eax, 0x3bd1cf(%rip)    # 0x3e2a68
movl 0xd4(%rsp), %eax
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax,%rax)