.global	main
main:
	xor	%eax,%eax
	dec	%ax
	lea	2(%eax,%eax),%ecx
	sub	%ecx,%esp
	or	%eax,%esp
	mov	%esp,%esi
	inc	%esi
	xor	%eax,%esp
	cld
	mov	%esp,%edi
	rep	stosb
	xor	%ebx,%ebx
	lea	3(%ebx),%eax
	lea	2(%esi),%ecx
	addr16 lea 16384(%bx),%edx
	int	$0x80
	push	%eax
	mov	%esi,%ebx
	mov	%esi,%edi
	mov	%eax,%ecx
	pusha
	mov	$0x0a,%al
	stosb
	stosb
	lodsl
	mov	%eax,(%edi,%ecx)
	popa
	mov	$'S',%al
	repne	scasb
	dec	%edi
	push	$0
	push	$0
loop3:
	sub	$8,%bx
	mov	%edi,0(%ebx)
	popl	4(%ebx)
	pop	%edi
	test	%edi,%edi
	jne	loop3
	push	%edi
loop2:
	mov	$0x030a,%ax
loop1:	
	mov	(%ebx),%edi
	stc
	jmp	x
xcy:
	mov	%esi,%edx
	sbb	%edi,%edx
	lea	(%esi,%edx,4),%edx
	mov	(%edx),%ecx
	and	$~3,%ecx
	mov	4(%ebx),%ebp
	cmp	%ebp,%ecx
	jbe	gonext
	mov	(%edi),%cl
	cmp	$'G',%cl
	je	1f
	cmpb	$' ',%cl
	jne	gonext
	lea	4(%ebp),%ecx
	push	%ecx
	push	%edi
1:
	mov	%ebp,(%edx)
	or	%ah,(%edx)
gonext:
	dec	%ah
	jns	loop1
	add	$8,%bx
	jne	loop2
	pop	%edi
	test	%edi,%edi
	jne	loop3

	cld
	mov	(%esp),%ecx
	mov	%esi,%edi
	mov	$'G',%al
	repne	scasb

	dec	%edi
	.byte	0xb8,0x0a	# mov $0x??????0a,%eax (next 3 bytes)
goalloop:
	movb	$'$',(%edi)	# 3 bytes instruction
	mov	%esi,%edx
	sub	%edi,%edx
	mov	-4(%esi,%edx,4),%ah
	xor	$1,%ah		# clears CF
x:
	pushf
	push	%eax
	xor	%ecx,%ecx
	dec	%ecx
	std
	repne	scasb
	cmp	%edi,%esi
	je	xret
	mov	%ecx,%edx
	and	$3,%ah
	je	x0
	cld
	inc	%edi
	inc	%edx
	sub	$2,%ah
	jb	x1
	ja	x3
x2:
	inc	%edx
	.byte	0x3c	# cmp: ignore the next 1 byte instruction
x1:
	inc	%edi
	inc	%edx
x3:
x0:
	repne	scasb
	sub	%edx,%edi
	dec	%edi
xret:
	pop	%eax
	popf
	jc	xcy
	cmpb	$' ',(%edi)
	je	goalloop

	pop	%edx
	xor	%ebx,%ebx
	lea	4(%ebx),%eax
	inc	%ebx
	lea	2(%esi),%ecx
	int	$0x80
	mov	%ebx,%eax
	int	$0x80
