# cc -nostdlib r.s
_start:	.globl _start
	bufsiz = 0x2000
	sub	$bufsiz,%rsp
	and	$-64,%rsp
	sub	$16,%rsp
	push	%rsp
	pop	%rdi
	cld
	push	$15
	pop	%rcx
	mov	$':',%al
	rep	stosb
	mov	$'1',%al
	stosb
	mov	$1,%cl
	push	%rdi
	pop	%rsi

	o10 = 0
	lf = 5
	lb = 5
	lfb = 9
.macro	setup	n,x,y
	ln = \n+1
	o11 = o10+lb
	o12 = o11+ln
	o13 = o12+lf
	o14 = o13+ln
	o15 = o14+ln
	o16 = o15+lfb
	o17 = o16+ln
	o18 = o17+ln
	o19 = o18+lf
	o20 = o19+ln
	o21 = o20+lb
	o22 = o21+lf
	o23 = o22+ln
	o24 = o23+ln
	o25 = o24+lf
	o26 = o25+lb
	o27 = o26+ln
	o28 = o27+lf
	o29 = o28+ln
	o30 = o29+ln
	o31 = o30+lfb
	o32 = o31+ln
	o33 = o32+ln
	o34 = o33+lf
	o35 = o34+ln
	o36 = o35+lb
	o37 = o36+lf
	o38 = o37+ln
	o39 = o38+ln
	o40 = o39+lf
	len30 = o40
	nrep = bufsiz/len30
	nrep2 = ((\y-\x)/30)/nrep
	nrep3 = ((\y-\x)/30)%nrep
	mov	$\n,%ecx
	mov	$nrep*30,%ebp
	call	main3
.endm
.macro	incf6
	mov	%r14,%rax
	add	$1,%r14
	xor	%r14,%rax
	and	%rcx,%rax
	mov	%rax,%rdx
	shr	$4,%rax
	or	%rdx,%rax
	and	%rbp,%rax
	or	%rax,%r14
.endm
.macro	fast	s
	movabs	$0xf0f0f0f0f0f0f0f0,%rcx
	movabs	$0x36f6f6f6f6f6f6f6,%rbp
	movabs	$0x6c6c6c6c6c6c6c6,%r11
	mov	$nrep2-1,%r15d
	call	num2f6
2:	mov	$nrep,%r13d
	mov	%rsi,%r12
	movabs	$0x6c6c6c6c6c6c6c6,%r11
1:	mov	%r14,%r8
	sub	%r11,%r8
	incf6
	mov	%r14,%r9
	sub	%r11,%r9
	incf6
	mov	%r14,%r10
	sub	%r11,%r10
	incf6
	\s
	add	$len30,%r12
	sub	$1,%r13d
	jne	1b
	call	flush
	sub	$1,%r15d
	jne	2b
.if	nrep3>0
	mov	$nrep3,%r13d
	mov	%rsi,%r12
	movabs	$0x6c6c6c6c6c6c6c6,%r11
1:	mov	%r14,%r8
	sub	%r11,%r8
	incf6
	mov	%r14,%r9
	sub	%r11,%r9
	incf6
	mov	%r14,%r10
	sub	%r11,%r10
	incf6
	\s
	add	$len30,%r12
	sub	$1,%r13d
	jne	1b
	mov	%r12,%rdi
	call	flush
.endif
.endm
.macro	constno	i,a,b,c,d,e,f,g,h,m
	\i	$\a|\b<<8|\c<<16|\d<<24|\e<<32|\f<<40|\g<<48|\h<<56,\m
