# 9 inputs
# 11 outputs
# 15 D-type flipflops
# 57 inverters
# 104 gates (44 ANDs + 19 NANDs + 10 ORs + 31 NORs)

INPUT(START)
INPUT(B0)
INPUT(B1)
INPUT(B2)
INPUT(B3)
INPUT(A0)
INPUT(A1)
INPUT(A2)
INPUT(A3)

OUTPUT(CNTVCO2)
OUTPUT(CNTVCON2)
OUTPUT(READY)
OUTPUT(P0)
OUTPUT(P1)
OUTPUT(P2)
OUTPUT(P3)
OUTPUT(P4)
OUTPUT(P5)
OUTPUT(P6)
OUTPUT(P7)

CT2 = DFF(CNTVG3VD)
CT1 = DFF(CNTVG2VD)
CT0 = DFF(CNTVG1VD)
ACVQN3 = DFF(ACVG4VD1)
ACVQN2 = DFF(ACVG3VD1)
ACVQN1 = DFF(ACVG2VD1)
ACVQN0 = DFF(ACVG1VD1)
MRVQN3 = DFF(MRVG4VD)
MRVQN2 = DFF(MRVG3VD)
MRVQN1 = DFF(MRVG2VD)
MRVQN0 = DFF(MRVG1VD)
AX3 = DFF(AM3)
AX2 = DFF(AM2)
AX1 = DFF(AM1)
AX0 = DFF(AM0)

READY = NOT(READYN)
CT1N = NOT(CT1)
CNTVG3VQN = NOT(CT2)
CNTVG2VQN = NOT(CT1)
CNTVCO0 = NOT(CNTVG1VQN)
CNTVCON0 = NOT(CT0)
CNTVG1VQN = NOT(CT0)
CNTVG1VD1 = NOT(READY)
S3 = NOT(ADDVG4VSN)
CO = NOT(ADDVG4VCN)
S2 = NOT(ADDVG3VSN)
ADDVC3 = NOT(ADDVG3VCN)
S1 = NOT(ADDVG2VSN)
ADDVC2 = NOT(ADDVG2VCN)
ADDVC1 = NOT(ADDVG1VCN)
S0 = NOT(ADDVG1VP)
AD0 = NOT(AD0N)
AD1 = NOT(AD1N)
AD2 = NOT(AD2N)
AD3 = NOT(AD3N)
ACVPCN = NOT(START)
P7 = NOT(ACVQN3)
P6 = NOT(ACVQN2)
P5 = NOT(ACVQN1)
P4 = NOT(ACVQN0)
SMVG5VS0P = N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ADDVG2VCNVAD1NF = AND(AD1, P5)
SMVG5VG1VAD2NF = AND(SMVG5VS0P, CO)
SMVG5VG1VAD1NF = AND(SMVS0N, P7)
SMVG4VG1VAD2NF = AND(SMVG4VS0P, S3)
SMVG4VG1VAD1NF = AND(SMVS0N, P6)
SMVG3VG1VAD2NF = AND(SMVG3VS0P, S2)
SMVG3VG1VAD1NF = AND(SMVS0N, P5)
SMVG2VG1VAD2NF = AND(SMVG2VS0P, S1)
SMVG2VG1VAD1NF = AND(SMVS0N, P4)
MRVG4VDVAD2NF = AND(MRVSHLDN, BM3)
MRVG4VDVAD1NF = AND(ADSH, S0)
MRVG3VDVAD2NF = AND(MRVSHLDN, BM2)
MRVG3VDVAD1NF = AND(ADSH, P3)
MRVG2VDVAD2NF = AND(MRVSHLDN, BM1)
MRVG2VDVAD1NF = AND(ADSH, P2)
MRVG1VDVAD2NF = AND(MRVSHLDN, BM0)
MRVG1VDVAD1NF = AND(ADSH, P1)
BMVG5VG1VAD2NF = AND(BMVG5VS0P, B3)
BMVG5VG1VAD1NF = AND(BMVS0N, P3)
BMVG4VG1VAD2NF = AND(BMVG4VS0P, B2)
BMVG4VG1VAD1NF = AND(BMVS0N, P2)
BMVG3VG1VAD2NF = AND(BMVG3VS0P, B1)
BMVG3VG1VAD1NF = AND(BMVS0N, P1)
BMVG2VG1VAD2NF = AND(BMVG2VS0P, B0)
BMVG2VG1VAD1NF = AND(BMVS0N, P0)
AMVG5VG1VAD2NF = AND(AMVG5VS0P, A3)
AMVG5VG1VAD1NF = AND(AMVS0N, AX3)
AMVG4VG1VAD2NF = AND(AMVG4VS0P, A2)
AMVG4VG1VAD1NF = AND(AMVS0N, AX2)
AMVG3VG1VAD2NF = AND(AMVG3VS0P, A1)
AMVG3VG1VAD1NF = AND(AMVS0N, AX1)
AMVG2VG1VAD2NF = AND(AMVG2VS0P, A0)
AMVG2VG1VAD1NF = AND(AMVS0N, AX0)

