Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);p[x]=y;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i++<N;){p[i]=i;r[i]=1;};for(i=m;i-->0;){c=a[i][0],d=a[i][1];b[i]=b[i+1];if(f(c)!=f(d)){b[i]-=r[f(c)]*r[f(d)];u(c,d);}}for(i=0;i++<m;)printf("%ld\n",b[i]);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 800008
p:
	.zero	800008
	.globl	r
	.align 32
	.type	r, @object
	.size	r, 800008
r:
	.zero	800008
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	i
	.align 8
	.type	i, @object
	.size	i, 8
i:
	.zero	8
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 800008
b:
	.zero	800008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1600016
a:
	.zero	1600016
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	d
	.align 8
	.type	d, @object
	.size	d, 8
d:
	.zero	8
	.text
	.globl	f
	.type	f, @function
f:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movl	-4(%rbp), %eax
	cltq
	cmpq	%rax, %rdx
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	%eax, %edi
	call	f
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	f, .-f
	.globl	u
	.type	u, @function
u:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rax, %rcx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	r(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	u, .-u
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$8, %rsp
	.cfi_offset 3, -24
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	$0, i(%rip)
	jmp	.L6
.L7:
	movq	i(%rip), %rax
	salq	$4, %rax
	leaq	8(%rax), %rdx
	leaq	a(%rip), %rax
	addq	%rax, %rdx
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rcx
	leaq	a(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	%rax, i(%rip)
.L6:
	movq	i(%rip), %rdx
	movq	m(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L7
	movq	n(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	n(%rip), %rax
	imulq	%rdx, %rax
	movq	m(%rip), %rdx
	movq	%rax, %rcx
	shrq	$63, %rcx
	addq	%rcx, %rax
	sarq	%rax
	movq	%rax, %rcx
	salq	$3, %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	$0, i(%rip)
	jmp	.L8
.L9:
	movq	i(%rip), %rdx
	movq	i(%rip), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	$1, (%rdx,%rax)
.L8:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	cmpq	$100000, %rax
	jle	.L9
	movq	m(%rip), %rax
	movq	%rax, i(%rip)
	jmp	.L10
.L11:
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, c(%rip)
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, d(%rip)
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	i(%rip), %rdx
	leaq	0(,%rax,8), %rcx
	leaq	b(%rip), %rax
	movq	(%rcx,%rax), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	b(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	movl	%eax, %ebx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cmpl	%eax, %ebx
	je	.L10
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rbx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	imulq	%rax, %rbx
	movq	%rbx, %rsi
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	i(%rip), %rax
	movq	%rdx, %rcx
	subq	%rsi, %rcx
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	d(%rip), %rax
	movl	%eax, %edx
	movq	c(%rip), %rax
	movl	%edx, %esi
	movl	%eax, %edi
	call	u
.L10:
	movq	i(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, i(%rip)
	testq	%rax, %rax
	jg	.L11
	movq	$0, i(%rip)
	jmp	.L12
.L13:
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L12:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	movq	m(%rip), %rdx
	cmpq	%rdx, %rax
	jl	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	f
	.type	f, @function
f:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movslq	%edi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	p(%rip), %rbp
	movq	%r12, %rax
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	0(%rbp,%r12,8), %rdx
	cmpq	%r12, %rdx
	je	.L1
	movslq	%edx, %rbx
	movl	%edx, %eax
	movq	0(%rbp,%rbx,8), %rcx
	movq	%rbx, %rdx
	cmpq	%rbx, %rcx
	je	.L3
	movslq	%ecx, %r13
	movl	%ecx, %eax
	movq	0(%rbp,%r13,8), %rcx
	movq	%r13, %rdx
	cmpq	%r13, %rcx
	je	.L4
	movslq	%ecx, %r14
	movl	%ecx, %eax
	movq	0(%rbp,%r14,8), %rcx
	movq	%r14, %rdx
	cmpq	%r14, %rcx
	je	.L5
	movslq	%ecx, %rsi
	movl	%ecx, %eax
	movq	0(%rbp,%rsi,8), %rcx
	movq	%rsi, %rdx
	cmpq	%rsi, %rcx
	je	.L6
	movslq	%ecx, %r15
	movl	%ecx, %eax
	movq	0(%rbp,%r15,8), %rdi
	movq	%r15, %rdx
	cmpq	%r15, %rdi
	je	.L7
	movq	%rsi, 8(%rsp)
	call	f
	movq	8(%rsp), %rsi
	movslq	%eax, %rdx
	movq	%rdx, 0(%rbp,%r15,8)
.L7:
	movq	%rdx, 0(%rbp,%rsi,8)
.L6:
	movq	%rdx, 0(%rbp,%r14,8)
.L5:
	movq	%rdx, 0(%rbp,%r13,8)
.L4:
	movq	%rdx, 0(%rbp,%rbx,8)
.L3:
	movq	%rdx, 0(%rbp,%r12,8)
.L1:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	f, .-f
	.p2align 4
	.globl	u
	.type	u, @function
u:
.LFB1:
	.cfi_startproc
	endbr64
	leaq	p(%rip), %r9
	movslq	%edi, %r10
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%esi, %r8
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	(%r9,%r10,8), %rdx
	cmpq	%r10, %rdx
	je	.L13
	movslq	%edx, %r11
	movl	%edx, %eax
	movq	(%r9,%r11,8), %rcx
	movq	%r11, %rdx
	cmpq	%r11, %rcx
	je	.L14
	movslq	%ecx, %rbx
	movl	%ecx, %eax
	movq	(%r9,%rbx,8), %rcx
	movq	%rbx, %rdx
	cmpq	%rbx, %rcx
	je	.L15
	movslq	%ecx, %r12
	movl	%ecx, %eax
	movq	(%r9,%r12,8), %rcx
	movq	%r12, %rdx
	cmpq	%r12, %rcx
	je	.L16
	movslq	%ecx, %rbp
	movl	%ecx, %eax
	movq	(%r9,%rbp,8), %rdi
	movq	%rbp, %rdx
	cmpq	%rbp, %rdi
	je	.L17
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%r9,%rbp,8)
.L17:
	movq	%rdx, (%r9,%r12,8)
.L16:
	movq	%rdx, (%r9,%rbx,8)
.L15:
	movq	%rdx, (%r9,%r11,8)
.L14:
	movq	%rdx, (%r9,%r10,8)
	movslq	%eax, %r10
.L13:
	movq	(%r9,%r8,8), %rcx
	movq	%r8, %rdx
	cmpq	%r8, %rcx
	je	.L18
	movslq	%ecx, %r11
	movl	%ecx, %eax
	movq	(%r9,%r11,8), %rcx
	movq	%r11, %rdx
	cmpq	%r11, %rcx
	je	.L19
	movslq	%ecx, %rbp
	movl	%ecx, %eax
	movq	(%r9,%rbp,8), %rcx
	movq	%rbp, %rdx
	cmpq	%rbp, %rcx
	je	.L20
	movslq	%ecx, %rbx
	movl	%ecx, %eax
	movq	(%r9,%rbx,8), %rdi
	movq	%rbx, %rdx
	cmpq	%rbx, %rdi
	je	.L21
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%r9,%rbx,8)
.L21:
	movq	%rdx, (%r9,%rbp,8)
.L20:
	movq	%rdx, (%r9,%r11,8)
.L19:
	movq	%rdx, (%r9,%r8,8)
	movslq	%eax, %r8
.L18:
	leaq	r(%rip), %rax
	movq	%rdx, (%r9,%r10,8)
	movq	(%rax,%r10,8), %rdx
	addq	(%rax,%r8,8), %rdx
	movq	%rdx, (%rax,%r8,8)
	movq	%rdx, (%rax,%r10,8)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	u, .-u
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%ld%ld"
.LC2:
	.string	"%d%d"
.LC5:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	m(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC1(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	scanf@PLT
	movq	m(%rip), %rax
	movq	$0, i(%rip)
	testq	%rax, %rax
	jle	.L24
	xorl	%esi, %esi
	leaq	a(%rip), %rbx
	leaq	.LC2(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L25:
	salq	$4, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	8(%rbx,%rsi), %rdx
	addq	%rbx, %rsi
	call	scanf@PLT
	movq	i(%rip), %rax
	leaq	1(%rax), %rsi
	movq	m(%rip), %rax
	movq	%rsi, i(%rip)
	cmpq	%rax, %rsi
	jl	.L25
.L24:
	movq	n(%rip), %rdx
	leaq	b(%rip), %rbp
	movdqa	.LC0(%rip), %xmm0
	leaq	p(%rip), %rbx
	movdqa	.LC3(%rip), %xmm3
	movdqa	.LC4(%rip), %xmm2
	leaq	r(%rip), %r13
	leaq	-1(%rdx), %rcx
	imulq	%rdx, %rcx
	movq	%rcx, %rdx
	shrq	$63, %rdx
	addq	%rcx, %rdx
	sarq	%rdx
	movq	%rdx, 0(%rbp,%rax,8)
	movl	$8, %edx
	.p2align 4,,10
	.p2align 3
.L26:
	movdqa	%xmm0, %xmm1
	movups	%xmm2, 0(%r13,%rdx)
	paddq	%xmm3, %xmm0
	movups	%xmm1, (%rbx,%rdx)
	addq	$16, %rdx
	cmpq	$800008, %rdx
	jne	.L26
	movq	$100001, 800008+p(%rip)
	leaq	a(%rip), %r12
	movq	$1, 800008+r(%rip)
	jmp	.L43
	.p2align 4,,10
	.p2align 3
.L46:
	movq	%rcx, %rdx
	movq	0(%rbp,%rax,8), %rax
	salq	$4, %rdx
	addq	%r12, %rdx
	movq	%rax, 0(%rbp,%rcx,8)
	movq	(%rdx), %r8
	movq	8(%rdx), %rdx
	movq	%r8, c(%rip)
	movl	%r8d, %r9d
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %r10
	movq	%rdx, d(%rip)
	cmpq	%r8, %r10
	je	.L28
	movl	%r10d, %r9d
	movslq	%r10d, %r10
	movq	(%rbx,%r10,8), %r11
	movq	%r10, %rcx
	cmpq	%r10, %r11
	je	.L29
	movl	%r11d, %r9d
	movslq	%r11d, %r11
	movq	(%rbx,%r11,8), %r14
	movq	%r11, %rcx
	cmpq	%r11, %r14
	je	.L30
	movl	%r14d, %r9d
	movslq	%r14d, %r14
	movq	(%rbx,%r14,8), %r15
	movq	%r14, %rcx
	cmpq	%r14, %r15
	je	.L31
	movl	%r15d, %r9d
	movslq	%r15d, %r15
	movq	(%rbx,%r15,8), %rsi
	movq	%r15, %rcx
	cmpq	%r15, %rsi
	je	.L32
	movl	%esi, %r9d
	movslq	%esi, %rsi
	movq	(%rbx,%rsi,8), %rax
	movq	%rsi, %rcx
	cmpq	%rsi, %rax
	je	.L33
	movslq	%eax, %rdx
	movl	%eax, %r9d
	movq	(%rbx,%rdx,8), %rdi
	movq	%rdx, (%rsp)
	movq	%rdx, %rcx
	cmpq	%rdx, %rdi
	je	.L34
	movq	%rsi, 8(%rsp)
	call	f
	movq	(%rsp), %rdx
	movq	8(%rsp), %rsi
	movslq	%eax, %rcx
	movq	%rcx, (%rbx,%rdx,8)
	movq	%rcx, %r9
.L34:
	movq	%rcx, (%rbx,%rsi,8)
	movq	d(%rip), %rdx
.L33:
	movq	%rcx, (%rbx,%r15,8)
.L32:
	movq	%rcx, (%rbx,%r14,8)
.L31:
	movq	%rcx, (%rbx,%r11,8)
.L30:
	movq	%rcx, (%rbx,%r10,8)
.L29:
	movq	%rcx, (%rbx,%r8,8)
.L28:
	movslq	%edx, %r10
	movslq	%edx, %rdx
	movq	(%rbx,%rdx,8), %r8
	cmpq	%rdx, %r8
	je	.L35
	movl	%r8d, %eax
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %r11
	movq	%r8, %rdx
	cmpq	%r8, %r11
	je	.L36
	movl	%r11d, %eax
	movslq	%r11d, %r11
	movq	(%rbx,%r11,8), %r14
	movq	%r11, %rdx
	cmpq	%r11, %r14
	je	.L37
	movl	%r14d, %eax
	movslq	%r14d, %r14
	movq	(%rbx,%r14,8), %r15
	movq	%r14, %rdx
	cmpq	%r14, %r15
	je	.L38
	movl	%r15d, %eax
	movslq	%r15d, %r15
	movq	(%rbx,%r15,8), %rcx
	movq	%r15, %rdx
	cmpq	%r15, %rcx
	je	.L39
	movl	%ecx, %eax
	movslq	%ecx, %rcx
	movq	(%rbx,%rcx,8), %rdi
	movq	%rcx, %rdx
	cmpq	%rcx, %rdi
	je	.L40
	movslq	%edi, %rsi
	movq	(%rbx,%rsi,8), %rax
	movq	%rsi, (%rsp)
	movq	%rsi, %rdx
	cmpq	%rsi, %rax
	je	.L41
	movl	%eax, %edi
	movq	%rcx, 8(%rsp)
	call	f
	movq	(%rsp), %rsi
	movq	8(%rsp), %rcx
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%rsi,8)
	movq	%rdx, %rdi
.L41:
	movq	%rdx, (%rbx,%rcx,8)
	movl	%edi, %eax
.L40:
	movq	%rdx, (%rbx,%r15,8)
.L39:
	movq	%rdx, (%rbx,%r14,8)
.L38:
	movq	%rdx, (%rbx,%r11,8)
.L37:
	movq	%rdx, (%rbx,%r8,8)
.L36:
	movq	%rdx, (%rbx,%r10,8)
	movl	%eax, %r10d
.L35:
	cmpl	%r9d, %r10d
	jne	.L42
.L58:
	movq	i(%rip), %rax
.L43:
	leaq	-1(%rax), %rcx
	movq	%rcx, i(%rip)
	testq	%rax, %rax
	jg	.L46
	cmpq	$0, m(%rip)
	movl	$1, %eax
	movq	$1, i(%rip)
	leaq	.LC5(%rip), %rbx
	jle	.L56
	.p2align 4,,10
	.p2align 3
.L47:
	movq	0(%rbp,%rax,8), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	movq	i(%rip), %rdx
	cmpq	m(%rip), %rdx
	leaq	1(%rdx), %rax
	movq	%rax, i(%rip)
	jl	.L47
.L56:
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L42:
	.cfi_restore_state
	movq	c(%rip), %r8
	movl	%r8d, %eax
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %rdi
	cmpq	%r8, %rdi
	je	.L44
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%r8,8)
.L44:
	movq	d(%rip), %rsi
	cltq
	movq	0(%r13,%rax,8), %r8
	movslq	%esi, %r9
	movl	%esi, %eax
	movq	(%rbx,%r9,8), %rdi
	cmpq	%r9, %rdi
	je	.L45
	call	f
	movq	d(%rip), %rsi
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%r9,8)
.L45:
	movq	i(%rip), %rdx
	cltq
	movl	c(%rip), %edi
	imulq	0(%r13,%rax,8), %r8
	subq	%r8, 0(%rbp,%rdx,8)
	call	u
	jmp	.L58
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.globl	d
	.bss
	.align 8
	.type	d, @object
	.size	d, 8
d:
	.zero	8
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1600016
a:
	.zero	1600016
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 800008
b:
	.zero	800008
	.globl	i
	.align 8
	.type	i, @object
	.size	i, 8
i:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	r
	.align 32
	.type	r, @object
	.size	r, 800008
r:
	.zero	800008
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 800008
p:
	.zero	800008
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.quad	1
	.quad	2
	.align 16
.LC3:
	.quad	2
	.quad	2
	.align 16
.LC4:
	.quad	1
	.quad	1
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	f
	.type	f, @function
f:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movslq	%edi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	p(%rip), %rbp
	movq	%r12, %rax
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	0(%rbp,%r12,8), %rdx
	cmpq	%r12, %rdx
	je	.L1
	movslq	%edx, %rbx
	movl	%edx, %eax
	movq	0(%rbp,%rbx,8), %rcx
	movq	%rbx, %rdx
	cmpq	%rbx, %rcx
	je	.L3
	movslq	%ecx, %r13
	movl	%ecx, %eax
	movq	0(%rbp,%r13,8), %rcx
	movq	%r13, %rdx
	cmpq	%r13, %rcx
	je	.L4
	movslq	%ecx, %r14
	movl	%ecx, %eax
	movq	0(%rbp,%r14,8), %rcx
	movq	%r14, %rdx
	cmpq	%r14, %rcx
	je	.L5
	movslq	%ecx, %rsi
	movl	%ecx, %eax
	movq	0(%rbp,%rsi,8), %rcx
	movq	%rsi, %rdx
	cmpq	%rsi, %rcx
	je	.L6
	movslq	%ecx, %r15
	movl	%ecx, %eax
	movq	0(%rbp,%r15,8), %rdi
	movq	%r15, %rdx
	cmpq	%r15, %rdi
	je	.L7
	movq	%rsi, 8(%rsp)
	call	f
	movq	8(%rsp), %rsi
	movslq	%eax, %rdx
	movq	%rdx, 0(%rbp,%r15,8)
.L7:
	movq	%rdx, 0(%rbp,%rsi,8)
.L6:
	movq	%rdx, 0(%rbp,%r14,8)
.L5:
	movq	%rdx, 0(%rbp,%r13,8)
.L4:
	movq	%rdx, 0(%rbp,%rbx,8)
.L3:
	movq	%rdx, 0(%rbp,%r12,8)
.L1:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	f, .-f
	.p2align 4
	.globl	u
	.type	u, @function
u:
.LFB1:
	.cfi_startproc
	endbr64
	leaq	p(%rip), %r9
	movslq	%edi, %r10
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%esi, %r8
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	(%r9,%r10,8), %rdx
	cmpq	%r10, %rdx
	je	.L13
	movslq	%edx, %r11
	movl	%edx, %eax
	movq	(%r9,%r11,8), %rcx
	movq	%r11, %rdx
	cmpq	%r11, %rcx
	je	.L14
	movslq	%ecx, %rbx
	movl	%ecx, %eax
	movq	(%r9,%rbx,8), %rcx
	movq	%rbx, %rdx
	cmpq	%rbx, %rcx
	je	.L15
	movslq	%ecx, %r12
	movl	%ecx, %eax
	movq	(%r9,%r12,8), %rcx
	movq	%r12, %rdx
	cmpq	%r12, %rcx
	je	.L16
	movslq	%ecx, %rbp
	movl	%ecx, %eax
	movq	(%r9,%rbp,8), %rdi
	movq	%rbp, %rdx
	cmpq	%rbp, %rdi
	je	.L17
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%r9,%rbp,8)
.L17:
	movq	%rdx, (%r9,%r12,8)
.L16:
	movq	%rdx, (%r9,%rbx,8)
.L15:
	movq	%rdx, (%r9,%r11,8)
.L14:
	movq	%rdx, (%r9,%r10,8)
	movslq	%eax, %r10
.L13:
	movq	(%r9,%r8,8), %rcx
	movq	%r8, %rdx
	cmpq	%r8, %rcx
	je	.L18
	movslq	%ecx, %r11
	movl	%ecx, %eax
	movq	(%r9,%r11,8), %rcx
	movq	%r11, %rdx
	cmpq	%r11, %rcx
	je	.L19
	movslq	%ecx, %rbp
	movl	%ecx, %eax
	movq	(%r9,%rbp,8), %rcx
	movq	%rbp, %rdx
	cmpq	%rbp, %rcx
	je	.L20
	movslq	%ecx, %rbx
	movl	%ecx, %eax
	movq	(%r9,%rbx,8), %rdi
	movq	%rbx, %rdx
	cmpq	%rbx, %rdi
	je	.L21
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%r9,%rbx,8)
.L21:
	movq	%rdx, (%r9,%rbp,8)
.L20:
	movq	%rdx, (%r9,%r11,8)
.L19:
	movq	%rdx, (%r9,%r8,8)
	movslq	%eax, %r8
.L18:
	leaq	r(%rip), %rax
	movq	%rdx, (%r9,%r10,8)
	movq	(%rax,%r10,8), %rdx
	addq	(%rax,%r8,8), %rdx
	movq	%rdx, (%rax,%r8,8)
	movq	%rdx, (%rax,%r10,8)
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	u, .-u
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%ld%ld"
.LC2:
	.string	"%d%d"
.LC5:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	m(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC1(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	scanf@PLT
	movq	m(%rip), %rax
	movq	$0, i(%rip)
	testq	%rax, %rax
	jle	.L24
	xorl	%esi, %esi
	leaq	a(%rip), %rbx
	leaq	.LC2(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L25:
	salq	$4, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	8(%rbx,%rsi), %rdx
	addq	%rbx, %rsi
	call	scanf@PLT
	movq	i(%rip), %rax
	leaq	1(%rax), %rsi
	movq	m(%rip), %rax
	movq	%rsi, i(%rip)
	cmpq	%rax, %rsi
	jl	.L25
.L24:
	movq	n(%rip), %rdx
	leaq	b(%rip), %rbp
	movdqa	.LC0(%rip), %xmm0
	leaq	p(%rip), %rbx
	movdqa	.LC3(%rip), %xmm3
	movdqa	.LC4(%rip), %xmm2
	leaq	r(%rip), %r13
	leaq	-1(%rdx), %rcx
	imulq	%rdx, %rcx
	movq	%rcx, %rdx
	shrq	$63, %rdx
	addq	%rcx, %rdx
	sarq	%rdx
	movq	%rdx, 0(%rbp,%rax,8)
	movl	$8, %edx
	.p2align 4,,10
	.p2align 3
.L26:
	movdqa	%xmm0, %xmm1
	movups	%xmm2, 0(%r13,%rdx)
	paddq	%xmm3, %xmm0
	movups	%xmm1, (%rbx,%rdx)
	addq	$16, %rdx
	cmpq	$800008, %rdx
	jne	.L26
	movq	$100001, 800008+p(%rip)
	leaq	a(%rip), %r12
	movq	$1, 800008+r(%rip)
	jmp	.L43
	.p2align 4,,10
	.p2align 3
.L46:
	movq	%rcx, %rdx
	movq	0(%rbp,%rax,8), %rax
	salq	$4, %rdx
	addq	%r12, %rdx
	movq	%rax, 0(%rbp,%rcx,8)
	movq	(%rdx), %r8
	movq	8(%rdx), %rdx
	movq	%r8, c(%rip)
	movl	%r8d, %r9d
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %r10
	movq	%rdx, d(%rip)
	cmpq	%r8, %r10
	je	.L28
	movl	%r10d, %r9d
	movslq	%r10d, %r10
	movq	(%rbx,%r10,8), %r11
	movq	%r10, %rcx
	cmpq	%r10, %r11
	je	.L29
	movl	%r11d, %r9d
	movslq	%r11d, %r11
	movq	(%rbx,%r11,8), %r14
	movq	%r11, %rcx
	cmpq	%r11, %r14
	je	.L30
	movl	%r14d, %r9d
	movslq	%r14d, %r14
	movq	(%rbx,%r14,8), %r15
	movq	%r14, %rcx
	cmpq	%r14, %r15
	je	.L31
	movl	%r15d, %r9d
	movslq	%r15d, %r15
	movq	(%rbx,%r15,8), %rsi
	movq	%r15, %rcx
	cmpq	%r15, %rsi
	je	.L32
	movl	%esi, %r9d
	movslq	%esi, %rsi
	movq	(%rbx,%rsi,8), %rax
	movq	%rsi, %rcx
	cmpq	%rsi, %rax
	je	.L33
	movslq	%eax, %rdx
	movl	%eax, %r9d
	movq	(%rbx,%rdx,8), %rdi
	movq	%rdx, (%rsp)
	movq	%rdx, %rcx
	cmpq	%rdx, %rdi
	je	.L34
	movq	%rsi, 8(%rsp)
	call	f
	movq	(%rsp), %rdx
	movq	8(%rsp), %rsi
	movslq	%eax, %rcx
	movq	%rcx, (%rbx,%rdx,8)
	movq	%rcx, %r9
.L34:
	movq	%rcx, (%rbx,%rsi,8)
	movq	d(%rip), %rdx
.L33:
	movq	%rcx, (%rbx,%r15,8)
.L32:
	movq	%rcx, (%rbx,%r14,8)
.L31:
	movq	%rcx, (%rbx,%r11,8)
.L30:
	movq	%rcx, (%rbx,%r10,8)
.L29:
	movq	%rcx, (%rbx,%r8,8)
.L28:
	movslq	%edx, %r10
	movslq	%edx, %rdx
	movq	(%rbx,%rdx,8), %r8
	cmpq	%rdx, %r8
	je	.L35
	movl	%r8d, %eax
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %r11
	movq	%r8, %rdx
	cmpq	%r8, %r11
	je	.L36
	movl	%r11d, %eax
	movslq	%r11d, %r11
	movq	(%rbx,%r11,8), %r14
	movq	%r11, %rdx
	cmpq	%r11, %r14
	je	.L37
	movl	%r14d, %eax
	movslq	%r14d, %r14
	movq	(%rbx,%r14,8), %r15
	movq	%r14, %rdx
	cmpq	%r14, %r15
	je	.L38
	movl	%r15d, %eax
	movslq	%r15d, %r15
	movq	(%rbx,%r15,8), %rcx
	movq	%r15, %rdx
	cmpq	%r15, %rcx
	je	.L39
	movl	%ecx, %eax
	movslq	%ecx, %rcx
	movq	(%rbx,%rcx,8), %rdi
	movq	%rcx, %rdx
	cmpq	%rcx, %rdi
	je	.L40
	movslq	%edi, %rsi
	movq	(%rbx,%rsi,8), %rax
	movq	%rsi, (%rsp)
	movq	%rsi, %rdx
	cmpq	%rsi, %rax
	je	.L41
	movl	%eax, %edi
	movq	%rcx, 8(%rsp)
	call	f
	movq	(%rsp), %rsi
	movq	8(%rsp), %rcx
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%rsi,8)
	movq	%rdx, %rdi
.L41:
	movq	%rdx, (%rbx,%rcx,8)
	movl	%edi, %eax
.L40:
	movq	%rdx, (%rbx,%r15,8)
.L39:
	movq	%rdx, (%rbx,%r14,8)
.L38:
	movq	%rdx, (%rbx,%r11,8)
.L37:
	movq	%rdx, (%rbx,%r8,8)
.L36:
	movq	%rdx, (%rbx,%r10,8)
	movl	%eax, %r10d
.L35:
	cmpl	%r9d, %r10d
	jne	.L42
.L58:
	movq	i(%rip), %rax
.L43:
	leaq	-1(%rax), %rcx
	movq	%rcx, i(%rip)
	testq	%rax, %rax
	jg	.L46
	cmpq	$0, m(%rip)
	movl	$1, %eax
	movq	$1, i(%rip)
	leaq	.LC5(%rip), %rbx
	jle	.L56
	.p2align 4,,10
	.p2align 3
.L47:
	movq	0(%rbp,%rax,8), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	movq	i(%rip), %rdx
	cmpq	m(%rip), %rdx
	leaq	1(%rdx), %rax
	movq	%rax, i(%rip)
	jl	.L47
.L56:
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L42:
	.cfi_restore_state
	movq	c(%rip), %r8
	movl	%r8d, %eax
	movslq	%r8d, %r8
	movq	(%rbx,%r8,8), %rdi
	cmpq	%r8, %rdi
	je	.L44
	call	f
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%r8,8)
.L44:
	movq	d(%rip), %rsi
	cltq
	movq	0(%r13,%rax,8), %r8
	movslq	%esi, %r9
	movl	%esi, %eax
	movq	(%rbx,%r9,8), %rdi
	cmpq	%r9, %rdi
	je	.L45
	call	f
	movq	d(%rip), %rsi
	movslq	%eax, %rdx
	movq	%rdx, (%rbx,%r9,8)
.L45:
	movq	i(%rip), %rdx
	cltq
	movl	c(%rip), %edi
	imulq	0(%r13,%rax,8), %r8
	subq	%r8, 0(%rbp,%rdx,8)
	call	u
	jmp	.L58
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.globl	d
	.bss
	.align 8
	.type	d, @object
	.size	d, 8
d:
	.zero	8
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1600016
a:
	.zero	1600016
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 800008
b:
	.zero	800008
	.globl	i
	.align 8
	.type	i, @object
	.size	i, 8
i:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	r
	.align 32
	.type	r, @object
	.size	r, 800008
r:
	.zero	800008
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 800008
p:
	.zero	800008
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.quad	1
	.quad	2
	.align 16
.LC3:
	.quad	2
	.quad	2
	.align 16
.LC4:
	.quad	1
	.quad	1
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);p[x]=y;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i++<N;){p[i]=i;r[i]=1;};for(i=m;i-->0;){c=a[i][0],d=a[i][1];b[i]=b[i+1];if(f(c)!=f(d)){b[i]-=r[f(c)]*r[f(d)];u(c,d);}}for(i=0;i++<m;)printf("%ld\n",b[i]);}
6 5
3 3
1 2
5 6
3 4
4 5
 4 5