.endm
.macro	s4
	mov	%r8d,%eax
	bswap	%eax
	mov	$'\n',%al
	mov	%eax,o11-1(%r12)
	mov	%eax,o13-1(%r12)
	mov	%eax,o14-1(%r12)
	mov	%eax,o16-1(%r12)
	mov	%eax,o17-1(%r12)
	mov	%eax,o19-1(%r12)
	mov	%r9d,%eax
	bswap	%eax
	mov	$'\n',%al
	mov	%eax,o22-1(%r12)
	mov	%eax,o23-1(%r12)
	mov	%eax,o26-1(%r12)
	mov	%eax,o28-1(%r12)
	mov	%eax,o29-1(%r12)
	mov	%r10d,%eax
	bswap	%eax
	mov	$'\n',%al
	mov	%eax,o31-1(%r12)
	mov	%eax,o32-1(%r12)
	mov	%eax,o34-1(%r12)
	mov	%eax,o37-1(%r12)
	mov	%eax,o38-1(%r12)
.endm
.macro	s5
	mov	%r8d,%eax
	bswap	%eax
	mov	%eax,o11(%r12)
	mov	%eax,o13(%r12)
	mov	%eax,o14(%r12)
	mov	%eax,o16(%r12)
	mov	%eax,o17(%r12)
	mov	%eax,o19(%r12)
	mov	%r9d,%eax
	bswap	%eax
	mov	%eax,o22(%r12)
	mov	%eax,o23(%r12)
	mov	%eax,o26(%r12)
	mov	%eax,o28(%r12)
	mov	%eax,o29(%r12)
	mov	%r10d,%eax
	bswap	%eax
	mov	%eax,o31(%r12)
	mov	%eax,o32(%r12)
	mov	%eax,o34(%r12)
	mov	%eax,o37(%r12)
	mov	%eax,o38(%r12)
.endm
.macro	s6
	mov	%r8,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$24,%rax
	shr	$56,%rdx
	mov	%eax,o11(%r12)
	mov	%dl,o11+4(%r12)
	mov	%eax,o13(%r12)
	mov	%dl,o13+4(%r12)
	mov	%eax,o14(%r12)
	mov	%dl,o14+4(%r12)
	mov	%eax,o16(%r12)
	mov	%dl,o16+4(%r12)
	mov	%eax,o17(%r12)
	mov	%dl,o17+4(%r12)
	mov	%eax,o19(%r12)
	mov	%dl,o19+4(%r12)
	mov	%r9,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$24,%rax
	shr	$56,%rdx
	mov	%eax,o22(%r12)
	mov	%dl,o22+4(%r12)
	mov	%eax,o23(%r12)
	mov	%dl,o23+4(%r12)
	mov	%eax,o26(%r12)
	mov	%dl,o26+4(%r12)
	mov	%eax,o28(%r12)
	mov	%dl,o28+4(%r12)
	mov	%eax,o29(%r12)
	mov	%dl,o29+4(%r12)
	mov	%r10,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$24,%rax
	shr	$56,%rdx
	mov	%eax,o31(%r12)
	mov	%dl,o31+4(%r12)
	mov	%eax,o32(%r12)
	mov	%dl,o32+4(%r12)
	mov	%eax,o34(%r12)
	mov	%dl,o34+4(%r12)
	mov	%eax,o37(%r12)
	mov	%dl,o37+4(%r12)
	mov	%eax,o38(%r12)
	mov	%dl,o38+4(%r12)