CNTVG3VG2VOR1NF = OR(CT2, CNTVG3VD1)
CNTVG2VG2VOR1NF = OR(CT1, CNTVG2VD1)
CNTVG1VG2VOR1NF = OR(CT0, CNTVG1VD1)
ADDVG4VCNVOR2NF = OR(ADDVC3, AD3, P7)
ADDVG4VCNVOR1NF = OR(AD3, P7)
ADDVG3VCNVOR2NF = OR(ADDVC2, AD2, P6)
ADDVG3VCNVOR1NF = OR(AD2, P6)
ADDVG2VCNVOR2NF = OR(ADDVC1, AD1, P5)
ADDVG2VCNVOR1NF = OR(AD1, P5)
ADDVG1VPVOR1NF = OR(AD0, P4)

READYN = NAND(CT0, CT1N, CT2)
CNTVCON2 = NAND(CT2, CNTVCO1)
CNTVG3VZ = NAND(CNTVG3VG2VOR1NF, CNTVG3VZ1)
CNTVG3VZ1 = NAND(CT2, CNTVG3VD1)
CNTVCON1 = NAND(CT1, CNTVCO0)
CNTVG2VZ = NAND(CNTVG2VG2VOR1NF, CNTVG2VZ1)
CNTVG2VZ1 = NAND(CT1, CNTVG2VD1)
CNTVG1VZ = NAND(CNTVG1VG2VOR1NF, CNTVG1VZ1)
CNTVG1VZ1 = NAND(CT0, CNTVG1VD1)
ADDVG1VP = NAND(ADDVG1VPVOR1NF, ADDVG1VCN)
ADDVG1VCN = NAND(AD0, P4)
AD0N = NAND(P0, AX0)
AD1N = NAND(P0, AX1)
AD2N = NAND(P0, AX2)
AD3N = NAND(P0, AX3)
ACVG4VD1 = NAND(ACVPCN, SM3)
ACVG3VD1 = NAND(ACVPCN, SM2)
ACVG2VD1 = NAND(ACVPCN, SM1)
ACVG1VD1 = NAND(ACVPCN, SM0)

ADSH = NOR(READY, INIT)
INIT = NOR(CT0, CT1, CT2)
CNTVCO2 = NOR(CNTVG3VQN, CNTVCON1)
CNTVG3VD = NOR(CNTVG3VZ, START)
CNTVG3VD1 = NOR(READY, CNTVCON1)
CNTVCO1 = NOR(CNTVG2VQN, CNTVCON0)
CNTVG2VD = NOR(CNTVG2VZ, START)
CNTVG2VD1 = NOR(READY, CNTVCON0)
CNTVG1VD = NOR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