1 2
3 4
1 3
3 3
1 4
 2 1
2 2
 6 5
3 3
1 2
5 6
3 4
2 5
 4 5
1 2
3 4
1 3
3 3
1 1
 6 5
2 3
1 2
5 6
3 4
4 3
 4 5
1 0
3 4
1 3
2 3
1 4
 6 5
3 3
1 1
5 6
3 4
4 5
 4 5
1 2
3 4
1 3
3 2
1 1
 4 1
1 3
3 4
1 3
3 3
1 1

8
9
12
14
15
 3
3
5
5
6
 1
 8
11
13
14
15
 3
5
6
6
6
 12
13
14
14
15
 0
0
4
5
6
 9
9
12
14
15
 0
3
5
6
6
 6

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);p[x]=y;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i++<N;){p[i]=i;r[i]=1;};for(i=m;i-->0;){c=a[i][0],d=a[i][1];b[i]=b[i+1];if(f(c)!=f(d)){b[i]-=r[f(c)]*r[f(d)];u(c,d);}}for(i=0;i++<m;)printf("%ld\n",b[i]);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 800008
p:
	.zero	800008
	.globl	r
	.align 32
	.type	r, @object
	.size	r, 800008
r:
	.zero	800008
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	i
	.align 8
	.type	i, @object
	.size	i, 8