.endm
.macro	s7
	mov	%r8,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$16,%rax
	shr	$48,%rdx
	mov	%eax,o11(%r12)
	mov	%dx,o11+4(%r12)
	mov	%eax,o13(%r12)
	mov	%dx,o13+4(%r12)
	mov	%eax,o14(%r12)
	mov	%dx,o14+4(%r12)
	mov	%eax,o16(%r12)
	mov	%dx,o16+4(%r12)
	mov	%eax,o17(%r12)
	mov	%dx,o17+4(%r12)
	mov	%eax,o19(%r12)
	mov	%dx,o19+4(%r12)
	mov	%r9,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$16,%rax
	shr	$48,%rdx
	mov	%eax,o22(%r12)
	mov	%dx,o22+4(%r12)
	mov	%eax,o23(%r12)
	mov	%dx,o23+4(%r12)
	mov	%eax,o26(%r12)
	mov	%dx,o26+4(%r12)
	mov	%eax,o28(%r12)
	mov	%dx,o28+4(%r12)
	mov	%eax,o29(%r12)
	mov	%dx,o29+4(%r12)
	mov	%r10,%rax
	bswap	%rax
	mov	%rax,%rdx
	shr	$16,%rax
	shr	$48,%rdx
	mov	%eax,o31(%r12)
	mov	%dx,o31+4(%r12)
	mov	%eax,o32(%r12)
	mov	%dx,o32+4(%r12)
	mov	%eax,o34(%r12)
	mov	%dx,o34+4(%r12)
	mov	%eax,o37(%r12)
	mov	%dx,o37+4(%r12)
	mov	%eax,o38(%r12)
	mov	%dx,o38+4(%r12)
.endm
.macro	s8
	mov	%r8,%rax
	bswap	%rax
	mov	$'\n',%al
	mov	%rax,o11-1(%r12)
	mov	%rax,o13-1(%r12)
	mov	%rax,o14-1(%r12)
	mov	%rax,o16-1(%r12)
	mov	%rax,o17-1(%r12)
	mov	%rax,o19-1(%r12)
	mov	%r9,%rax
	bswap	%rax
	mov	$'\n',%al
	mov	%rax,o22-1(%r12)
	mov	%rax,o23-1(%r12)
	mov	%rax,o26-1(%r12)
	mov	%rax,o28-1(%r12)
	mov	%rax,o29-1(%r12)
	mov	%r10,%rax
	bswap	%rax
	mov	$'\n',%al
	mov	%rax,o31-1(%r12)
	mov	%rax,o32-1(%r12)
	mov	%rax,o34-1(%r12)
	mov	%rax,o37-1(%r12)
	mov	%rax,o38-1(%r12)
.endm
.macro	s9
	mov	%r8,%rax
	bswap	%rax
	mov	%rax,o11(%r12)
	mov	%rax,o13(%r12)
	mov	%rax,o14(%r12)
	mov	%rax,o16(%r12)
	mov	%rax,o17(%r12)
	mov	%rax,o19(%r12)
	mov	%r9,%rax
	bswap	%rax
	mov	%rax,o22(%r12)
	mov	%rax,o23(%r12)
	mov	%rax,o26(%r12)
	mov	%rax,o28(%r12)
	mov	%rax,o29(%r12)
	mov	%r10,%rax
	bswap	%rax
	mov	%rax,o31(%r12)
	mov	%rax,o32(%r12)
	mov	%rax,o34(%r12)
	mov	%rax,o37(%r12)
	mov	%rax,o38(%r12)
.endm
.macro	s10
	mov	%r8,%rax
	bswap	%rax
	movzbl	%al,%edx
	shr	$6,%edx
	add	$'1',%edx
	and	$0xffffffffffffff3f,%rax
	mov	%dl,o11(%r12)
	mov	%rax,o11+1(%r12)
	mov	%dl,o13(%r12)
	mov	%rax,o13+1(%r12)
	mov	%dl,o14(%r12)
	mov	%rax,o14+1(%r12)
	mov	%dl,o16(%r12)
	mov	%rax,o16+1(%r12)
	mov	%dl,o17(%r12)
	mov	%rax,o17+1(%r12)
	mov	%dl,o19(%r12)
	mov	%rax,o19+1(%r12)
	mov	%r9,%rax
	bswap	%rax
	movzbl	%al,%edx
	shr	$6,%edx
	add	$'1',%edx
	and	$0xffffffffffffff3f,%rax
	mov	%dl,o22(%r12)
	mov	%rax,o22+1(%r12)
	mov	%dl,o23(%r12)
	mov	%rax,o23+1(%r12)
	mov	%dl,o26(%r12)
	mov	%rax,o26+1(%r12)
	mov	%dl,o28(%r12)
	mov	%rax,o28+1(%r12)
	mov	%dl,o29(%r12)
	mov	%rax,o29+1(%r12)
	mov	%r10,%rax
	bswap	%rax
	movzbl	%al,%edx
	shr	$6,%edx
	add	$'1',%edx
	and	$0xffffffffffffff3f,%rax
	mov	%dl,o31(%r12)
	mov	%rax,o31+1(%r12)
	mov	%dl,o32(%r12)
	mov	%rax,o32+1(%r12)
	mov	%dl,o34(%r12)
	mov	%rax,o34+1(%r12)
	mov	%dl,o37(%r12)
	mov	%rax,o37+1(%r12)
	mov	%dl,o38(%r12)
	mov	%rax,o38+1(%r12)
