l187f	proc	near
	call	WriteHeader
	call	ClearHeader
	mov	cx,16
	xor	di,di
@@1:	push	cx
	mov	word ptr Cnt[di],1
	mov	cx,di
	shr	cx,1
	mov	ax,1
	shl	ax,cl
	mov	d3caa,ax
	mov	Phase,ax
	cmp	ax,400h
	jb	@@2
	cmp	ax,2000h
	ja	@@2
	cmp	d3cef,0
	je	@@4
@@2:	call	l18f6
	mov	bx,FirstUnit
@@3:	mov	es,bx
	mov	d3cb2,bx
	push	es di
	call	cs:l141c[di]
	pop	di es
	mov	bx,es:[4]
	or	bx,bx
	jnz	@@3
@@4:	pop	cx
	inc	di
	inc	di
	loop	@@1
	ret
l187f	endp

l18d6	dw	0c100h,8085h,8000h,0
	dw	1,3,92h,4ch
	dw	8600h,8500h,0a00h,0
	dw	400h,400h,0,-1
l18f6	proc	near
	mov	ax,cs:l18d6[di]
	cmp	ax,0
	je	@@5
	or	d3caa,ax
	push	di
	mov	cx,10h
	xor	di,di
@@1:	shr	ax,1
	jnc	@@2
	mov	word ptr Cnt[di],1
@@2:	inc	di
	inc	di
	or	ax,ax
	jz	@@3
	loop	@@1
@@3:	pop	di
	cmp	Cnt.TypeCount,1
	jne	@@4
	cmp	Phase,100h
	je	@@4
	mov	Cnt.TypeCount,21h
@@4:	cmp	Cnt.ScopeCount,1
	jne	@@5
	push	word ptr Cnt[8]
	pop	Cnt.ScopeCount
@@5:	test	d3caa,0b00h
	jz	@@6
	not	d3cbe
@@6:	ret
l18f6	endp

l194e	proc	near
	mov	ax,es:[3ch]
	inc	ax
	add	Cnt.NameCount,ax
	ret
l194e	endp

l1958	proc	near
	mov	si,es:[si]
	or	si,si
	jz	@@1
	push	es
	mov	bl,es:[si+3]
	xor	bh,bh
	lea	si,[bx+si+4]
	mov	si,es:[si+2]
	add	si,es:[0ch]
	mov	si,es:[si]
	mov	es,ProcInfo
	add	dx,es:[si+8]
	pop	es
@@1:	ret
l1958	endp

WriteHeader	proc	near
	mov	ax,30h
	cmp	Cnt.ClassCount,1
	je	@@1
	add	ax,10h
@@1:	call	GetMem
	call	StartBuf
	call	l1a51
	mov	ax,52fbh
	stosw
	mov	ax,208h
	cmp	Cnt.ClassCount,1
	je	@@2
	mov	ax,209h
@@2:	stosw
	mov	ax,NamePoolSize.Offs
	stosw
	mov	ax,NamePoolSize.Segm
	stosw
	mov	ax,Cnt.NameCount
	dec	ax
	stosw
	mov	ax,Cnt.TypeCount
	dec	ax
	stosw
	mov	d3cf0,ax
	mov	ax,Cnt.MemberCount
	dec	ax
	stosw
	mov	d3cf2,ax
	mov	ax,Cnt.SymbolCount
	dec	ax
	stosw
	inc	di
	inc	di
	mov	ax,Cnt.SegmentCount
	dec	ax
	stosw
	inc	di
	inc	di
	mov	ax,Cnt.ScopeCount
	dec	ax
	stosw
	mov	ax,Cnt.LineNumberCount
	dec	ax
	stosw
	mov	ax,Cnt.SourceFileCount
	dec	ax
	stosw
	mov	ax,Cnt.SegmentCount
	dec	ax
	stosw
	mov	ax,Cnt.CorrelCount
	dec	ax
	stosw
	add	di,4
	cmp	OverlaysPresent,1
	je	@@3
	add	di,4
	inc	di
	jmp	short @@4
@@3:	inc	di
	inc	di
	mov	ax,DataStart
	stosw
	mov	al,2
	stosb
@@4:	inc	di
	inc	di
	mov	ax,Cnt.DataCount
	dec	ax
	stosw
	mov	d3cf6,ax
	inc	di
	mov	d3cef,0
	cmp	Cnt.ClassCount,1
	jne	@@5
	mov	d3cf4,0
	inc	di
	inc	di
	jmp	short @@6