i:
	.zero	8
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 800008
b:
	.zero	800008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1600016
a:
	.zero	1600016
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	d
	.align 8
	.type	d, @object
	.size	d, 8
d:
	.zero	8
	.text
	.globl	f
	.type	f, @function
f:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movl	-4(%rbp), %eax
	cltq
	cmpq	%rax, %rdx
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	%eax, %edi
	call	f
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	f, .-f
	.globl	u
	.type	u, @function
u:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rax, %rcx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	r(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	u, .-u
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$8, %rsp
	.cfi_offset 3, -24
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	$0, i(%rip)
	jmp	.L6
.L7:
	movq	i(%rip), %rax
	salq	$4, %rax
	leaq	8(%rax), %rdx
	leaq	a(%rip), %rax
	addq	%rax, %rdx
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rcx
	leaq	a(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	%rax, i(%rip)
.L6:
	movq	i(%rip), %rdx
	movq	m(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L7
	movq	n(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	n(%rip), %rax
	imulq	%rdx, %rax
	movq	m(%rip), %rdx
	movq	%rax, %rcx
	shrq	$63, %rcx
	addq	%rcx, %rax
	sarq	%rax
	movq	%rax, %rcx
	salq	$3, %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	$0, i(%rip)
	jmp	.L8
.L9:
	movq	i(%rip), %rdx
	movq	i(%rip), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	$1, (%rdx,%rax)
.L8:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	cmpq	$100000, %rax
	jle	.L9
	movq	m(%rip), %rax
	movq	%rax, i(%rip)
	jmp	.L10
.L11:
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, c(%rip)
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, d(%rip)
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	i(%rip), %rdx
	leaq	0(,%rax,8), %rcx
	leaq	b(%rip), %rax
	movq	(%rcx,%rax), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	b(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	movl	%eax, %ebx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cmpl	%eax, %ebx
	je	.L10
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rbx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	imulq	%rax, %rbx
	movq	%rbx, %rsi
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	i(%rip), %rax
	movq	%rdx, %rcx
	subq	%rsi, %rcx
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	d(%rip), %rax
	movl	%eax, %edx
	movq	c(%rip), %rax
	movl	%edx, %esi
	movl	%eax, %edi
	call	u
.L10:
	movq	i(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, i(%rip)
	testq	%rax, %rax
	jg	.L11
	movq	$0, i(%rip)
	jmp	.L12
.L13:
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L12:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	movq	m(%rip), %rdx
	cmpq	%rdx, %rax
	jl	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 800008
p:
	.zero	800008
	.globl	r
	.align 32
	.type	r, @object
	.size	r, 800008
r:
	.zero	800008
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	i
	.align 8
	.type	i, @object
	.size	i, 8
i:
	.zero	8
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 800008
b:
	.zero	800008
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1600016
a:
	.zero	1600016
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	d
	.align 8
	.type	d, @object
	.size	d, 8
d:
	.zero	8
	.text
	.globl	f
	.type	f, @function
f:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movl	-4(%rbp), %eax
	cltq
	cmpq	%rax, %rdx
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	%eax, %edi
	call	f
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	p(%rip), %rax
	movq	(%rdx,%rax), %rax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	f, .-f
	.globl	u
	.type	u, @function
u:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	call	f
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltq
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	addq	%rax, %rcx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	movl	-4(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	leaq	r(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	u, .-u
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$8, %rsp
	.cfi_offset 3, -24
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	$0, i(%rip)
	jmp	.L6
.L7:
	movq	i(%rip), %rax
	salq	$4, %rax
	leaq	8(%rax), %rdx
	leaq	a(%rip), %rax
	addq	%rax, %rdx
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rcx
	leaq	a(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	%rax, i(%rip)
.L6:
	movq	i(%rip), %rdx
	movq	m(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L7
	movq	n(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	n(%rip), %rax
	imulq	%rdx, %rax
	movq	m(%rip), %rdx
	movq	%rax, %rcx
	shrq	$63, %rcx
	addq	%rcx, %rax
	sarq	%rax
	movq	%rax, %rcx
	salq	$3, %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	$0, i(%rip)
	jmp	.L8
.L9:
	movq	i(%rip), %rdx
	movq	i(%rip), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	p(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	$1, (%rdx,%rax)
.L8:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	cmpq	$100000, %rax
	jle	.L9
	movq	m(%rip), %rax
	movq	%rax, i(%rip)
	jmp	.L10
.L11:
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, c(%rip)
	movq	i(%rip), %rax
	salq	$4, %rax
	movq	%rax, %rdx
	leaq	8+a(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, d(%rip)
	movq	i(%rip), %rax
	addq	$1, %rax
	movq	i(%rip), %rdx
	leaq	0(,%rax,8), %rcx
	leaq	b(%rip), %rax
	movq	(%rcx,%rax), %rax
	leaq	0(,%rdx,8), %rcx
	leaq	b(%rip), %rdx
	movq	%rax, (%rcx,%rdx)
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	movl	%eax, %ebx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cmpl	%eax, %ebx
	je	.L10
	movq	c(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rbx
	movq	d(%rip), %rax
	movl	%eax, %edi
	call	f
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	r(%rip), %rax
	movq	(%rdx,%rax), %rax
	imulq	%rax, %rbx
	movq	%rbx, %rsi
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rdx
	movq	i(%rip), %rax
	movq	%rdx, %rcx
	subq	%rsi, %rcx
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	%rcx, (%rdx,%rax)
	movq	d(%rip), %rax
	movl	%eax, %edx
	movq	c(%rip), %rax
	movl	%edx, %esi
	movl	%eax, %edi
	call	u
.L10:
	movq	i(%rip), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, i(%rip)
	testq	%rax, %rax
	jg	.L11
	movq	$0, i(%rip)
	jmp	.L12
.L13:
	movq	i(%rip), %rax
	leaq	0(,%rax,8), %rdx
	leaq	b(%rip), %rax
	movq	(%rdx,%rax), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L12:
	movq	i(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, i(%rip)
	movq	m(%rip), %rdx
	cmpq	%rdx, %rax
	jl	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