.endm

	mov	$999,%ebp
	call	main2
	constno	movl,':','1','0','0',0,0,0,0,-5(%rsi)
	setup	4,1000,10000
	fast	s4
	constno	movl,'1','0','0','0',0,0,0,0,-5(%rsi)
	setup	5,10000,100000
	fast	s5
	constno	movabs,':',':',':','1','0','0','0','0',%rax
	mov	%rax,-9(%rsi)
	setup	6,100000,1000000
	fast	s6
	constno	movabs,':',':','1','0','0','0','0','0',%rax
	mov	%rax,-9(%rsi)
	setup	7,1000000,10000000
	fast	s7
	constno	movabs,':','1','0','0','0','0','0','0',%rax
	mov	%rax,-9(%rsi)
	setup	8,10000000,100000000
	fast	s8
	constno	movabs,'1','0','0','0','0','0','0','0',%rax
	mov	%rax,-9(%rsi)
	setup	9,100000000,1000000000
	fast	s9
	movb	$'1',-10(%rsi)
	constno	movabs,'0','0','0','0','0','0','0','0',%rax
	mov	%rax,-9(%rsi)
	setup	10,1000000000,4294967290
	fast	s10
	movb	$'4',-10(%rsi)
	constno	movabs,'2','9','4','9','6','7','2','9',%rax
	mov	%rax,-9(%rsi)
	mov	$10,%ecx
	mov	$5,%ebp
	call	main3
	xor	%edi,%edi
	push	$60
	pop	%rax
	syscall
main2:	mov	$0x5f562d0f,%ebx	# 56 5f = push %rsi; pop %rdi
	main3 = .-2
main1:	dec	%bl
	js	main2
	push	%rcx
	jpo	nextm
	mov	$'F'+'i'*0x100+'z'*0x10000+'z'*0x1000000,%eax
	shr	%bh
	jnbe	skipf
stor:	stosl
	jb	skipn
skipf:	sub	$'F'+'i'*0x100-('B'+'u'*0x100),%ax
	jmp	stor
nextm:	sub	%rcx,%rsi
	rep	movsb
skipn:	mov	$0xa,%al
	stosb
	pop	%rcx
	push	%rsi
next1:	dec	%rsi
	incb	(%rsi)
	cmpb	$':',(%rsi)
	jb	next2
	andb	$'1',(%rsi)
	jpe	next1
	inc	%ecx
next2:	pop	%rsi
	dec	%ebp
	jne	main1
flush:	mov	%edi,%edx
	sub	%esi,%edx
	push	%rcx
	push	%rdi
	push	$1
	pop	%rax
	mov	%eax,%edi
	syscall
	pop	%rdi
	pop	%rcx
	ret
num2f6:	xor	%r14,%r14
	movzbl	-10(%rsi),%eax
	sub	$'1',%al
	cmp	$4,%al
	cmovb	%eax,%r14d
	shl	$62,%r14
	mov	-9(%rsi),%rax
	bswap	%rax
	add	%r11,%rax
	or	%rax,%r14
	ret
