data/full_repos/permissive/123218339/fixSinkList.v
data/verilator_xmls/0b694e3f-a4c4-4ffe-8058-7d25e517a0f9.xml
module fixSinkList(clock, nrst, start, address, wr_en, data_in, data_out, done);
	input clock, nrst, start;
	input [`WORD_WIDTH-1:0] data_in;
    output done, wr_en;
    output [`WORD_WIDTH-1:0] address, data_out;


    reg done_buf, wr_en_buf;
    reg [`WORD_WIDTH-1:0] address_count, data_out_buf, i, j, k;
    reg [`WORD_WIDTH-1:0] knownSinks, sinkIDs, worstHops, qValue, neighborCount, knownSinkCount, sinkIDCount;
    reg [3:0] state;

    always @ (posedge clock) begin
        if (!nrst) begin
            done_buf <= 0;
            address_count <= 16'h68A;
            state <= 0;
            i <= 0;
            j <= 0;
            k <= 0;
        end
        else begin
            case (state)
                0: begin
                    if (start) begin
                        state = 1;
                        address_count <= 16'h68A;
                    end
                    else state = 0;
                end

                1: begin
                    neighborCount = data_in;
                    state = 2;
                    address_count = 16'h688;
                end

                2: begin
                    knownSinkCount = data_in;
                    state = 3;
                    address_count = 16'h8;
                end

                3: begin
                    knownSinks = data_in;
                    state = 4;
                    address_count = 16'h68E + 2*i;
                end

                4: begin                    
                    sinkIDCount = data_in;
                    state = 5;
                    address_count = 16'h248 + 16*i + 2*k;
                end

                5: begin
                    sinkIDs = data_in;

                    if (knownSinks == sinkIDs) begin
                        i = i + 1;
                        k = 0;
                        

                        if (i == neighborCount) begin
                            j = j + 1;
                            i = 0;
                            k = 0;
                            
                            if (j == knownSinkCount) begin
                                state = 10;
                            end
                            else begin
                                state = 3;
                                address_count = 16'h8;
                            end
                        end
                        else begin
                            state = 4;
                            address_count = 16'h68E + 2*i;
                        end
                    end
                    else begin
                        k = k + 1;
                        
                        if (k == sinkIDCount) begin
                            state = 6;
                            data_out_buf = knownSinks;

                            wr_en_buf = 1;
                        end
                        else begin

                            address_count = 16'h248 + 16*i + 2*k;
                        end
                    end                                  
                end

                6: begin
                    wr_en_buf = 0;
                    state = 7;
                    address_count = 16'h28 + 2*j;
                end

                7: begin
                    worstHops = data_in;
                    state = 8;
                    address_count = 16'h1C8 + 2*i;
                end

                8: begin
                    qValue = data_in;
                    data_out_buf = qValue + (worstHops - 1);
                    state = 9;

                    wr_en_buf = 1; 
                end

                9: begin
                    wr_en_buf = 0;
                    i = i + 1;
                    k = 0;

                    if (i == neighborCount) begin
                        j = j + 1;
                        i = 0;
                        k = 0;
                        
                        if (j == knownSinkCount) begin
                            state = 10;
                        end
                        else begin
                            state = 3;
                            address_count = 16'h8;
                        end 
                    end
                    else begin
                        state = 4;
                        address_count = 16'h68E + 2*i;
                    end 
                end

                10: begin
                    done_buf = 1;
                end

                default: state = 10;
            endcase
        end
    end
    assign done = done_buf;
    assign address = address_count;
    assign wr_en = wr_en_buf;
    assign data_out = data_out_buf;
endmodule
module fixSinkList(clock, nrst, start, address, wr_en, data_in, data_out, done);

	input clock, nrst, start;
	input [`WORD_WIDTH-1:0] data_in;
    output done, wr_en;
    output [`WORD_WIDTH-1:0] address, data_out;


    reg done_buf, wr_en_buf;
    reg [`WORD_WIDTH-1:0] address_count, data_out_buf, i, j, k;
    reg [`WORD_WIDTH-1:0] knownSinks, sinkIDs, worstHops, qValue, neighborCount, knownSinkCount, sinkIDCount;
    reg [3:0] state;

    always @ (posedge clock) begin
        if (!nrst) begin
            done_buf <= 0;
            address_count <= 16'h68A;
            state <= 0;
            i <= 0;
            j <= 0;
            k <= 0;
        end
        else begin
            case (state)
                0: begin
                    if (start) begin
                        state = 1;
                        address_count <= 16'h68A;
                    end
                    else state = 0;
                end

                1: begin
                    neighborCount = data_in;
                    state = 2;
                    address_count = 16'h688;
                end

                2: begin
                    knownSinkCount = data_in;
                    state = 3;
                    address_count = 16'h8;
                end

                3: begin
                    knownSinks = data_in;
                    state = 4;
                    address_count = 16'h68E + 2*i;
                end

                4: begin                    
                    sinkIDCount = data_in;
                    state = 5;
                    address_count = 16'h248 + 16*i + 2*k;
                end

                5: begin
                    sinkIDs = data_in;

                    if (knownSinks == sinkIDs) begin
                        i = i + 1;
                        k = 0;
                        

                        if (i == neighborCount) begin
                            j = j + 1;
                            i = 0;
                            k = 0;
                            
                            if (j == knownSinkCount) begin
                                state = 10;
                            end
                            else begin
                                state = 3;
                                address_count = 16'h8;
                            end
                        end
                        else begin
                            state = 4;
                            address_count = 16'h68E + 2*i;
                        end
                    end
                    else begin
                        k = k + 1;
                        
                        if (k == sinkIDCount) begin
                            state = 6;
                            data_out_buf = knownSinks;

                            wr_en_buf = 1;
                        end
                        else begin

                            address_count = 16'h248 + 16*i + 2*k;
                        end
                    end                                  
                end

                6: begin
                    wr_en_buf = 0;
                    state = 7;
                    address_count = 16'h28 + 2*j;
                end

                7: begin
                    worstHops = data_in;
                    state = 8;
                    address_count = 16'h1C8 + 2*i;
                end

                8: begin
                    qValue = data_in;
                    data_out_buf = qValue + (worstHops - 1);
                    state = 9;

                    wr_en_buf = 1; 
                end

                9: begin
                    wr_en_buf = 0;
                    i = i + 1;
                    k = 0;

                    if (i == neighborCount) begin
                        j = j + 1;
                        i = 0;
                        k = 0;
                        
                        if (j == knownSinkCount) begin
                            state = 10;
                        end
                        else begin
                            state = 3;
                            address_count = 16'h8;
                        end 
                    end
                    else begin
                        state = 4;
                        address_count = 16'h68E + 2*i;
                    end 
                end

                10: begin
                    done_buf = 1;
                end

                default: state = 10;
            endcase
        end
    end
    assign done = done_buf;
    assign address = address_count;
    assign wr_en = wr_en_buf;
    assign data_out = data_out_buf;
endmodule