// File: chhylp123[P]hifiasm/Correct.cpp
// Function: process_boundary(overlap_region_alloc*, All_reads*, Correct_dumy*, Graph*, Graph*, Cigar_record*, long long, Round2_alignment*, window_list_alloc*)
int process_boundary(overlap_region_alloc* overlap_list, All_reads* R_INF, Correct_dumy* dumy, Graph* g, Graph* DAGCon,
Cigar_record* current_cigar, long long uncorrected_window_start, Round2_alignment* second_round, window_list_alloc* win_ciagr_buf)
{
    char* r_string = dumy->corrected_read;
    long long r_total_length = current_cigar->new_read_length;
    long long corrected_window_start, corrected_window_end;
    int extra_begin;
    int extra_end;

    if(dumy->last_boundary_length == 0)
    {
        return 0;
    }

    corrected_window_start = dumy->last_boundary_length - WINDOW_BOUNDARY/2;
    corrected_window_end = dumy->last_boundary_length + WINDOW_BOUNDARY/2 - 1;

    if(corrected_window_start < 0)
    {
        corrected_window_start = 0;
    }

    if (corrected_window_end >= current_cigar->new_read_length)
    {
        corrected_window_end = current_cigar->new_read_length - 1;
    }

    clear_Graph(g);
    clear_Graph(DAGCon);

    long long x_start, x_end;
    long long x_length, x_len, o_len;
    int threshold; 
    long long Window_Len;
    char* x_string = NULL;
    char* y_string = NULL;
    char* backbone = NULL;
    long long backbone_length;
    long long i;
    long long y_start, y_length;
    long long overlapID, windowID;
    long long startNodeID, endNodeID, currentNodeID;
    int end_site;
    unsigned int error;
    int real_y_start;
    long long total_error = 0;

    backbone = r_string + corrected_window_start;
    backbone_length = corrected_window_end - corrected_window_start + 1;
    addUnmatchedSeqToGraph(g, backbone, backbone_length, &startNodeID, &endNodeID);


    long long correct_x_pos_s;
    long long matched_coverage = 0;
    for (i = 0; i < (long long)dumy->length; i++)
    {
        overlapID = dumy->overlapID[i];
        correct_x_pos_s = (overlap_list->list[overlapID].x_pos_s / WINDOW) * WINDOW;
        windowID = (uncorrected_window_start - correct_x_pos_s) / WINDOW;

        ///skip if window is unmatched
        if (overlap_list->list[overlapID].w_list.a[windowID].y_end == -1)
        {
            continue;
        }

        x_start = overlap_list->list[overlapID].w_list.a[windowID].x_start;
        y_start = overlap_list->list[overlapID].w_list.a[windowID].y_start;

        


        /**
         * There are total 3 cases:
         * 1.  this window of x is overlapped fully by y
         *     x: ------|------|---------
         *     y: ------|------|---------
         *     in this case, x_start == uncorrected_window_start, x_length == WINDOW
         * 2.  the suiffx of x's window is overlapped by the prefix of y
         *     x: ------|------|---------
         *               y: |--|-----------  
         *      in this case, x_start > uncorrected_window_start, x_length < WINDOW
         *      this overlap is useless
         * 3.  the prefix of x's window is overlapped by y (see last window)
         *      x: |------|------|-----|---
         *                 y: |--|-----|------  
         *      or
         *          x: |------|------|-----|----
         *        y: --|------|------|-----|--
         *      
         *      in this case, x_start == uncorrected_window_start, x_length < WINDOW
         * 
         *      case 1 and case 3 are useful, while case 2 is useless
         * **/

        ///case 1 and case 3 are useful
        if(x_start == uncorrected_window_start)
        {
            extra_begin = extra_end = 0;
            x_start = corrected_window_start;
            x_end = corrected_window_end;
            x_len = x_end - x_start + 1;
            threshold = x_len * asm_opt.max_ov_diff_ec;
            /****************************may have bugs********************************/
            threshold = Adjust_Threshold(threshold, x_len);
            /****************************may have bugs********************************/
            ///y_start may less than 0
            y_start = y_start - WINDOW_BOUNDARY/2;

            ///in fact, we don't need this line, just worry for bug
            if(y_start < 0)
            {
                continue;
            }

            Window_Len = x_len + (threshold << 1);

            error =(unsigned int)-1;
            if(determine_overlap_region(threshold, y_start, overlap_list->list[overlapID].y_id, Window_Len, Get_READ_LENGTH((*R_INF), overlap_list->list[overlapID].y_id),
            &extra_begin, &extra_end, &y_start, &o_len))
            {
                fill_subregion(dumy->overlap_region, y_start, o_len, overlap_list->list[overlapID].y_pos_strand, 
                R_INF, overlap_list->list[overlapID].y_id, extra_begin, extra_end);

                x_string = r_string + x_start;
                y_string = dumy->overlap_region;

                ///both end site and real_y_start have extra_begin
                ///should be improved, since most of overlaps are exact overlaps
                ///we can do it quickly
                end_site = Reserve_Banded_BPM_PATH(y_string, Window_Len, x_string, x_len, threshold, &error, &real_y_start,
                        &(dumy->path_length), dumy->matrix_bit, dumy->path, -1, -1);
            }

            

            ///try to calculate using higher threshold
            if(error==(unsigned int)-1)
            {
                extra_begin = extra_end = 0;
                x_start = corrected_window_start;
                x_end = corrected_window_end;
                x_len = x_end - x_start + 1;
                threshold = threshold * 2;
                /****************************may have bugs********************************/
                threshold = Adjust_Threshold(threshold, x_len);
                /****************************may have bugs********************************/
                if(x_len >= 300 && threshold < THRESHOLD_MAX_SIZE)
                {
                    threshold = THRESHOLD_MAX_SIZE;
                }
                if(threshold > THRESHOLD_MAX_SIZE)
                {
                    threshold = THRESHOLD_MAX_SIZE;
                }
                Window_Len = x_len + (threshold << 1);
                y_start = overlap_list->list[overlapID].w_list.a[windowID].y_start - WINDOW_BOUNDARY/2;

                ///in fact, we don't need this line, just worry for bug
                if(y_start < 0)
                {
                    continue;
                }

                error =(unsigned int)-1;
                if(determine_overlap_region(threshold, y_start, overlap_list->list[overlapID].y_id, Window_Len, Get_READ_LENGTH((*R_INF), overlap_list->list[overlapID].y_id),
                &extra_begin, &extra_end, &y_start, &o_len))
                {
                    fill_subregion(dumy->overlap_region, y_start, o_len, overlap_list->list[overlapID].y_pos_strand, 
                    R_INF, overlap_list->list[overlapID].y_id, extra_begin, extra_end);

                    x_string = r_string + x_start;
                    y_string = dumy->overlap_region;

                    ///both end site and real_y_start have extra_begin
                    ///should be improved, since most of overlaps are exact overlaps
                    ///we can do it quickly
                    end_site = Reserve_Banded_BPM_PATH(y_string, Window_Len, x_string, x_len, threshold, &error, &real_y_start,
                            &(dumy->path_length), dumy->matrix_bit, dumy->path, -1, -1);
                }
            }

            if (error!=(unsigned int)-1)
            {

                

                total_error = total_error + error;
                matched_coverage++;
                win_ciagr_buf->a[0].x_start = x_start; win_ciagr_buf->a[0].x_end = x_end;
                win_ciagr_buf->c.n = 0;
                generate_cigar(dumy->path, dumy->path_length, &(win_ciagr_buf->a[0]), win_ciagr_buf, &real_y_start, &end_site, &error, x_string, x_len, y_string);  
                ///both end site and real_y_start have extra_begin
                real_y_start -= extra_begin;
                end_site -= extra_begin;

                y_length = end_site - real_y_start + 1;
                y_start = y_start + real_y_start;
                

                x_start = corrected_window_start;
                x_length = corrected_window_end - x_start + 1;

                ///here can be improved, make y_string = dumy->overlap_region + real_y_start + extra_begin
                recover_UC_Read_sub_region(dumy->overlap_region, y_start, y_length, overlap_list->list[overlapID].y_pos_strand, 
                R_INF, overlap_list->list[overlapID].y_id);

                x_string = r_string + x_start;
                y_string = dumy->overlap_region;

                currentNodeID = x_start - corrected_window_start;
                
                addmatchedSeqToGraph(g, currentNodeID, x_string, x_length, y_string, y_length, &(win_ciagr_buf->a[0]), win_ciagr_buf, startNodeID, endNodeID);
            }

        }///case 2 is useless
        else if(x_start != uncorrected_window_start)
        {
            continue;
        }        
    }


    if(matched_coverage >= MIN_COVERAGE_THRESHOLD)
    {
        ///if there are no error, we do not need correction
        if(total_error == 0)
        {
            return 0;
        }
        
        clear_Cigar_record(&(second_round->tmp_cigar));
        clear_Correct_dumy_pure(&(second_round->dumy));

        ///correct bases in [start_base, end_base]
        long long start_base = corrected_window_start + WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY;
        long long end_base = corrected_window_end - WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY;

        if(end_base > start_base)
        {
            ///note there is an additional "S" node
            ///and start from i-th node, we can correct (i+1)-th base
            /// so the condition when traversing graph is 
            ///(node >= start_base - corrected_window_start && node <= end_base - corrected_window_start)
            get_seq_from_Graph(g, DAGCon, &(second_round->dumy), &(second_round->tmp_cigar), backbone, 
            r_string, r_total_length, corrected_window_start);
            
            /**
            if(verify_cigar_2(backbone, backbone_length, second_round->dumy.corrected_read, 
                second_round->dumy.corrected_read_length, &(second_round->tmp_cigar), -1))
            {
                fprintf(stderr, "hahah\n");
            }
            **/
            
            merge_cigars(dumy, current_cigar, second_round, start_base, end_base,
            corrected_window_start, corrected_window_end);
            


        }
        
    }
    else
    {
        return 0;
    }

    return 1;
    
    
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3a82d
movl $0x0, -0xc(%rbp)
jmp 0x3b26e
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
subq $0xbb, %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
addq $0xbb, %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x3a864
movq $0x0, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movl 0x20(%rcx), %ecx
cmpq %rcx, %rax
jl 0x3a884
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2c330
movq -0x38(%rbp), %rdi
callq 0x2c330
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0x118(%rbp)
movq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x60(%rbp), %rax
subq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
leaq -0xf8(%rbp), %r8
callq 0x2c3c0
movq $0x0, -0x128(%rbp)
movq $0x0, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jge 0x3b18e
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl $0x177, %ecx            # imm = 0x177
xorl %edx, %edx
divl %ecx
imull $0x177, %eax, %eax      # imm = 0x177
movl %eax, %eax
movq %rax, -0x120(%rbp)
movq 0x10(%rbp), %rax
subq -0x120(%rbp), %rax
movl $0x177, %ecx            # imm = 0x177
cqto
idivq %rcx
movq %rax, -0xe8(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0xe8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
jne 0x3a9cc
jmp 0x3b177
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0xe8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0xe8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
cmpq 0x10(%rbp), %rax
jne 0x3b167
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
subq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
cvtsi2sdq -0x88(%rbp), %xmm0
leaq 0x389d7d(%rip), %rax    # 0x3c47f8
mulsd 0xc0(%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
jne 0x3aaad
cmpq $0x4, -0x88(%rbp)
jl 0x3aaad
movl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x3aab9
movl -0x94(%rbp), %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0xd0(%rbp), %rax
subq $0xbb, %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd0(%rbp)
jge 0x3aae8
jmp 0x3b177
movq -0x88(%rbp), %rax
movl -0x94(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movl $0xffffffff, -0x108(%rbp) # imm = 0xFFFFFFFF
movl -0x94(%rbp), %edi
movq -0xd0(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %edx
movq -0xa0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %r8
movq (%r8), %r8
imulq $0xa8, -0xe0(%rbp), %r9
addq %r9, %r8
movl 0x10(%r8), %r8d
movq (%rax,%r8,8), %r8
leaq -0x64(%rbp), %r9
leaq -0x68(%rbp), %r11
leaq -0xd0(%rbp), %r10
leaq -0x90(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x32290
cmpl $0x0, %eax
je 0x3aca1
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0xd0(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movb %al, %cl
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %r9
addq %r9, %rax
movl 0x10(%rax), %eax
movl %eax, %r9d
movl -0x64(%rbp), %r10d
movl -0x68(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xa0(%rbp), %rax
movl %eax, %esi
movq -0xa8(%rbp), %rdx
movq -0x88(%rbp), %rax
movl %eax, %ecx
movl -0x94(%rbp), %eax
movw %ax, %r8w
movq -0x28(%rbp), %r11
addq $0x7d70, %r11           # imm = 0x7D70
movq -0x28(%rbp), %r10
addq $0xff0, %r10            # imm = 0xFF0
movq -0x28(%rbp), %rax
addq $0xa14, %rax            # imm = 0xA14
leaq -0x108(%rbp), %r9
leaq -0x10c(%rbp), %rbx
movzwl %r8w, %r8d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
callq 0x9e3d0
movl %eax, -0x104(%rbp)
cmpl $-0x1, -0x108(%rbp)
jne 0x3af5a
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
subq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movl -0x94(%rbp), %eax
shll %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
jne 0x3ad0d
cmpq $0x4, -0x88(%rbp)
jl 0x3ad0d
movl $0x1, %eax
movl %eax, -0x140(%rbp)
jmp 0x3ad19
movl -0x94(%rbp), %eax
movl %eax, -0x140(%rbp)
movl -0x140(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpq $0x12c, -0x88(%rbp) # imm = 0x12C
jl 0x3ad45
cmpl $0x1f, -0x94(%rbp)
jge 0x3ad45
movl $0x1f, -0x94(%rbp)
cmpl $0x1f, -0x94(%rbp)
jle 0x3ad58
movl $0x1f, -0x94(%rbp)
movq -0x88(%rbp), %rax
movl -0x94(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0xe8(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
subl $0xbb, %eax
cltq
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd0(%rbp)
jge 0x3adbb
jmp 0x3b177
movl $0xffffffff, -0x108(%rbp) # imm = 0xFFFFFFFF
movl -0x94(%rbp), %edi
movq -0xd0(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %edx
movq -0xa0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %r8
movq (%r8), %r8
imulq $0xa8, -0xe0(%rbp), %r9
addq %r9, %r8
movl 0x10(%r8), %r8d
movq (%rax,%r8,8), %r8
leaq -0x64(%rbp), %r9
leaq -0x68(%rbp), %r11
leaq -0xd0(%rbp), %r10
leaq -0x90(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x32290
cmpl $0x0, %eax
je 0x3af58
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0xd0(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movb %al, %cl
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %r9
addq %r9, %rax
movl 0x10(%rax), %eax
movl %eax, %r9d
movl -0x64(%rbp), %r10d
movl -0x68(%rbp), %eax
movzbl %cl, %ecx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x32160
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xa0(%rbp), %rax
movl %eax, %esi
movq -0xa8(%rbp), %rdx
movq -0x88(%rbp), %rax
movl %eax, %ecx
movl -0x94(%rbp), %eax
movw %ax, %r8w
movq -0x28(%rbp), %r11
addq $0x7d70, %r11           # imm = 0x7D70
movq -0x28(%rbp), %r10
addq $0xff0, %r10            # imm = 0xFF0
movq -0x28(%rbp), %rax
addq $0xa14, %rax            # imm = 0xA14
leaq -0x108(%rbp), %r9
leaq -0x10c(%rbp), %rbx
movzwl %r8w, %r8d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
callq 0x9e3d0
movl %eax, -0x104(%rbp)
jmp 0x3af5a
cmpl $-0x1, -0x108(%rbp)
je 0x3b165
movq -0x118(%rbp), %rax
movl -0x108(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x118(%rbp)
movq -0x128(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, (%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl %ecx, 0x4(%rax)
movq 0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq -0x28(%rbp), %rax
movl 0x7d70(%rax), %esi
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq 0x20(%rbp), %rcx
movq -0xa8(%rbp), %r11
movq -0x88(%rbp), %rax
movl %eax, %r10d
movq -0xb0(%rbp), %rax
leaq -0x10c(%rbp), %r8
leaq -0x104(%rbp), %r9
leaq -0x108(%rbp), %rbx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x9f0f0
movl -0x64(%rbp), %ecx
movl -0x10c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10c(%rbp)
movl -0x64(%rbp), %ecx
movl -0x104(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x104(%rbp)
movl -0x104(%rbp), %eax
subl -0x10c(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rax
movslq -0x10c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
subq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0xe0(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0xe0(%rbp), %r9
addq %r9, %rcx
movl 0x10(%rcx), %ecx
movl %ecx, %r9d
movzbl %al, %ecx
callq 0x9a30
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb0(%rbp)
movq -0x70(%rbp), %rax
subq -0x58(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x30(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0xb0(%rbp), %r8
movq -0xd8(%rbp), %r9
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rbx
movq 0x20(%rbp), %r11
movq -0xf0(%rbp), %r10
movq -0xf8(%rbp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x2c4e0
jmp 0x3b175
movq -0x70(%rbp), %rax
cmpq 0x10(%rbp), %rax
je 0x3b173
jmp 0x3b177
jmp 0x3b175
jmp 0x3b177
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x3a91f
cmpq $0x3, -0x128(%rbp)
jl 0x3b25e
cmpq $0x0, -0x118(%rbp)
jne 0x3b1b2
movl $0x0, -0xc(%rbp)
jmp 0x3b26e
movq 0x18(%rbp), %rdi
addq $0x8dc0, %rdi           # imm = 0x8DC0
callq 0x31d60
movq 0x18(%rbp), %rdi
callq 0x31d00
movq -0x58(%rbp), %rax
addq $0x19, %rax
movq %rax, -0x130(%rbp)
movq -0x60(%rbp), %rax
subq $0x19, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
cmpq -0x130(%rbp), %rax
jle 0x3b25c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq 0x18(%rbp), %rcx
addq $0x8dc0, %rcx           # imm = 0x8DC0
movq -0xb8(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x50(%rbp), %r10
movq -0x58(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x39860
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x130(%rbp), %rcx
movq -0x138(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %rax
movq %rax, (%rsp)
callq 0x3a1d0
jmp 0x3b267
movl $0x0, -0xc(%rbp)
jmp 0x3b26e
movl $0x1, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)