// File: lukasz-wiecaszek[P]h264iframedecoder/h264_parser.cpp
// Function: ymn::h264_parser::parse_slice_header(ymn::istream<0>&, unsigned int, unsigned int)
h264_parser_status_e h264_parser::parse_slice_header(istream_be& s, uint32_t nal_ref_idc, uint32_t nal_unit_type)
{
    h264_parser_status_e retval = h264_parser_status_e::NAL_UNIT_CORRUPTED;

    do {
        uint32_t pic_parameter_set_id;
        uint32_t seq_parameter_set_id;
        uint32_t slice_type;
        bool status;

        h264::slice_header& slice_header = m_slice_header;
        slice_header.reset();

        slice_header.nal_ref_idc = nal_ref_idc;
        slice_header.nal_unit_type = nal_unit_type;

        s.read_exp_golomb_u(slice_header.first_mb_in_slice);

        if (!CHK_EXPR(s.read_exp_golomb_u(slice_type), std::cout) ||
            !CHK_RANGE(slice_type, 0U, 9U, std::cout)) {
            s.mark_corrupted();
            break;
        }

        slice_header.slice_type = slice_type;

        if (!CHK_EXPR(s.read_exp_golomb_u(pic_parameter_set_id), std::cout) ||
            !CHK_RANGE(pic_parameter_set_id, 0U, static_cast<unsigned>(H264_PARSER_MAX_NUMBER_OF_PPS - 1), std::cout)) {
            s.mark_corrupted();
            break;
        }

        h264::pps& pps = m_pps_table[pic_parameter_set_id];
        if (!pps.is_valid()) {
            std::cout << "error: slice header refers to pps #" << pic_parameter_set_id << " which is not valid";
            std::cout << std::endl;
            break;
        }

        seq_parameter_set_id = pps.seq_parameter_set_id;

        h264::sps& sps = m_sps_table[seq_parameter_set_id];
        if (!sps.is_valid()) {
            std::cout << "error: pps #" << pic_parameter_set_id;
            std::cout << " refers to sps #" << seq_parameter_set_id << " which is not valid";
            std::cout << std::endl;
            break;
        }

        slice_header.pic_parameter_set_id = pic_parameter_set_id;
        slice_header.set_active_pps(&m_pps_table[pic_parameter_set_id]);

        if (sps.separate_colour_plane_flag)
            s.read_bits(2, slice_header.colour_plane_id);
        else
            slice_header.colour_plane_id = 3;//TODO: #define INVALID_COLOUR_PLANE_ID

        s.read_bits(sps.log2_max_frame_num_minus4 + 4, slice_header.frame_num);

        if (!sps.frame_mbs_only_flag) {
            s.read_bits(1, slice_header.field_pic_flag);
            if (slice_header.field_pic_flag)
                s.read_bits(1, slice_header.bottom_field_flag);
        }
        else
            slice_header.field_pic_flag = 0;

        if (nal_unit_type == 5)
            s.read_exp_golomb_u(slice_header.idr_pic_id);

        if (sps.pic_order_cnt_type == 0) {
            s.read_bits(sps.t0.log2_max_pic_order_cnt_lsb_minus4 + 4, slice_header.pic_order_cnt_lsb);
            if (pps.bottom_field_pic_order_in_frame_present_flag && !slice_header.field_pic_flag)
                s.read_exp_golomb_s(slice_header.delta_pic_order_cnt_bottom);
        }

        if (sps.pic_order_cnt_type == 1 && !sps.t1.delta_pic_order_always_zero_flag) {
            s.read_exp_golomb_s(slice_header.delta_pic_order_cnt[0]);
            if (pps.bottom_field_pic_order_in_frame_present_flag && !slice_header.field_pic_flag)
                s.read_exp_golomb_s(slice_header.delta_pic_order_cnt[1]);
        }

        if (pps.redundant_pic_cnt_present_flag)
            s.read_exp_golomb_u(slice_header.redundant_pic_cnt);

        if (h264::slice_type_e::B == slice_type)
            s.read_bits(1, slice_header.direct_spatial_mv_pred_flag);

        if (h264::slice_type_e::P  == slice_type ||
            h264::slice_type_e::SP == slice_type ||
            h264::slice_type_e::B  == slice_type) {
            s.read_bits(1, slice_header.num_ref_idx_active_override_flag);
            if (slice_header.num_ref_idx_active_override_flag) {
                if (!CHK_EXPR(s.read_exp_golomb_u(slice_header.num_ref_idx_l0_active_minus1), std::cout) ||
                    !CHK_STRUCT_RANGE(slice_header, num_ref_idx_l0_active_minus1, 0U, 31U, std::cout)) {
                    s.mark_corrupted();
                    break;
                }
                if (h264::slice_type_e::B == slice_type)
                    if (!CHK_EXPR(s.read_exp_golomb_u(slice_header.num_ref_idx_l1_active_minus1), std::cout) ||
                        !CHK_STRUCT_RANGE(slice_header, num_ref_idx_l1_active_minus1, 0U, 31U, std::cout)) {
                        s.mark_corrupted();
                        break;
                    }
            }
            else {
                slice_header.num_ref_idx_l0_active_minus1 = pps.num_ref_idx_l0_default_active_minus1;
                if (h264::slice_type_e::B == slice_type)
                    slice_header.num_ref_idx_l1_active_minus1 = pps.num_ref_idx_l1_default_active_minus1;
            }
        }

        if ((h264::slice_type_e::I != slice_type) &&
            (h264::slice_type_e::SI != slice_type)) {
            status = parse_ref_pic_list_modification(s, slice_header.rplm_l0);
            if (!status)
                break;
        }

        if (h264::slice_type_e::B == slice_type) {
            status = parse_ref_pic_list_modification(s, slice_header.rplm_l1);
            if (!status)
                break;
        }

        if ((pps.weighted_pred_flag && ((h264::slice_type_e::P == slice_type) || (h264::slice_type_e::SP == slice_type))) ||
            (pps.weighted_bipred_idc == 1 && (h264::slice_type_e::B == slice_type))) {
            h264::pred_weight_table& pwt = slice_header.pwt;

            pwt.slice_type = h264::to_slice_type_e(slice_type);
            pwt.chroma_components_present = sps.chroma_format_idc && !sps.separate_colour_plane_flag;
            pwt.num_ref_idx_l0_active_minus1 = slice_header.num_ref_idx_l0_active_minus1;
            pwt.num_ref_idx_l1_active_minus1 = slice_header.num_ref_idx_l1_active_minus1;

            status = parse_pred_weight_table(s, pwt);
            if (!status)
                break;
        }

        if (nal_ref_idc != 0) {
            if (nal_unit_type == 5)
                parse_dec_ref_pic_marking_idr(s, slice_header.drpm_idr);
            else
                parse_dec_ref_pic_marking_nonidr(s, slice_header.drpm_nonidr);
        }

        if ((pps.entropy_coding_mode_flag) &&
            (h264::slice_type_e::I != slice_type) && (h264::slice_type_e::SI != slice_type)) {
            if (!CHK_EXPR(s.read_exp_golomb_u(slice_header.cabac_init_idc), std::cout) ||
                !CHK_STRUCT_RANGE(slice_header, cabac_init_idc, 0U, 2U, std::cout)) {
                s.mark_corrupted();
                break;
            }
        }

        if (!CHK_EXPR(s.read_exp_golomb_s(slice_header.slice_qp_delta), std::cout) ||
            !CHK_STRUCT_RANGE(slice_header, slice_qp_delta,
                -26 - 6 * static_cast<int>(sps.bit_depth_luma_minus8) - pps.pic_init_qp_minus26,
                 25 - pps.pic_init_qp_minus26, std::cout)) {
            s.mark_corrupted();
            break;
        }

        if ((h264::slice_type_e::SI == slice_type) && (h264::slice_type_e::SP == slice_type)) {
            if (h264::slice_type_e::SP == slice_type)
                s.read_bits(1, slice_header.sp_for_switch_flag);
            s.read_exp_golomb_s(slice_header.slice_qs_delta);
        }

        if (pps.deblocking_filter_control_present_flag) {
            s.read_exp_golomb_u(slice_header.disable_deblocking_filter_idc);
            if (slice_header.disable_deblocking_filter_idc != 1) {
                s.read_exp_golomb_s(slice_header.slice_alpha_c0_offset_div2);
                s.read_exp_golomb_s(slice_header.slice_beta_offset_div2);
            }
        }

        if ((pps.num_slice_groups_minus1 > 0) &&
            ((pps.slice_group_map_type >= 3) && (pps.slice_group_map_type <= 5))) {
            s.read_bits(
                ilog2(pps.t2.slice_group_change_rate_minus1 + 1),
                slice_header.slice_group_change_cycle);
        }

        if (s.status() != ISTREAM_STATUS_OK)
            break;

        set_slice_data(s);

        slice_header.set_valid(true);
        retval = h264_parser_status_e::SLICE_PARSED;
    } while (0);

    return retval;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl %edx, 0x54(%rsp)
movl %ecx, 0x50(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x2, 0x4c(%rsp)
movq 0x10(%rsp), %rax
addq $0x87960, %rax          # imm = 0x87960
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17530
movl 0x54(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0xc(%rax)
movl 0x50(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x14, %rsi
callq 0x17200
movq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0x1011f(%rip), %rdi     # 0x25648
movq 0x18a90(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x1553b
jmp 0x1555d
movl 0x40(%rsp), %esi
leaq 0xebe9(%rip), %rdi      # 0x2412f
xorl %edx, %edx
movl $0x9, %ecx
movq 0x18a6c(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x1556c
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
movl 0x40(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x18(%rax)
movq 0x58(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0xfe21(%rip), %rdi      # 0x253b5
movq 0x18a25(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x155a6
jmp 0x155c8
movl 0x48(%rsp), %esi
leaq 0xe4f3(%rip), %rdi      # 0x23aa4
xorl %edx, %edx
movl $0xff, %ecx
movq 0x18a01(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x155d7
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
movq 0x10(%rsp), %rax
addq $0x16130, %rax          # imm = 0x16130
movl 0x48(%rsp), %ecx
imulq $0x718, %rcx, %rcx      # imm = 0x718
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x16ec0
testb $0x1, %al
jne 0x15649
movq 0x189b6(%rip), %rdi     # 0x2dfc0
leaq 0x10057(%rip), %rsi     # 0x25668
callq 0x2140
movq %rax, %rdi
movl 0x48(%rsp), %esi
callq 0x2220
movq %rax, %rdi
leaq 0xfdd1(%rip), %rsi      # 0x253fd
callq 0x2140
movq 0x18988(%rip), %rdi     # 0x2dfc0
movq 0x18969(%rip), %rsi     # 0x2dfa8
callq 0x2180
jmp 0x15ec7
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x44(%rsp)
addq $0x128, %rax            # imm = 0x128
movl 0x44(%rsp), %ecx
imulq $0xb00, %rcx, %rcx      # imm = 0xB00
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x16ec0
testb $0x1, %al
jne 0x156e6
movq 0x18938(%rip), %rdi     # 0x2dfc0
leaq 0xfd50(%rip), %rsi      # 0x253df
callq 0x2140
movq %rax, %rdi
movl 0x48(%rsp), %esi
callq 0x2220
movq 0x18919(%rip), %rdi     # 0x2dfc0
leaq 0xfd3e(%rip), %rsi      # 0x253ec
callq 0x2140
movq %rax, %rdi
movl 0x44(%rsp), %esi
callq 0x2220
movq %rax, %rdi
leaq 0xfd34(%rip), %rsi      # 0x253fd
callq 0x2140
movq 0x188eb(%rip), %rdi     # 0x2dfc0
movq 0x188cc(%rip), %rsi     # 0x2dfa8
callq 0x2180
jmp 0x15ec7
movq 0x10(%rsp), %rsi
movl 0x48(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x30(%rsp), %rdi
addq $0x16130, %rsi          # imm = 0x16130
movl 0x48(%rsp), %eax
imulq $0x718, %rax, %rax      # imm = 0x718
addq %rax, %rsi
callq 0x17bc0
movq 0x20(%rsp), %rax
cmpl $0x0, 0x14(%rax)
je 0x1573b
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x20, %rdx
movl $0x2, %esi
callq 0x16f30
jmp 0x15747
movq 0x30(%rsp), %rax
movl $0x3, 0x20(%rax)
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2d8(%rax), %esi
addl $0x4, %esi
movq 0x30(%rsp), %rdx
addq $0x24, %rdx
callq 0x16f30
movq 0x20(%rsp), %rax
cmpl $0x0, 0x6fc(%rax)
jne 0x157b3
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x28, %rdx
movl $0x1, %esi
callq 0x16f30
movq 0x30(%rsp), %rax
cmpl $0x0, 0x28(%rax)
je 0x157b1
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x2c, %rdx
movl $0x1, %esi
callq 0x16f30
jmp 0x157bf
movq 0x30(%rsp), %rax
movl $0x0, 0x28(%rax)
cmpl $0x5, 0x50(%rsp)
jne 0x157d9
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x30, %rsi
callq 0x17200
movq 0x20(%rsp), %rax
cmpl $0x0, 0x2dc(%rax)
jne 0x15833
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2e0(%rax), %esi
addl $0x4, %esi
movq 0x30(%rsp), %rdx
addq $0x34, %rdx
callq 0x16f30
movq 0x28(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x15831
movq 0x30(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x15831
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x38, %rsi
callq 0x17690
jmp 0x15833
movq 0x20(%rsp), %rax
cmpl $0x1, 0x2dc(%rax)
jne 0x15891
movq 0x20(%rsp), %rax
cmpl $0x0, 0x2e0(%rax)
jne 0x15891
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x3c, %rsi
callq 0x17690
movq 0x28(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1588f
movq 0x30(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x1588f
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x3c, %rsi
addq $0x4, %rsi
callq 0x17690
jmp 0x15891
movq 0x28(%rsp), %rax
cmpl $0x0, 0x44c(%rax)
je 0x158b2
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x44, %rsi
callq 0x17200
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x158c6
jmp 0x158de
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x48, %rdx
movl $0x1, %esi
callq 0x16f30
movl 0x40(%rsp), %esi
xorl %edi, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15916
movl 0x40(%rsp), %esi
movl $0x3, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15916
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15916
jmp 0x15a61
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x4c, %rdx
movl $0x1, %esi
callq 0x16f30
movq 0x30(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x15a23
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x50, %rsi
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0xfd2f(%rip), %rdi      # 0x2568c
movq 0x1865c(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x1596f
jmp 0x15995
movq 0x30(%rsp), %rax
movl 0x50(%rax), %esi
leaq 0xfd4d(%rip), %rdi      # 0x256cb
xorl %edx, %edx
movl $0x1f, %ecx
movq 0x18634(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x159a4
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x159b8
jmp 0x15a21
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x54, %rsi
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0xfd1d(%rip), %rdi      # 0x256f5
movq 0x185e1(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x159ea
jmp 0x15a10
movq 0x30(%rsp), %rax
movl 0x54(%rax), %esi
leaq 0xfd3b(%rip), %rdi      # 0x25734
xorl %edx, %edx
movl $0x1f, %ecx
movq 0x185b9(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x15a1f
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
jmp 0x15a21
jmp 0x15a5f
movq 0x28(%rsp), %rax
movl 0x428(%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x50(%rax)
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15a4a
jmp 0x15a5d
movq 0x28(%rsp), %rax
movl 0x42c(%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x54(%rax)
jmp 0x15a5f
jmp 0x15a61
movl 0x40(%rsp), %esi
movl $0x2, %edi
callq 0x122e0
testb $0x1, %al
jne 0x15a75
jmp 0x15ab5
movl 0x40(%rsp), %esi
movl $0x4, %edi
callq 0x122e0
testb $0x1, %al
jne 0x15a89
jmp 0x15ab5
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq $0x58, %rdx
callq 0x133f0
andb $0x1, %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x3f(%rsp)
jne 0x15ab3
jmp 0x15ec7
jmp 0x15ab5
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15ac9
jmp 0x15af8
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq $0x88, %rdx
callq 0x133f0
andb $0x1, %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x3f(%rsp)
jne 0x15af6
jmp 0x15ec7
jmp 0x15af8
movq 0x28(%rsp), %rax
cmpl $0x0, 0x430(%rax)
je 0x15b27
movl 0x40(%rsp), %esi
xorl %edi, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15b50
movl 0x40(%rsp), %esi
movl $0x3, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15b50
movq 0x28(%rsp), %rax
cmpl $0x1, 0x434(%rax)
jne 0x15bf0
movl 0x40(%rsp), %esi
movl $0x1, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15b50
jmp 0x15bf0
movq 0x30(%rsp), %rax
addq $0xb8, %rax
movq %rax, 0x18(%rsp)
movl 0x40(%rsp), %edi
callq 0x15ed0
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x20(%rsp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x10(%rcx)
movb %al, 0xf(%rsp)
je 0x15b96
movq 0x20(%rsp), %rax
cmpl $0x0, 0x14(%rax)
setne %al
xorb $-0x1, %al
movb %al, 0xf(%rsp)
movq 0x10(%rsp), %rdi
movb 0xf(%rsp), %cl
movq 0x18(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x10(%rax)
movq 0x30(%rsp), %rax
movl 0x50(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x30(%rsp), %rax
movl 0x54(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x420(%rax)
movq 0x58(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x13550
andb $0x1, %al
movb %al, 0x3f(%rsp)
testb $0x1, 0x3f(%rsp)
jne 0x15bee
jmp 0x15ec7
jmp 0x15bf0
cmpl $0x0, 0x54(%rsp)
je 0x15c38
cmpl $0x5, 0x50(%rsp)
jne 0x15c1b
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq $0x8e0, %rdx            # imm = 0x8E0
callq 0x137f0
jmp 0x15c36
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq $0x8f8, %rdx            # imm = 0x8F8
callq 0x13870
jmp 0x15c38
movq 0x28(%rsp), %rax
cmpl $0x0, 0x14(%rax)
je 0x15ce1
movl 0x40(%rsp), %esi
movl $0x2, %edi
callq 0x122e0
testb $0x1, %al
jne 0x15c5e
jmp 0x15ce1
movl 0x40(%rsp), %esi
movl $0x4, %edi
callq 0x122e0
testb $0x1, %al
jne 0x15c72
jmp 0x15ce1
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x958, %rsi            # imm = 0x958
callq 0x17200
movzbl %al, %esi
andl $0x1, %esi
leaq 0xfac9(%rip), %rdi      # 0x2575e
movq 0x18324(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x15ca7
jmp 0x15cd0
movq 0x30(%rsp), %rax
movl 0x958(%rax), %esi
leaq 0xfad6(%rip), %rdi      # 0x2578f
xorl %edx, %edx
movl $0x2, %ecx
movq 0x182f9(%rip), %r8      # 0x2dfc0
callq 0x17330
testb $0x1, %al
jne 0x15cdf
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
jmp 0x15ce1
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x95c, %rsi            # imm = 0x95C
callq 0x17690
movzbl %al, %esi
andl $0x1, %esi
leaq 0xfaa7(%rip), %rdi      # 0x257ab
movq 0x182b5(%rip), %rdx     # 0x2dfc0
callq 0x17180
testb $0x1, %al
jne 0x15d16
jmp 0x15d63
movq 0x30(%rsp), %rax
movl 0x95c(%rax), %esi
movq 0x20(%rsp), %rax
imull $0x6, 0x18(%rax), %eax
movl $0xffffffe6, %edx       # imm = 0xFFFFFFE6
subl %eax, %edx
movq 0x28(%rsp), %rax
subl 0x438(%rax), %edx
movq 0x28(%rsp), %rax
movl $0x19, %ecx
subl 0x438(%rax), %ecx
leaq 0xfa89(%rip), %rdi      # 0x257dc
movq 0x18266(%rip), %r8      # 0x2dfc0
callq 0x17810
testb $0x1, %al
jne 0x15d72
movq 0x58(%rsp), %rdi
callq 0x17130
jmp 0x15ec7
movl 0x40(%rsp), %esi
movl $0x4, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15d86
jmp 0x15ddf
movl 0x40(%rsp), %esi
movl $0x3, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15d9a
jmp 0x15ddf
movl 0x40(%rsp), %esi
movl $0x3, %edi
callq 0x122c0
testb $0x1, %al
jne 0x15dae
jmp 0x15dc9
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x960, %rdx            # imm = 0x960
movl $0x1, %esi
callq 0x16f30
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x964, %rsi            # imm = 0x964
callq 0x17690
movq 0x28(%rsp), %rax
cmpl $0x0, 0x444(%rax)
je 0x15e3f
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x968, %rsi            # imm = 0x968
callq 0x17200
movq 0x30(%rsp), %rax
cmpl $0x1, 0x968(%rax)
je 0x15e3d
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x96c, %rsi            # imm = 0x96C
callq 0x17690
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x970, %rsi            # imm = 0x970
callq 0x17690
jmp 0x15e3f
movq 0x28(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jbe 0x15e90
movq 0x28(%rsp), %rax
cmpl $0x3, 0x20(%rax)
jb 0x15e90
movq 0x28(%rsp), %rax
cmpl $0x5, 0x20(%rax)
ja 0x15e90
movq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rax
movl 0x28(%rax), %edi
addl $0x1, %edi
callq 0x15ef0
movq (%rsp), %rdi
movl %eax, %esi
movq 0x30(%rsp), %rdx
addq $0x974, %rdx            # imm = 0x974
callq 0x16f30
movq 0x58(%rsp), %rdi
callq 0x17150
cmpl $0x0, %eax
je 0x15ea1
jmp 0x15ec7
movq 0x10(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x16920
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq 0x17160
movl $0x7, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
addq $0x68, %rsp
retq