`timescale 1ns/1ns

module lca_4(
	input		[3:0]       A_in  ,
	input	    [3:0]		B_in  ,
    input                   C_1   ,
 
 	output	 wire			CO    ,
	output   wire [3:0]	    S
);
    reg [3:0] g;
    reg [3:0] c;
    reg [3:0] p;
    reg [3:0] s;
    integer i;
    always  @(*)begin
        for(i=0;i<4;i=i+1)begin
            g[i] = A_in[i] & B_in[i];
            p[i] = A_in[i] ^ B_in[i];
            c[i] = i>0 ? (g[i]|p[i]&c[i-1]) : (g[i]|C_1&p[i]);
            s[i] = i>0 ? (p[i]^c[i-1]) : (p[i]^C_1);
         end
    end
    assign S = s;
    assign CO = c[3];
endmodule