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

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

typedef struct{
	TLong b;
	TLong c;
} BC;

int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *p,const int *q){
	return ((BC *)q)->c - ((BC *)p)->c;
}

int main(int argc, char const *argv[])
{
	TLong n,m;
	TLong a[100003];
	BC bc[100003];
	TLong max = 0,sum = 0;
	TLong cnt = 0,pcnt = 0;

	scanf("%lld%lld",&n,&m);
	for (TLong i = 0; i < n; ++i)	scanf("%lld",&a[i]);
	for (TLong i = 0; i < m; ++i)	scanf("%lld%lld",&bc[i].b, &bc[i].c);
	qsort(a,n,sizeof(TLong),ASC);
	qsort(bc,m,sizeof(BC),DESC);

	for (TLong i = 0; i < n; ++i)
	{
		if(pcnt >= bc[cnt].b){
			++cnt;
			pcnt = 0;
			if(cnt >= m)	break;
		}
		if(a[i] < bc[cnt].c) a[i] = bc[cnt].c;
		else break;
		++pcnt;
	}
	for (TLong i = 0; i < n; ++i)	sum += a[i];
	printf("%lld\n", sum);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ASC
	.type	ASC, @function
ASC:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ASC, .-ASC
	.globl	DESC
	.type	DESC, @function
DESC:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	DESC, .-DESC
	.section	.rodata
.LC0:
	.string	"%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-2396160(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$4032, %rsp
	movl	%edi, -2400180(%rbp)
	movq	%rsi, -2400192(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2400104(%rbp)
	movq	$0, -2400160(%rbp)
	movq	$0, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	leaq	-2400168(%rbp), %rdx
	leaq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -2400136(%rbp)
	jmp	.L6
.L7:
	leaq	-2400096(%rbp), %rdx
	movq	-2400136(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400136(%rbp)
.L6:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400136(%rbp)
	jl	.L7
	movq	$0, -2400128(%rbp)
	jmp	.L8
.L9:
	leaq	-1600064(%rbp), %rdx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rdx, %rax
	leaq	8(%rax), %rdx
	leaq	-1600064(%rbp), %rcx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400128(%rbp)
.L8:
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400128(%rbp)
	jl	.L9
	movq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	-2400096(%rbp), %rax
	leaq	ASC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-2400168(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600064(%rbp), %rax
	leaq	DESC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$16, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -2400120(%rbp)
	jmp	.L10
.L15:
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600064, %rax
	movq	(%rax), %rax
	cmpq	%rax, -2400144(%rbp)
	jl	.L11
	addq	$1, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400152(%rbp)
	jge	.L20
.L11:
	movq	-2400120(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rdx
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L21
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rdx
	movq	-2400120(%rbp), %rax
	movq	%rdx, -2400096(%rbp,%rax,8)
	addq	$1, -2400144(%rbp)
	addq	$1, -2400120(%rbp)
.L10:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400120(%rbp)
	jl	.L15
	jmp	.L12
.L20:
	nop
	jmp	.L12
.L21:
	nop
.L12:
	movq	$0, -2400112(%rbp)
	jmp	.L16
.L17:
	movq	-2400112(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rax
	addq	%rax, -2400160(%rbp)
	addq	$1, -2400112(%rbp)
.L16:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400112(%rbp)
	jl	.L17
	movq	-2400160(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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	ASC
	.type	ASC, @function
ASC:
.LFB51:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE51:
	.size	ASC, .-ASC
	.p2align 4
	.globl	DESC
	.type	DESC, @function
DESC:
.LFB52:
	.cfi_startproc
	endbr64
	movq	8(%rsi), %rax
	subl	8(%rdi), %eax
	ret
	.cfi_endproc
.LFE52:
	.size	DESC, .-DESC
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB53:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-2396160(%rsp), %r11
	.cfi_def_cfa 11, 2396208
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3952, %rsp
	.cfi_def_cfa_offset 2400160
	leaq	.LC0(%rip), %r13
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r14
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 2400104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %rbx
	movq	%rbx, %r12
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L8:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	addq	$8, %r12
	cmpq	%rbp, (%rsp)
	jg	.L8
.L9:
	leaq	800048(%rsp), %r14
	xorl	%r12d, %r12d
	cmpq	$0, 8(%rsp)
	movq	%r14, %rbp
	jle	.L7
	.p2align 4,,10
	.p2align 3
.L12:
	leaq	8(%rbp), %rdx
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	addq	$1, %r12
	addq	$16, %rbp
	cmpq	%r12, 8(%rsp)
	jg	.L12
.L7:
	movq	(%rsp), %rsi
	leaq	ASC(%rip), %rcx
	movl	$8, %edx
	movq	%rbx, %rdi
	call	qsort@PLT
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	movl	$16, %edx
	leaq	DESC(%rip), %rcx
	call	qsort@PLT
	movq	(%rsp), %rdi
	xorl	%edx, %edx
	testq	%rdi, %rdi
	jle	.L11
	movq	8(%rsp), %r8
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L30:
	movq	%rsi, (%rbx,%rax,8)
	addq	$1, %rax
	addq	$1, %rcx
	cmpq	%rdi, %rax
	je	.L16
.L17:
	movq	%rdx, %rsi
	salq	$4, %rsi
	cmpq	%rcx, 800048(%rsp,%rsi)
	jg	.L13
	addq	$1, %rdx
	cmpq	%rdx, %r8
	jle	.L16
	xorl	%ecx, %ecx
.L13:
	movq	%rdx, %rsi
	salq	$4, %rsi
	movq	800056(%rsp,%rsi), %rsi
	cmpq	%rsi, (%rbx,%rax,8)
	jl	.L30
.L16:
	cmpq	$1, %rdi
	je	.L22
	movq	%rdi, %rax
	pxor	%xmm0, %xmm0
	shrq	%rax
	salq	$4, %rax
	addq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L15:
	paddq	(%rbx), %xmm0
	addq	$16, %rbx
	cmpq	%rbx, %rax
	jne	.L15
	movdqa	%xmm0, %xmm1
	movq	%rdi, %rax
	psrldq	$8, %xmm1
	andq	$-2, %rax
	andl	$1, %edi
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rdx
	je	.L11
.L14:
	addq	16(%rsp,%rax,8), %rdx
.L11:
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	2400104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$2400112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L22:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%edx, %edx
	jmp	.L14
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE53:
	.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:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	ASC
	.type	ASC, @function
ASC:
.LFB51:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE51:
	.size	ASC, .-ASC
	.p2align 4
	.globl	DESC
	.type	DESC, @function
DESC:
.LFB52:
	.cfi_startproc
	endbr64
	movq	8(%rsi), %rax
	subl	8(%rdi), %eax
	ret
	.cfi_endproc
.LFE52:
	.size	DESC, .-DESC
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB53:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-2396160(%rsp), %r11
	.cfi_def_cfa 11, 2396208
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3952, %rsp
	.cfi_def_cfa_offset 2400160
	leaq	.LC0(%rip), %r13
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r14
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 2400104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	movq	%rsp, %rsi
	leaq	16(%rsp), %rbx
	movq	%rbx, %r12
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L8:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	addq	$8, %r12
	cmpq	%rbp, (%rsp)
	jg	.L8
.L9:
	leaq	800048(%rsp), %r14
	xorl	%r12d, %r12d
	cmpq	$0, 8(%rsp)
	movq	%r14, %rbp
	jle	.L7
	.p2align 4,,10
	.p2align 3
.L12:
	leaq	8(%rbp), %rdx
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	addq	$1, %r12
	addq	$16, %rbp
	cmpq	%r12, 8(%rsp)
	jg	.L12
.L7:
	movq	(%rsp), %rsi
	leaq	ASC(%rip), %rcx
	movl	$8, %edx
	movq	%rbx, %rdi
	call	qsort@PLT
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	movl	$16, %edx
	leaq	DESC(%rip), %rcx
	call	qsort@PLT
	movq	(%rsp), %rdi
	xorl	%edx, %edx
	testq	%rdi, %rdi
	jle	.L11
	movq	8(%rsp), %r8
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L30:
	movq	%rsi, (%rbx,%rax,8)
	addq	$1, %rax
	addq	$1, %rcx
	cmpq	%rdi, %rax
	je	.L16
.L17:
	movq	%rdx, %rsi
	salq	$4, %rsi
	cmpq	%rcx, 800048(%rsp,%rsi)
	jg	.L13
	addq	$1, %rdx
	cmpq	%rdx, %r8
	jle	.L16
	xorl	%ecx, %ecx
.L13:
	movq	%rdx, %rsi
	salq	$4, %rsi
	movq	800056(%rsp,%rsi), %rsi
	cmpq	%rsi, (%rbx,%rax,8)
	jl	.L30
.L16:
	cmpq	$1, %rdi
	je	.L22
	movq	%rdi, %rax
	pxor	%xmm0, %xmm0
	shrq	%rax
	salq	$4, %rax
	addq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L15:
	paddq	(%rbx), %xmm0
	addq	$16, %rbx
	cmpq	%rbx, %rax
	jne	.L15
	movdqa	%xmm0, %xmm1
	movq	%rdi, %rax
	psrldq	$8, %xmm1
	andq	$-2, %rax
	andl	$1, %edi
	paddq	%xmm1, %xmm0
	movq	%xmm0, %rdx
	je	.L11
.L14:
	addq	16(%rsp,%rax,8), %rdx
.L11:
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	2400104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$2400112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L22:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%edx, %edx
	jmp	.L14
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE53:
	.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:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

typedef struct{
	TLong b;
	TLong c;
} BC;

int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *p,const int *q){
	return ((BC *)q)->c - ((BC *)p)->c;
}

int main(int argc, char const *argv[])
{
	TLong n,m;
	TLong a[100003];
	BC bc[100003];
	TLong max = 0,sum = 0;
	TLong cnt = 0,pcnt = 0;

	scanf("%lld%lld",&n,&m);
	for (TLong i = 0; i < n; ++i)	scanf("%lld",&a[i]);
	for (TLong i = 0; i < m; ++i)	scanf("%lld%lld",&bc[i].b, &bc[i].c);
	qsort(a,n,sizeof(TLong),ASC);
	qsort(bc,m,sizeof(BC),DESC);

	for (TLong i = 0; i < n; ++i)
	{
		if(pcnt >= bc[cnt].b){
			++cnt;
			pcnt = 0;
			if(cnt >= m)	break;
		}
		if(a[i] < bc[cnt].c) a[i] = bc[cnt].c;
		else break;
		++pcnt;
	}
	for (TLong i = 0; i < n; ++i)	sum += a[i];
	printf("%lld\n", sum);
	return 0;
}

10 3
1 8 5 7 100 4 7 33 13 5
3 10
4 30
1 4
 3 2
5 1 1
2 3
1 5
 3 2
100 100 100
0 99
3 99
 11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000001
 10 2
0 8 5 7 100 4 7 33 24 5
3 10
4 30
1 4
 3 2
5 1 1
2 3
1 7
 10 2
0 8 5 7 100 4 7 33 24 5
3 15
4 30
1 4
 3 2
5 1 1
2 3
1 6
 3 2
5 1 1
2 3
2 6
 10 2
0 4 5 7 100 4 7 33 33 5
3 15
4 30
1 4

296
 13
 300
 10000000004
 307
 15
 322
 14
 17
 331

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

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

typedef struct{
	TLong b;
	TLong c;
} BC;

int ASC(const int *a,const int *b){
	return (*a - *b);
}

int DESC(const int *p,const int *q){
	return ((BC *)q)->c - ((BC *)p)->c;
}

int main(int argc, char const *argv[])
{
	TLong n,m;
	TLong a[100003];
	BC bc[100003];
	TLong max = 0,sum = 0;
	TLong cnt = 0,pcnt = 0;

	scanf("%lld%lld",&n,&m);
	for (TLong i = 0; i < n; ++i)	scanf("%lld",&a[i]);
	for (TLong i = 0; i < m; ++i)	scanf("%lld%lld",&bc[i].b, &bc[i].c);
	qsort(a,n,sizeof(TLong),ASC);
	qsort(bc,m,sizeof(BC),DESC);

	for (TLong i = 0; i < n; ++i)
	{
		if(pcnt >= bc[cnt].b){
			++cnt;
			pcnt = 0;
			if(cnt >= m)	break;
		}
		if(a[i] < bc[cnt].c) a[i] = bc[cnt].c;
		else break;
		++pcnt;
	}
	for (TLong i = 0; i < n; ++i)	sum += a[i];
	printf("%lld\n", sum);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ASC
	.type	ASC, @function
ASC:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ASC, .-ASC
	.globl	DESC
	.type	DESC, @function
DESC:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	DESC, .-DESC
	.section	.rodata
.LC0:
	.string	"%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-2396160(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$4032, %rsp
	movl	%edi, -2400180(%rbp)
	movq	%rsi, -2400192(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2400104(%rbp)
	movq	$0, -2400160(%rbp)
	movq	$0, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	leaq	-2400168(%rbp), %rdx
	leaq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -2400136(%rbp)
	jmp	.L6
.L7:
	leaq	-2400096(%rbp), %rdx
	movq	-2400136(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400136(%rbp)
.L6:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400136(%rbp)
	jl	.L7
	movq	$0, -2400128(%rbp)
	jmp	.L8
.L9:
	leaq	-1600064(%rbp), %rdx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rdx, %rax
	leaq	8(%rax), %rdx
	leaq	-1600064(%rbp), %rcx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400128(%rbp)
.L8:
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400128(%rbp)
	jl	.L9
	movq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	-2400096(%rbp), %rax
	leaq	ASC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-2400168(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600064(%rbp), %rax
	leaq	DESC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$16, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -2400120(%rbp)
	jmp	.L10
.L15:
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600064, %rax
	movq	(%rax), %rax
	cmpq	%rax, -2400144(%rbp)
	jl	.L11
	addq	$1, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400152(%rbp)
	jge	.L20
.L11:
	movq	-2400120(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rdx
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L21
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rdx
	movq	-2400120(%rbp), %rax
	movq	%rdx, -2400096(%rbp,%rax,8)
	addq	$1, -2400144(%rbp)
	addq	$1, -2400120(%rbp)
.L10:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400120(%rbp)
	jl	.L15
	jmp	.L12
.L20:
	nop
	jmp	.L12
.L21:
	nop
.L12:
	movq	$0, -2400112(%rbp)
	jmp	.L16
.L17:
	movq	-2400112(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rax
	addq	%rax, -2400160(%rbp)
	addq	$1, -2400112(%rbp)
.L16:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400112(%rbp)
	jl	.L17
	movq	-2400160(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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	ASC
	.type	ASC, @function
ASC:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ASC, .-ASC
	.globl	DESC
	.type	DESC, @function
DESC:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movq	8(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	DESC, .-DESC
	.section	.rodata
.LC0:
	.string	"%lld%lld"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-2396160(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$4032, %rsp
	movl	%edi, -2400180(%rbp)
	movq	%rsi, -2400192(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2400104(%rbp)
	movq	$0, -2400160(%rbp)
	movq	$0, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	leaq	-2400168(%rbp), %rdx
	leaq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -2400136(%rbp)
	jmp	.L6
.L7:
	leaq	-2400096(%rbp), %rdx
	movq	-2400136(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400136(%rbp)
.L6:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400136(%rbp)
	jl	.L7
	movq	$0, -2400128(%rbp)
	jmp	.L8
.L9:
	leaq	-1600064(%rbp), %rdx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rdx, %rax
	leaq	8(%rax), %rdx
	leaq	-1600064(%rbp), %rcx
	movq	-2400128(%rbp), %rax
	salq	$4, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -2400128(%rbp)
.L8:
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400128(%rbp)
	jl	.L9
	movq	-2400176(%rbp), %rax
	movq	%rax, %rsi
	leaq	-2400096(%rbp), %rax
	leaq	ASC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-2400168(%rbp), %rax
	movq	%rax, %rsi
	leaq	-1600064(%rbp), %rax
	leaq	DESC(%rip), %rdx
	movq	%rdx, %rcx
	movl	$16, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -2400120(%rbp)
	jmp	.L10
.L15:
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600064, %rax
	movq	(%rax), %rax
	cmpq	%rax, -2400144(%rbp)
	jl	.L11
	addq	$1, -2400152(%rbp)
	movq	$0, -2400144(%rbp)
	movq	-2400168(%rbp), %rax
	cmpq	%rax, -2400152(%rbp)
	jge	.L20
.L11:
	movq	-2400120(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rdx
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L21
	movq	-2400152(%rbp), %rax
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$1600056, %rax
	movq	(%rax), %rdx
	movq	-2400120(%rbp), %rax
	movq	%rdx, -2400096(%rbp,%rax,8)
	addq	$1, -2400144(%rbp)
	addq	$1, -2400120(%rbp)
.L10:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400120(%rbp)
	jl	.L15
	jmp	.L12
.L20:
	nop
	jmp	.L12
.L21:
	nop
.L12:
	movq	$0, -2400112(%rbp)
	jmp	.L16
.L17:
	movq	-2400112(%rbp), %rax
	movq	-2400096(%rbp,%rax,8), %rax
	addq	%rax, -2400160(%rbp)
	addq	$1, -2400112(%rbp)
.L16:
	movq	-2400176(%rbp), %rax
	cmpq	%rax, -2400112(%rbp)
	jl	.L17
	movq	-2400160(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.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:
