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>
int comp(const void *p,const void *q){
	return *(int *)p - *(int *)q;
}
int main(){
	int i,j,n,m,t[205],w[105],s[105],e[105],p;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&w[i],&s[i],&e[i]);
			t[i*2]=s[i];t[i*2+1]=e[i];
		}
		qsort(t,n*2,sizeof(int),comp);
		for(i=0;i<n*2;i++){
			p=0;
			for(j=0;j<n;j++){
				if(t[i]>=s[j] && t[i]<e[j])p+=w[j];
			}
			//printf("%3d:%d\n",t[i],p);
			if(p>150)break;
		}
		printf("%s\n",(i==n*2)?"OK":"NG");
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	comp
	.type	comp, @function
comp:
.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	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"OK"
.LC3:
	.string	"NG"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$2144, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-2144(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2144(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	$0, -2140(%rbp)
	jmp	.L6
.L7:
	leaq	-1264(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-1696(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	leaq	-2128(%rbp), %rsi
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rsi, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2140(%rbp), %eax
	leal	(%rax,%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	movl	-2140(%rbp), %eax
	addl	%eax, %eax
	leal	1(%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	addl	$1, -2140(%rbp)
.L6:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L7
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	movslq	%eax, %rsi
	leaq	-832(%rbp), %rax
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -2140(%rbp)
	jmp	.L8
.L14:
	movl	$0, -2132(%rbp)
	movl	$0, -2136(%rbp)
	jmp	.L9
.L11:
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	-2136(%rbp), %eax
	cltq
	movl	-2128(%rbp,%rax,4), %eax
	addl	%eax, -2132(%rbp)
.L10:
	addl	$1, -2136(%rbp)
.L9:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2136(%rbp)
	jl	.L11
	cmpl	$150, -2132(%rbp)
	jg	.L22
	addl	$1, -2140(%rbp)
.L8:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L14
	jmp	.L13
.L22:
	nop
.L13:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jne	.L15
	leaq	.LC2(%rip), %rax
	jmp	.L16
.L15:
	leaq	.LC3(%rip), %rax
.L16:
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L17
.L21:
	nop
	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
.LFE7:
	.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	comp
	.type	comp, @function
comp:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	comp, .-comp
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"OK"
.LC1:
	.string	"NG"
.LC2:
	.string	"%d"
.LC3:
	.string	"%d%d%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC3(%rip), %rbx
	subq	$2168, %rsp
	.cfi_def_cfa_offset 2224
	movq	%fs:40, %rax
	movq	%rax, 2152(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L4
	leaq	1328(%rsp), %r13
	jle	.L5
	leaq	896(%rsp), %r14
	leaq	32(%rsp), %rax
	xorl	%ebp, %ebp
	xorl	%r15d, %r15d
	leaq	464(%rsp), %r12
	movq	%rax, (%rsp)
	movq	%r14, %rax
	leaq	1328(%rsp), %r13
	movq	%r12, %r14
	movq	%rax, %r12
	.p2align 4,,10
	.p2align 3
.L6:
	movq	(%rsp), %rax
	leaq	(%r12,%rbp), %rcx
	leaq	(%r14,%rbp), %rdx
	movq	%rbx, %rdi
	addl	$1, %r15d
	leaq	(%rax,%rbp), %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movd	(%r14,%rbp), %xmm0
	movd	(%r12,%rbp), %xmm5
	movl	28(%rsp), %eax
	punpckldq	%xmm5, %xmm0
	movq	%xmm0, 0(%r13,%rbp,2)
	addq	$4, %rbp
	cmpl	%r15d, %eax
	jg	.L6
.L5:
	addl	%eax, %eax
	movq	%r13, %rdi
	movl	$4, %edx
	movslq	%eax, %rsi
	leaq	comp(%rip), %rcx
	call	qsort@PLT
	movl	28(%rsp), %edi
	leal	(%rdi,%rdi), %r11d
	testl	%r11d, %r11d
	jle	.L21
	movl	%edi, %eax
	movl	%edi, %r8d
	leal	1(%r11), %r9d
	movl	$1, %ecx
	shrl	$2, %eax
	leal	-1(%rdi), %r10d
	pxor	%xmm4, %xmm4
	andl	$-4, %r8d
	leal	-1(%rax), %edx
	addq	$1, %rdx
	salq	$4, %rdx
	.p2align 4,,10
	.p2align 3
.L8:
	testl	%edi, %edi
	jle	.L18
	movl	-4(%r13,%rcx,4), %ebp
	cmpl	$2, %r10d
	jbe	.L22
	movd	%ebp, %xmm6
	pxor	%xmm2, %xmm2
	leaq	32(%rsp), %rsi
	xorl	%eax, %eax
	pshufd	$0, %xmm6, %xmm3
	leaq	896(%rsp), %r14
	leaq	464(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L10:
	movdqa	(%r12,%rax), %xmm0
	movdqa	(%r14,%rax), %xmm1
	pcmpgtd	%xmm3, %xmm0
	pcmpgtd	%xmm3, %xmm1
	pcmpeqd	%xmm4, %xmm0
	pand	%xmm1, %xmm0
	pand	(%rsi,%rax), %xmm0
	addq	$16, %rax
	paddd	%xmm0, %xmm2
	cmpq	%rdx, %rax
	jne	.L10
	movdqa	%xmm2, %xmm0
	movl	%r8d, %eax
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %esi
	cmpl	%r8d, %edi
	je	.L11
.L9:
	movslq	%eax, %r12
	cmpl	464(%rsp,%r12,4), %ebp
	jl	.L12
	cmpl	896(%rsp,%r12,4), %ebp
	jge	.L12
	addl	32(%rsp,%r12,4), %esi
.L12:
	leal	1(%rax), %r12d
	cmpl	%r12d, %edi
	jle	.L11
	movslq	%r12d, %r12
	cmpl	464(%rsp,%r12,4), %ebp
	jl	.L13
	cmpl	896(%rsp,%r12,4), %ebp
	jge	.L13
	addl	32(%rsp,%r12,4), %esi
.L13:
	addl	$2, %eax
	cmpl	%edi, %eax
	jge	.L11
	cltq
	cmpl	464(%rsp,%rax,4), %ebp
	jl	.L11
	cmpl	896(%rsp,%rax,4), %ebp
	jge	.L11
	addl	32(%rsp,%rax,4), %esi
	.p2align 4,,10
	.p2align 3
.L11:
	cmpl	$150, %esi
	jg	.L23
.L18:
	movl	%ecx, %eax
	addq	$1, %rcx
	cmpq	%r9, %rcx
	jne	.L8
.L7:
	cmpl	%eax, %r11d
	leaq	.LC1(%rip), %rdi
	leaq	.LC0(%rip), %rax
	cmove	%rax, %rdi
.L16:
	call	puts@PLT
	jmp	.L19
.L22:
	xorl	%esi, %esi
	xorl	%eax, %eax
	jmp	.L9
.L23:
	leaq	.LC1(%rip), %rdi
	jmp	.L16
.L4:
	movq	2152(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$2168, %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
.L21:
	.cfi_restore_state
	xorl	%eax, %eax
	jmp	.L7
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.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	comp
	.type	comp, @function
comp:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	comp, .-comp
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"OK"
.LC1:
	.string	"NG"
.LC2:
	.string	"%d"
.LC3:
	.string	"%d%d%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC3(%rip), %rbx
	subq	$2168, %rsp
	.cfi_def_cfa_offset 2224
	movq	%fs:40, %rax
	movq	%rax, 2152(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L4
	leaq	1328(%rsp), %r13
	jle	.L5
	leaq	896(%rsp), %r14
	leaq	32(%rsp), %rax
	xorl	%ebp, %ebp
	xorl	%r15d, %r15d
	leaq	464(%rsp), %r12
	movq	%rax, (%rsp)
	movq	%r14, %rax
	leaq	1328(%rsp), %r13
	movq	%r12, %r14
	movq	%rax, %r12
	.p2align 4,,10
	.p2align 3
.L6:
	movq	(%rsp), %rax
	leaq	(%r12,%rbp), %rcx
	leaq	(%r14,%rbp), %rdx
	movq	%rbx, %rdi
	addl	$1, %r15d
	leaq	(%rax,%rbp), %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movd	(%r14,%rbp), %xmm0
	movd	(%r12,%rbp), %xmm5
	movl	28(%rsp), %eax
	punpckldq	%xmm5, %xmm0
	movq	%xmm0, 0(%r13,%rbp,2)
	addq	$4, %rbp
	cmpl	%r15d, %eax
	jg	.L6
.L5:
	addl	%eax, %eax
	movq	%r13, %rdi
	movl	$4, %edx
	movslq	%eax, %rsi
	leaq	comp(%rip), %rcx
	call	qsort@PLT
	movl	28(%rsp), %edi
	leal	(%rdi,%rdi), %r11d
	testl	%r11d, %r11d
	jle	.L21
	movl	%edi, %eax
	movl	%edi, %r8d
	leal	1(%r11), %r9d
	movl	$1, %ecx
	shrl	$2, %eax
	leal	-1(%rdi), %r10d
	pxor	%xmm4, %xmm4
	andl	$-4, %r8d
	leal	-1(%rax), %edx
	addq	$1, %rdx
	salq	$4, %rdx
	.p2align 4,,10
	.p2align 3
.L8:
	testl	%edi, %edi
	jle	.L18
	movl	-4(%r13,%rcx,4), %ebp
	cmpl	$2, %r10d
	jbe	.L22
	movd	%ebp, %xmm6
	pxor	%xmm2, %xmm2
	leaq	32(%rsp), %rsi
	xorl	%eax, %eax
	pshufd	$0, %xmm6, %xmm3
	leaq	896(%rsp), %r14
	leaq	464(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L10:
	movdqa	(%r12,%rax), %xmm0
	movdqa	(%r14,%rax), %xmm1
	pcmpgtd	%xmm3, %xmm0
	pcmpgtd	%xmm3, %xmm1
	pcmpeqd	%xmm4, %xmm0
	pand	%xmm1, %xmm0
	pand	(%rsi,%rax), %xmm0
	addq	$16, %rax
	paddd	%xmm0, %xmm2
	cmpq	%rdx, %rax
	jne	.L10
	movdqa	%xmm2, %xmm0
	movl	%r8d, %eax
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm2
	movdqa	%xmm2, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm2
	movd	%xmm2, %esi
	cmpl	%r8d, %edi
	je	.L11
.L9:
	movslq	%eax, %r12
	cmpl	464(%rsp,%r12,4), %ebp
	jl	.L12
	cmpl	896(%rsp,%r12,4), %ebp
	jge	.L12
	addl	32(%rsp,%r12,4), %esi
.L12:
	leal	1(%rax), %r12d
	cmpl	%r12d, %edi
	jle	.L11
	movslq	%r12d, %r12
	cmpl	464(%rsp,%r12,4), %ebp
	jl	.L13
	cmpl	896(%rsp,%r12,4), %ebp
	jge	.L13
	addl	32(%rsp,%r12,4), %esi
.L13:
	addl	$2, %eax
	cmpl	%edi, %eax
	jge	.L11
	cltq
	cmpl	464(%rsp,%rax,4), %ebp
	jl	.L11
	cmpl	896(%rsp,%rax,4), %ebp
	jge	.L11
	addl	32(%rsp,%rax,4), %esi
	.p2align 4,,10
	.p2align 3
.L11:
	cmpl	$150, %esi
	jg	.L23
.L18:
	movl	%ecx, %eax
	addq	$1, %rcx
	cmpq	%r9, %rcx
	jne	.L8
.L7:
	cmpl	%eax, %r11d
	leaq	.LC1(%rip), %rdi
	leaq	.LC0(%rip), %rax
	cmove	%rax, %rdi
.L16:
	call	puts@PLT
	jmp	.L19
.L22:
	xorl	%esi, %esi
	xorl	%eax, %eax
	jmp	.L9
.L23:
	leaq	.LC1(%rip), %rdi
	jmp	.L16
.L4:
	movq	2152(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$2168, %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
.L21:
	.cfi_restore_state
	xorl	%eax, %eax
	jmp	.L7
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.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>
int comp(const void *p,const void *q){
	return *(int *)p - *(int *)q;
}
int main(){
	int i,j,n,m,t[205],w[105],s[105],e[105],p;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&w[i],&s[i],&e[i]);
			t[i*2]=s[i];t[i*2+1]=e[i];
		}
		qsort(t,n*2,sizeof(int),comp);
		for(i=0;i<n*2;i++){
			p=0;
			for(j=0;j<n;j++){
				if(t[i]>=s[j] && t[i]<e[j])p+=w[j];
			}
			//printf("%3d:%d\n",t[i],p);
			if(p>150)break;
		}
		printf("%s\n",(i==n*2)?"OK":"NG");
	}
	return 0;
}
3
80 0 30
50 5 25
90 27 50
3
80 0 30
70 5 25
71 30 84
0
 3
80 0 15
64 5 25
149 27 50
3
80 0 10
70 10 25
22 30 84
0
 3
80 0 30
50 5 25
90 27 50
3
80 0 30
70 5 25
71 23 50
0
 3
1 0 30
50 5 25
90 28 50
3
80 0 40
70 5 25
71 30 84
0
 3
80 0 15
64 3 49
149 27 50
0
80 1 10
70 10 25
22 30 84
0
 3
80 0 8
50 5 29
90 51 50
0
80 0 10
70 5 25
71 3 84
0
 3
80 0 30
50 5 25
90 27 50
3
80 0 10
70 5 25
71 30 84
0
 3
80 0 30
50 5 25
149 27 50
3
80 0 10
70 5 25
71 30 84
0
 3
80 0 30
50 5 25
149 27 50
3
80 0 10
70 5 25
22 30 84
0
 3
80 0 30
50 5 25
149 27 50
3
80 0 10
70 10 25
22 30 84
0

NG
OK
 OK
OK
 NG
NG
 OK
NG
 NG
 OK
 NG
OK
 NG
OK
 NG
OK
 NG
OK

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>
int comp(const void *p,const void *q){
	return *(int *)p - *(int *)q;
}
int main(){
	int i,j,n,m,t[205],w[105],s[105],e[105],p;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&w[i],&s[i],&e[i]);
			t[i*2]=s[i];t[i*2+1]=e[i];
		}
		qsort(t,n*2,sizeof(int),comp);
		for(i=0;i<n*2;i++){
			p=0;
			for(j=0;j<n;j++){
				if(t[i]>=s[j] && t[i]<e[j])p+=w[j];
			}
			//printf("%3d:%d\n",t[i],p);
			if(p>150)break;
		}
		printf("%s\n",(i==n*2)?"OK":"NG");
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	comp
	.type	comp, @function
comp:
.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	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"OK"
.LC3:
	.string	"NG"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$2144, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-2144(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2144(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	$0, -2140(%rbp)
	jmp	.L6
.L7:
	leaq	-1264(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-1696(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	leaq	-2128(%rbp), %rsi
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rsi, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2140(%rbp), %eax
	leal	(%rax,%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	movl	-2140(%rbp), %eax
	addl	%eax, %eax
	leal	1(%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	addl	$1, -2140(%rbp)
.L6:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L7
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	movslq	%eax, %rsi
	leaq	-832(%rbp), %rax
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -2140(%rbp)
	jmp	.L8
.L14:
	movl	$0, -2132(%rbp)
	movl	$0, -2136(%rbp)
	jmp	.L9
.L11:
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	-2136(%rbp), %eax
	cltq
	movl	-2128(%rbp,%rax,4), %eax
	addl	%eax, -2132(%rbp)
.L10:
	addl	$1, -2136(%rbp)
.L9:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2136(%rbp)
	jl	.L11
	cmpl	$150, -2132(%rbp)
	jg	.L22
	addl	$1, -2140(%rbp)
.L8:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L14
	jmp	.L13
.L22:
	nop
.L13:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jne	.L15
	leaq	.LC2(%rip), %rax
	jmp	.L16
.L15:
	leaq	.LC3(%rip), %rax
.L16:
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L17
.L21:
	nop
	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
.LFE7:
	.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	comp
	.type	comp, @function
comp:
.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	comp, .-comp
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"OK"
.LC3:
	.string	"NG"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$2144, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-2144(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2144(%rbp), %eax
	testl	%eax, %eax
	je	.L21
	movl	$0, -2140(%rbp)
	jmp	.L6
.L7:
	leaq	-1264(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	(%rdx,%rax), %rcx
	leaq	-1696(%rbp), %rdx
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	leaq	-2128(%rbp), %rsi
	movl	-2140(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rsi, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2140(%rbp), %eax
	leal	(%rax,%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	movl	-2140(%rbp), %eax
	addl	%eax, %eax
	leal	1(%rax), %ecx
	movl	-2140(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -832(%rbp,%rax,4)
	addl	$1, -2140(%rbp)
.L6:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L7
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	movslq	%eax, %rsi
	leaq	-832(%rbp), %rax
	leaq	comp(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	$0, -2140(%rbp)
	jmp	.L8
.L14:
	movl	$0, -2132(%rbp)
	movl	$0, -2136(%rbp)
	jmp	.L9
.L11:
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1696(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-2140(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %edx
	movl	-2136(%rbp), %eax
	cltq
	movl	-1264(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L10
	movl	-2136(%rbp), %eax
	cltq
	movl	-2128(%rbp,%rax,4), %eax
	addl	%eax, -2132(%rbp)
.L10:
	addl	$1, -2136(%rbp)
.L9:
	movl	-2144(%rbp), %eax
	cmpl	%eax, -2136(%rbp)
	jl	.L11
	cmpl	$150, -2132(%rbp)
	jg	.L22
	addl	$1, -2140(%rbp)
.L8:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jl	.L14
	jmp	.L13
.L22:
	nop
.L13:
	movl	-2144(%rbp), %eax
	addl	%eax, %eax
	cmpl	%eax, -2140(%rbp)
	jne	.L15
	leaq	.LC2(%rip), %rax
	jmp	.L16
.L15:
	leaq	.LC3(%rip), %rax
.L16:
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L17
.L21:
	nop
	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
.LFE7:
	.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:
