(defun sn74382 (a b cn s)
;; This is a literal translation of the schematic given in the
;; data sheet.
(let ((a0 (ldb (byte 1 0) a))
(a1 (ldb (byte 1 1) a))
(a2 (ldb (byte 1 2) a))
(a3 (ldb (byte 1 3) a))
(b0 (ldb (byte 1 0) b))
(b1 (ldb (byte 1 1) b))
(b2 (ldb (byte 1 2) b))
(b3 (ldb (byte 1 3) b))
(s0 (ldb (byte 1 0) s))
(s1 (ldb (byte 1 1) s))
(s2 (ldb (byte 1 2) s)))
(let* ((k0 (lognot (logand (lognot s0) (lognot s1))))
(k1 (lognot (logand (lognot s1) (lognot s2))))
(p28 (logand (lognot s0) (lognot s1)))
(p29 (lognot (logand (lognot s0) s1)))
(p30 (lognot (logand s0 s1 (lognot s2))))
(p31 (logand (lognot s1) s2))
(q8 (logand (lognot s0) s2))
(u0 (lognot (logior q8 p31)))
(p0 (logand (lognot b0) (lognot a0) k1 p29))
(p1 (logand (lognot b0) a0 k0 p29 p30))
(p2 (logand b0 (lognot a0) k1 p30))
(p3 (logand (lognot a0) (lognot b0) k0 p30 u0))
(p4 (logand (lognot b0) a0 k1 p29))
(p5 (logand b0 (lognot a0) k1 p29))
(p6 (logand b0 a0 k0 p30))
(p7 (logand (lognot b1) (lognot a1) k1 p29))
(p8 (logand (lognot b1) a1 k0 p29 p30))
(p9 (logand b1 (lognot a1) k1 p30))
(p10 (logand (lognot a1) (lognot b1) k0 p30 u0))
(p11 (logand (lognot b1) a1 k1 p29))
(p12 (logand b1 (lognot a1) k1 p29))
(p13 (logand b1 a1 k0 p30))
(p14 (logand (lognot b2) (lognot a2) k1 p29))
(p15 (logand (lognot b2) a2 k0 p29 p30))
(p16 (logand b2 (lognot a2) k1 p30))
(p17 (logand (lognot a2) (lognot b2) k0 p30 u0))
(p18 (logand (lognot b2) a2 k1 p29))
(p19 (logand b2 (lognot a2) k1 p29))
(p20 (logand b2 a2 k0 p30))
(p21 (logand (lognot b3) (lognot a3) k1 p29))
(p22 (logand (lognot b3) a3 k0 p29 p30))
(p23 (logand b3 (lognot a3) k1 p30))
(p24 (logand (lognot b3) (lognot a3) k0 p30 u0))
(p25 (logand (lognot b3) a3 k1 p29))
(p26 (logand b3 (lognot a3) k1 p29))
(p27 (logand b3 a3 k0 p30))
(q0 (lognot (logior p0 p1 p2)))
(q1 (lognot (logior p3 p4 p5 p6)))
(q2 (lognot (logior p7 p8 p9)))
(q3 (lognot (logior p10 p11 p12 p13)))
(q4 (lognot (logior p14 p15 p16)))
(q5 (lognot (logior p17 p18 p19 p20)))
(q6 (lognot (logior p21 p22 p23)))
(q7 (lognot (logior p24 p25 p26 p27)))
(u1 (lognot (logior p28 s2)))
(w0 (lognot (logand cn u1)))
(w1 (logand cn q0 u1))
(w2 (logand q0 q1 u1))
(w3 (logand cn q0 q2 u1))
(w4 (logand q0 q2 q1 u1))
(w5 (logand q2 q3 u1))
(w6 (logand cn q0 q2 q4 u1))
(w7 (logand q0 q2 q4 q1 u1))
(w8 (logand q2 q4 q3 u1))
(w9 (logand q4 q5 u1))
(w10 (lognot (logand q0 q2 q4 q6)))
(w11 (logand q0 q2 q4 q6 q1))
(w12 (logand q2 q4 q6 q3))
(w13 (logand q4 q6 q5))
(w14 (logand q6 q7))
(w15 (lognot (logand cn q0 q2 q4 q6)))
(v0 (lognot (logior w1 w2)))
(v1 (lognot (logior w3 w4 w5)))
(v2 (lognot (logior w6 w7 w8 w9)))
(v3 (lognot (logior w11 w12 w13 w14)))
(v4 (logand v3 w15))
(v5 (lognot (logand v3 w15)))
(f0 (logxor w0 q1))
(f1 (logxor v0 q3))
(f2 (logxor v1 q5))
(f3 (logxor v2 q7))
(x4 (logxor v2 v4)))
(declare (ignore w10))
(values
(logior (ash (logand 1 f3) 3)
(ash (logand 1 f2) 2)
(ash (logand 1 f1) 1)
(ash (logand 1 f0) 0))
(logand 1 v5)
(logand 1 x4)
;; /p = w10 ('381)
;; /g = v3 ('381)
))))