@@5:	mov	d3cef,1
	mov	ax,10h
	stosw
	mov	ax,Cnt.ClassCount
	dec	ax
	stosw
	mov	ax,Cnt.ParentCount
	dec	ax
	stosw
	mov	d3cf4,ax
	inc	di
	inc	di
	inc	di
	inc	di
	mov	ax,Cnt.SegmentCount
	dec	ax
	stosw
	mov	ax,Cnt.SegmentCount
	dec	ax
	stosw
	inc	di
	inc	di
	inc	di
	inc	di
@@6:	call	StopBuf
	ret
WriteHeader	endp

l1a51	proc	near
	push	di
	shr	ax,1
	mov	cx,ax
	xor	ax,ax
	rep	stosw
	pop	di
	ret
l1a51	endp

l1a5c	proc	near
	push	bp
	mov	bp,sp
	push	si di ds
	mov	ax,di
	add	ax,si
	shr	ax,1
	push	ds si di
	dec	ax
	mov	cx,9
	mul	cx
	add	ax,d3cb6
	mov	si,ax
	call	StartBuf
	mov	dx,di
	mov	ax,es
	mov	ds,ax
	rep	movsb
	pop	di si es
@@1:	mov	bx,si
	mov	al,0
	call	l1ad2
	jz	@@2
	inc	si
	jmp	@@1
@@2:	mov	bx,di
	mov	al,1
	call	l1ad2
	jz	@@3
	dec	di
	jmp	@@2
@@3:	cmp	si,di
	ja	@@5
	je	@@4
	call	l1b3f
@@4:	inc	si
	dec	di
	cmp	si,di
	jna	@@1
@@5:	pop	ds
	cmp	[bp-2],di
	jae	@@6
	xchg	si,[bp-2]
	call	l1a5c
	mov	si,[bp-2]
@@6:	cmp	[bp-4],si
	jbe	@@7
	mov	di,[bp-4]
	call	l1a5c
@@7:	mov	sp,bp
	pop	bp
	ret
l1a5c	endp

l1aca	db	0,3,1,1,3,2,3,3
l1ad2	proc	near
	push	si di dx ax
	mov	si,dx
	mov	cx,9
	mov	ax,bx
	dec	ax
	mul	cx
	add	ax,es:d3cb6
	mov	di,ax
	pop	ax
	or	al,al
	jnz	@@1
	xchg	si,di
@@1:	lea	bx,l1aca
	mov	al,[di+8]
	and	al,7
	segcs	xlat
	mov	ah,al
	mov	al,[si+8]
	and	al,7
	segcs	xlat
	cmp	al,ah
	jb	@@4
	ja	@@5
	cmp	al,0
	jne	@@2
	mov	ax,[si+6]
	cmp	ax,[di+6]
	jb	@@4
	ja	@@5
	mov	ax,[si+4]
	cmp	ax,[di+4]
	jb	@@4
	jmp	short @@5
@@2:	cmp	al,1
	jne	@@3
	mov	ax,[si+4]
	cmp	ax,[di+4]
	jg	@@4
	jmp	short @@5
@@3:	mov	ax,[si]
	cmp	ax,[di]
	jmp	short @@7
@@4:	mov	al,1
	jmp	short @@6
@@5:	mov	al,0
@@6:	or	al,al
@@7:	pop	dx di si
	ret
l1ad2	endp

l1b3f	proc	near
	push	si di dx
	mov	cx,9
	mov	ax,si
	dec	ax
	mul	cx
	add	ax,es:d3cb6
	mov	si,ax
	mov	ax,di
	dec	ax
	mul	cx
	add	ax,es:d3cb6
	mov	di,ax
@@1:	mov	al,[si]
	xchg	al,[di]
	mov	[si],al
	inc	si
	inc	di
	loop	@@1
	pop	dx di si
	ret
l1b3f	endp

l1b6b	proc	near
	mov	dx,ax
	sub	ax,Cnt.SymbolCount
	jz	@@3
	neg	ax
	push	ax
	push	dx
	mov	di,ax
	mov	si,1
	push	es
	call	l1a5c
	pop	es dx cx
	push	ds es
	mov	di,d3cb6
	mov	es,ProcInfo
	mov	ds,BufPtr.Segm
@@1:	mov	al,[di+8]
	mov	ah,al
	and	al,7
	jnz	@@2
	test	ah,20h
	jz	@@2
	and	byte ptr [di+8],0dfh
	mov	bx,[di]
	mov	es:[bx],dx
	mov	ax,es:[bx+4]
	mov	[di],ax
@@2:	add	di,9
	inc	dx
	loop	@@1
	pop	es ds
@@3:	ret
l1b6b	endp
