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>
#define W 5
#define H_MAX 10
#define THRESHOLD 3
#define EMPTY -1

int field[W + 1][H_MAX];
int h;

int main(void)
{
    int x, y, i, stable, score;

    for(y = 0; y < H_MAX; y++)
        field[W][y] = EMPTY;

    while(scanf("%d", &h), h)
    {
        for(y = 0; y < h; y++)
            for(x = 0; x < W; x++)
                scanf("%d", &field[x][y]);

        stable = score = 0;

        while(!stable)
        {
            stable = 1;
            for(y = 0; y < h; y++)
                for(x = i = 0; x < W; x++)
                {
                    i++;
                    if(field[x][y] != field[x + 1][y])
                    {
                        if(i >= THRESHOLD && field[x][y] != EMPTY)
                        {
                            stable = 0;
                            score += field[x][y] * i;
                            while(i--) field[x - i][y] = EMPTY;
                        }
                        i = 0;
                    }
                }

            for(x = 0; x < W; x++)
                for(y = h - 1; y > 0; y--)
                    if(field[x][y] == EMPTY)
                    {
                        for(i = y; field[x][i] == EMPTY && i > 0; i--);
                        field[x][y] = field[x][i];
                        field[x][i] = EMPTY;
                    }
        }

        printf("%d\n", score);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	field
	.bss
	.align 32
	.type	field, @object
	.size	field, 240
field:
	.zero	240
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -16(%rbp)
	jmp	.L2
.L3:
	movl	-16(%rbp), %eax
	cltq
	addq	$50, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -16(%rbp)
.L2:
	cmpl	$9, -16(%rbp)
	jle	.L3
	jmp	.L4
.L27:
	movl	$0, -16(%rbp)
	jmp	.L5
.L8:
	movl	$0, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L6:
	cmpl	$4, -20(%rbp)
	jle	.L7
	addl	$1, -16(%rbp)
.L5:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L8
	movl	$0, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L9
.L26:
	movl	$1, -8(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L10
.L17:
	movl	$0, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L11
.L16:
	addl	$1, -12(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-20(%rbp), %eax
	leal	1(%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movslq	%edx, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	je	.L12
	cmpl	$2, -12(%rbp)
	jle	.L13
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L13
	movl	$0, -8(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	addl	%eax, -4(%rbp)
	jmp	.L14
.L15:
	movl	-20(%rbp), %eax
	subl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L14:
	movl	-12(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -12(%rbp)
	testl	%eax, %eax
	jne	.L15
.L13:
	movl	$0, -12(%rbp)
.L12:
	addl	$1, -20(%rbp)
.L11:
	cmpl	$4, -20(%rbp)
	jle	.L16
	addl	$1, -16(%rbp)
.L10:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L17
	movl	$0, -20(%rbp)
	jmp	.L18
.L25:
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L19
.L24:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L20
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L21
.L23:
	subl	$1, -12(%rbp)
.L21:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L22
	cmpl	$0, -12(%rbp)
	jg	.L23
.L22:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movl	-20(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	field(%rip), %rax
	movl	%edx, (%rcx,%rax)
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L20:
	subl	$1, -16(%rbp)
.L19:
	cmpl	$0, -16(%rbp)
	jg	.L24
	addl	$1, -20(%rbp)
.L18:
	cmpl	$4, -20(%rbp)
	jle	.L25
.L9:
	cmpl	$0, -8(%rbp)
	je	.L26
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %eax
	testl	%eax, %eax
	jne	.L27
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pcmpeqd	%xmm0, %xmm0
	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
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movups	%xmm0, 200+field(%rip)
	movq	$-1, 232+field(%rip)
	movups	%xmm0, 216+field(%rip)
.L2:
	leaq	h(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %eax
	movl	%eax, 20(%rsp)
	testl	%eax, %eax
	je	.L61
	leaq	200+field(%rip), %rbp
	movl	$0, %r12d
	jle	.L29
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	-200(%rbp), %rbx
.L3:
	movq	%rbx, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addq	$40, %rbx
	call	__isoc99_scanf@PLT
	cmpq	%rbp, %rbx
	jne	.L3
	movl	h(%rip), %eax
	addq	$1, %r12
	addq	$4, %rbp
	cmpl	%r12d, %eax
	jg	.L4
	movl	%eax, 20(%rsp)
.L29:
	subl	$1, %eax
	movl	$0, 64(%rsp)
	movl	$1, %r8d
	xorl	%r14d, %r14d
	movl	%eax, 72(%rsp)
	leaq	field(%rip), %r15
	cmpl	20(%rsp), %r14d
	jge	.L126
	.p2align 4,,10
	.p2align 3
.L17:
	movl	$3, %r9d
	movl	$4, %edi
.L26:
	movslq	%r14d, %rax
	xorl	%edx, %edx
	leaq	20(%rax), %r10
	movl	40(%r15,%rax,4), %esi
	cmpl	%esi, (%r15,%rax,4)
	movl	(%r15,%r10,4), %ecx
	sete	%dl
	xorl	%ebx, %ebx
	addl	$1, %edx
	cmpl	%ecx, %esi
	cmovne	%ebx, %edx
	leal	1(%rdx), %esi
	cmpl	120(%r15,%rax,4), %ecx
	je	.L7
	cmpl	$-1, %ecx
	je	.L35
	cmpl	$2, %esi
	jg	.L127
.L35:
	xorl	%esi, %esi
.L7:
	leaq	30(%rax), %r10
	leal	1(%rsi), %edx
	movl	(%r15,%r10,4), %ecx
	cmpl	160(%r15,%rax,4), %ecx
	je	.L8
	cmpl	$-1, %ecx
	je	.L119
	cmpl	$2, %edx
	jg	.L128
.L119:
	xorl	%edx, %edx
.L8:
	leaq	40(%rax), %rsi
	leal	1(%rdx), %r10d
	movl	(%r15,%rsi,4), %ecx
	cmpl	200(%r15,%rax,4), %ecx
	je	.L9
	cmpl	$2, %r10d
	jle	.L9
	cmpl	$-1, %ecx
	jne	.L129
.L9:
	addl	$1, %r14d
	cmpl	20(%rsp), %r14d
	jl	.L17
.L126:
	movl	72(%rsp), %ecx
	movl	%r8d, %r14d
	testl	%ecx, %ecx
	jle	.L18
.L15:
	movl	20(%rsp), %eax
	movl	$0, 16(%rsp)
	leaq	field(%rip), %r13
	movl	%r14d, 76(%rsp)
	leal	-2(%rax), %edi
	movl	%edi, 40(%rsp)
	movslq	72(%rsp), %rdi
	movq	%rdi, 32(%rsp)
	leal	-3(%rax), %edi
	movl	%edi, 28(%rsp)
	leal	-4(%rax), %edi
	movl	%edi, 24(%rsp)
	leal	-5(%rax), %edi
	movl	%edi, 60(%rsp)
	leal	-6(%rax), %edi
	movl	%edi, 56(%rsp)
	leal	-7(%rax), %edi
	movl	%edi, 52(%rsp)
	leal	-8(%rax), %edi
	subl	$9, %eax
	movl	%edi, 48(%rsp)
	movl	%eax, 44(%rsp)
.L23:
	movslq	16(%rsp), %r12
	movslq	40(%rsp), %rcx
	movq	32(%rsp), %rax
	movl	28(%rsp), %esi
	leaq	(%r12,%r12,4), %rdx
	movq	%r12, 8(%rsp)
	movl	24(%rsp), %edi
	movl	60(%rsp), %r8d
	movl	56(%rsp), %r9d
	leaq	(%rdx,%rdx), %r14
	movl	52(%rsp), %r10d
	movl	48(%rsp), %r11d
	movl	44(%rsp), %ebx
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L19:
	subq	$1, %rax
	subq	$1, %rcx
	subl	$1, %esi
	subl	$1, %edi
	subl	$1, %r8d
	subl	$1, %r9d
	subl	$1, %r10d
	subl	$1, %r11d
	subl	$1, %ebx
	testl	%eax, %eax
	jle	.L130
.L22:
	movl	0(%r13,%rax,4), %edx
	cmpl	$-1, %edx
	jne	.L19
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L121
	movl	0(%r13,%rcx,4), %edx
	movl	%ecx, %r12d
	cmpl	$-1, %edx
	jne	.L121
	testl	%ecx, %ecx
	je	.L121
	movslq	%esi, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%esi, %esi
	je	.L120
	movslq	%edi, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%edi, %edi
	je	.L120
	movslq	%r8d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r8d, %r8d
	je	.L120
	movslq	%r9d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r9d, %r9d
	je	.L120
	movslq	%r10d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r10d, %r10d
	je	.L120
	movslq	%r11d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r11d, %r11d
	je	.L120
	movslq	%ebx, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%ebx, %ebx
	je	.L120
	leal	-9(%rax), %r12d
	movl	%eax, 68(%rsp)
	movslq	%r12d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r12d, %r12d
	je	.L20
	subl	$1, %r12d
	movslq	%r12d, %rbp
	xorl	%r12d, %r12d
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	cmove	%r12, %rbp
.L20:
	movl	%edx, 0(%r13,%rax,4)
	movq	8(%rsp), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	0(%rbp,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L127:
	leal	(%rcx,%rcx,2), %ecx
	addl	%ecx, 64(%rsp)
	leal	-1(%rdx), %r8d
	movl	$2, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L34
	movl	$2, %edx
	subl	%r8d, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	testl	%r8d, %r8d
	je	.L35
	movl	$-1, (%r15,%r10,4)
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L128:
	imull	%edx, %ecx
	movl	%r9d, %edx
	leal	-1(%rsi), %r8d
	addl	%ecx, 64(%rsp)
	subl	%esi, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	testl	%esi, %esi
	je	.L37
	movl	%r9d, %edx
	subl	%r8d, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	leal	-2(%rsi), %edx
	testl	%r8d, %r8d
	je	.L119
	movl	%r9d, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L39
	movl	$-1, (%r15,%r10,4)
	xorl	%r8d, %r8d
	xorl	%edx, %edx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L129:
	imull	%r10d, %ecx
	addl	%ecx, 64(%rsp)
	leal	-1(%rdx), %r8d
	movl	%edi, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L10
	movl	%edi, %ecx
	leal	-2(%rdx), %r10d
	subl	%r8d, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%r8d, %r8d
	je	.L10
	movl	%edi, %ecx
	subl	$3, %edx
	subl	%r10d, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%r10d, %r10d
	je	.L12
	movl	%edi, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rax
	movl	$-1, (%r15,%rax,4)
	testl	%edx, %edx
	je	.L12
	movl	$-1, (%r15,%rsi,4)
	addl	$1, %r14d
	cmpl	%r14d, 20(%rsp)
	jle	.L122
.L14:
	xorl	%r8d, %r8d
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L130:
	addl	$1, 16(%rsp)
	movl	16(%rsp), %eax
	addq	$40, %r13
	cmpl	$5, %eax
	jne	.L23
	movl	76(%rsp), %r14d
.L18:
	testl	%r14d, %r14d
	jne	.L24
	movl	20(%rsp), %edx
	movl	$1, %r8d
	testl	%edx, %edx
	jg	.L17
	movl	72(%rsp), %eax
	movl	$1, %r14d
	testl	%eax, %eax
	jg	.L15
.L24:
	movl	64(%rsp), %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L120:
	xorl	%ebp, %ebp
	jmp	.L20
	.p2align 4,,10
	.p2align 3
.L121:
	movslq	%r12d, %rbp
	jmp	.L20
.L10:
	addl	$1, %r14d
	cmpl	%r14d, 20(%rsp)
	jg	.L14
.L122:
	movl	72(%rsp), %esi
	testl	%esi, %esi
	jle	.L131
.L44:
	xorl	%r14d, %r14d
	jmp	.L15
.L12:
	addl	$1, %r14d
	cmpl	20(%rsp), %r14d
	jl	.L14
	movl	72(%rsp), %esi
	testl	%esi, %esi
	jg	.L44
.L131:
	xorl	%r14d, %r14d
	cmpl	$0, 20(%rsp)
	movl	$1, %r8d
	jg	.L26
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L37:
	xorl	%r8d, %r8d
	jmp	.L119
.L34:
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	jmp	.L7
.L39:
	xorl	%r8d, %r8d
	jmp	.L8
.L61:
	addq	$88, %rsp
	.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
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	h
	.bss
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	field
	.align 32
	.type	field, @object
	.size	field, 240
field:
	.zero	240
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pcmpeqd	%xmm0, %xmm0
	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
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movups	%xmm0, 200+field(%rip)
	movq	$-1, 232+field(%rip)
	movups	%xmm0, 216+field(%rip)
.L2:
	leaq	h(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %eax
	movl	%eax, 20(%rsp)
	testl	%eax, %eax
	je	.L61
	leaq	200+field(%rip), %rbp
	movl	$0, %r12d
	jle	.L29
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	-200(%rbp), %rbx
.L3:
	movq	%rbx, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addq	$40, %rbx
	call	__isoc99_scanf@PLT
	cmpq	%rbp, %rbx
	jne	.L3
	movl	h(%rip), %eax
	addq	$1, %r12
	addq	$4, %rbp
	cmpl	%r12d, %eax
	jg	.L4
	movl	%eax, 20(%rsp)
.L29:
	subl	$1, %eax
	movl	$0, 64(%rsp)
	movl	$1, %r8d
	xorl	%r14d, %r14d
	movl	%eax, 72(%rsp)
	leaq	field(%rip), %r15
	cmpl	20(%rsp), %r14d
	jge	.L126
	.p2align 4,,10
	.p2align 3
.L17:
	movl	$3, %r9d
	movl	$4, %edi
.L26:
	movslq	%r14d, %rax
	xorl	%edx, %edx
	leaq	20(%rax), %r10
	movl	40(%r15,%rax,4), %esi
	cmpl	%esi, (%r15,%rax,4)
	movl	(%r15,%r10,4), %ecx
	sete	%dl
	xorl	%ebx, %ebx
	addl	$1, %edx
	cmpl	%ecx, %esi
	cmovne	%ebx, %edx
	leal	1(%rdx), %esi
	cmpl	120(%r15,%rax,4), %ecx
	je	.L7
	cmpl	$-1, %ecx
	je	.L35
	cmpl	$2, %esi
	jg	.L127
.L35:
	xorl	%esi, %esi
.L7:
	leaq	30(%rax), %r10
	leal	1(%rsi), %edx
	movl	(%r15,%r10,4), %ecx
	cmpl	160(%r15,%rax,4), %ecx
	je	.L8
	cmpl	$-1, %ecx
	je	.L119
	cmpl	$2, %edx
	jg	.L128
.L119:
	xorl	%edx, %edx
.L8:
	leaq	40(%rax), %rsi
	leal	1(%rdx), %r10d
	movl	(%r15,%rsi,4), %ecx
	cmpl	200(%r15,%rax,4), %ecx
	je	.L9
	cmpl	$2, %r10d
	jle	.L9
	cmpl	$-1, %ecx
	jne	.L129
.L9:
	addl	$1, %r14d
	cmpl	20(%rsp), %r14d
	jl	.L17
.L126:
	movl	72(%rsp), %ecx
	movl	%r8d, %r14d
	testl	%ecx, %ecx
	jle	.L18
.L15:
	movl	20(%rsp), %eax
	movl	$0, 16(%rsp)
	leaq	field(%rip), %r13
	movl	%r14d, 76(%rsp)
	leal	-2(%rax), %edi
	movl	%edi, 40(%rsp)
	movslq	72(%rsp), %rdi
	movq	%rdi, 32(%rsp)
	leal	-3(%rax), %edi
	movl	%edi, 28(%rsp)
	leal	-4(%rax), %edi
	movl	%edi, 24(%rsp)
	leal	-5(%rax), %edi
	movl	%edi, 60(%rsp)
	leal	-6(%rax), %edi
	movl	%edi, 56(%rsp)
	leal	-7(%rax), %edi
	movl	%edi, 52(%rsp)
	leal	-8(%rax), %edi
	subl	$9, %eax
	movl	%edi, 48(%rsp)
	movl	%eax, 44(%rsp)
.L23:
	movslq	16(%rsp), %r12
	movslq	40(%rsp), %rcx
	movq	32(%rsp), %rax
	movl	28(%rsp), %esi
	leaq	(%r12,%r12,4), %rdx
	movq	%r12, 8(%rsp)
	movl	24(%rsp), %edi
	movl	60(%rsp), %r8d
	movl	56(%rsp), %r9d
	leaq	(%rdx,%rdx), %r14
	movl	52(%rsp), %r10d
	movl	48(%rsp), %r11d
	movl	44(%rsp), %ebx
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L19:
	subq	$1, %rax
	subq	$1, %rcx
	subl	$1, %esi
	subl	$1, %edi
	subl	$1, %r8d
	subl	$1, %r9d
	subl	$1, %r10d
	subl	$1, %r11d
	subl	$1, %ebx
	testl	%eax, %eax
	jle	.L130
.L22:
	movl	0(%r13,%rax,4), %edx
	cmpl	$-1, %edx
	jne	.L19
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L121
	movl	0(%r13,%rcx,4), %edx
	movl	%ecx, %r12d
	cmpl	$-1, %edx
	jne	.L121
	testl	%ecx, %ecx
	je	.L121
	movslq	%esi, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%esi, %esi
	je	.L120
	movslq	%edi, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%edi, %edi
	je	.L120
	movslq	%r8d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r8d, %r8d
	je	.L120
	movslq	%r9d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r9d, %r9d
	je	.L120
	movslq	%r10d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r10d, %r10d
	je	.L120
	movslq	%r11d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r11d, %r11d
	je	.L120
	movslq	%ebx, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%ebx, %ebx
	je	.L120
	leal	-9(%rax), %r12d
	movl	%eax, 68(%rsp)
	movslq	%r12d, %rbp
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	jne	.L20
	testl	%r12d, %r12d
	je	.L20
	subl	$1, %r12d
	movslq	%r12d, %rbp
	xorl	%r12d, %r12d
	leaq	(%r14,%rbp), %rdx
	movl	(%r15,%rdx,4), %edx
	cmpl	$-1, %edx
	cmove	%r12, %rbp
.L20:
	movl	%edx, 0(%r13,%rax,4)
	movq	8(%rsp), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	0(%rbp,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	jmp	.L19
	.p2align 4,,10
	.p2align 3
.L127:
	leal	(%rcx,%rcx,2), %ecx
	addl	%ecx, 64(%rsp)
	leal	-1(%rdx), %r8d
	movl	$2, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L34
	movl	$2, %edx
	subl	%r8d, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	testl	%r8d, %r8d
	je	.L35
	movl	$-1, (%r15,%r10,4)
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L128:
	imull	%edx, %ecx
	movl	%r9d, %edx
	leal	-1(%rsi), %r8d
	addl	%ecx, 64(%rsp)
	subl	%esi, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	testl	%esi, %esi
	je	.L37
	movl	%r9d, %edx
	subl	%r8d, %edx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	$-1, (%r15,%rdx,4)
	leal	-2(%rsi), %edx
	testl	%r8d, %r8d
	je	.L119
	movl	%r9d, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L39
	movl	$-1, (%r15,%r10,4)
	xorl	%r8d, %r8d
	xorl	%edx, %edx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L129:
	imull	%r10d, %ecx
	addl	%ecx, 64(%rsp)
	leal	-1(%rdx), %r8d
	movl	%edi, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%edx, %edx
	je	.L10
	movl	%edi, %ecx
	leal	-2(%rdx), %r10d
	subl	%r8d, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%r8d, %r8d
	je	.L10
	movl	%edi, %ecx
	subl	$3, %edx
	subl	%r10d, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rcx
	movl	$-1, (%r15,%rcx,4)
	testl	%r10d, %r10d
	je	.L12
	movl	%edi, %ecx
	subl	%edx, %ecx
	movslq	%ecx, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,2), %rax
	movl	$-1, (%r15,%rax,4)
	testl	%edx, %edx
	je	.L12
	movl	$-1, (%r15,%rsi,4)
	addl	$1, %r14d
	cmpl	%r14d, 20(%rsp)
	jle	.L122
.L14:
	xorl	%r8d, %r8d
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L130:
	addl	$1, 16(%rsp)
	movl	16(%rsp), %eax
	addq	$40, %r13
	cmpl	$5, %eax
	jne	.L23
	movl	76(%rsp), %r14d
.L18:
	testl	%r14d, %r14d
	jne	.L24
	movl	20(%rsp), %edx
	movl	$1, %r8d
	testl	%edx, %edx
	jg	.L17
	movl	72(%rsp), %eax
	movl	$1, %r14d
	testl	%eax, %eax
	jg	.L15
.L24:
	movl	64(%rsp), %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L120:
	xorl	%ebp, %ebp
	jmp	.L20
	.p2align 4,,10
	.p2align 3
.L121:
	movslq	%r12d, %rbp
	jmp	.L20
.L10:
	addl	$1, %r14d
	cmpl	%r14d, 20(%rsp)
	jg	.L14
.L122:
	movl	72(%rsp), %esi
	testl	%esi, %esi
	jle	.L131
.L44:
	xorl	%r14d, %r14d
	jmp	.L15
.L12:
	addl	$1, %r14d
	cmpl	20(%rsp), %r14d
	jl	.L14
	movl	72(%rsp), %esi
	testl	%esi, %esi
	jg	.L44
.L131:
	xorl	%r14d, %r14d
	cmpl	$0, 20(%rsp)
	movl	$1, %r8d
	jg	.L26
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L37:
	xorl	%r8d, %r8d
	jmp	.L119
.L34:
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	jmp	.L7
.L39:
	xorl	%r8d, %r8d
	jmp	.L8
.L61:
	addq	$88, %rsp
	.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
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	h
	.bss
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	field
	.align 32
	.type	field, @object
	.size	field, 240
field:
	.zero	240
	.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>
#define W 5
#define H_MAX 10
#define THRESHOLD 3
#define EMPTY -1

int field[W + 1][H_MAX];
int h;

int main(void)
{
    int x, y, i, stable, score;

    for(y = 0; y < H_MAX; y++)
        field[W][y] = EMPTY;

    while(scanf("%d", &h), h)
    {
        for(y = 0; y < h; y++)
            for(x = 0; x < W; x++)
                scanf("%d", &field[x][y]);

        stable = score = 0;

        while(!stable)
        {
            stable = 1;
            for(y = 0; y < h; y++)
                for(x = i = 0; x < W; x++)
                {
                    i++;
                    if(field[x][y] != field[x + 1][y])
                    {
                        if(i >= THRESHOLD && field[x][y] != EMPTY)
                        {
                            stable = 0;
                            score += field[x][y] * i;
                            while(i--) field[x - i][y] = EMPTY;
                        }
                        i = 0;
                    }
                }

            for(x = 0; x < W; x++)
                for(y = h - 1; y > 0; y--)
                    if(field[x][y] == EMPTY)
                    {
                        for(i = y; field[x][i] == EMPTY && i > 0; i--);
                        field[x][y] = field[x][i];
                        field[x][i] = EMPTY;
                    }
        }

        printf("%d\n", score);
    }

    return 0;
}
1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 6 9
3 3 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 6 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 8 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 6 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 6 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 8 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 6 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 9 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 8 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 6 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 9 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 4 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 10 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 9 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 4 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 10 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
8 7 7 6 1
4 9 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 12
3
2 2 4 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 5 9
5 5 6 9 9
4 6 3 6 9
3 3 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 2 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 8 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 5 6 9 9
4 6 3 6 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
3 7 7 6 1
4 6 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 8 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 2 9
5 6 6 9 9
4 6 3 10 9
3 2 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
8 7 7 6 1
4 9 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 12
3
2 2 4 7 4
6 5 7 7 7
8 8 9 9 9
0
 1
6 9 9 9 9
5
5 9 5 5 9
5 5 6 9 9
4 6 3 6 9
3 3 2 9 9
2 2 1 1 1
10
3 5 6 5 6
2 2 2 8 3
6 2 5 9 2
7 7 7 6 1
4 2 6 4 9
8 9 1 1 8
5 6 1 8 1
6 8 2 1 2
9 6 3 3 5
5 3 8 8 8
5
1 2 3 4 5
6 7 8 9 1
2 3 4 5 6
7 8 9 1 2
3 4 5 6 7
3
2 2 10 7 4
6 5 7 7 7
8 8 9 9 9
0

36
33
99
0
72
 36
42
99
0
72
 36
42
81
0
72
 36
42
81
0
48
 36
24
81
0
48
 36
24
60
0
48
 36
38
81
0
72
 36
42
60
0
72
 36
9
60
0
48
 36
38
81
0
48

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>
#define W 5
#define H_MAX 10
#define THRESHOLD 3
#define EMPTY -1

int field[W + 1][H_MAX];
int h;

int main(void)
{
    int x, y, i, stable, score;

    for(y = 0; y < H_MAX; y++)
        field[W][y] = EMPTY;

    while(scanf("%d", &h), h)
    {
        for(y = 0; y < h; y++)
            for(x = 0; x < W; x++)
                scanf("%d", &field[x][y]);

        stable = score = 0;

        while(!stable)
        {
            stable = 1;
            for(y = 0; y < h; y++)
                for(x = i = 0; x < W; x++)
                {
                    i++;
                    if(field[x][y] != field[x + 1][y])
                    {
                        if(i >= THRESHOLD && field[x][y] != EMPTY)
                        {
                            stable = 0;
                            score += field[x][y] * i;
                            while(i--) field[x - i][y] = EMPTY;
                        }
                        i = 0;
                    }
                }

            for(x = 0; x < W; x++)
                for(y = h - 1; y > 0; y--)
                    if(field[x][y] == EMPTY)
                    {
                        for(i = y; field[x][i] == EMPTY && i > 0; i--);
                        field[x][y] = field[x][i];
                        field[x][i] = EMPTY;
                    }
        }

        printf("%d\n", score);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	field
	.bss
	.align 32
	.type	field, @object
	.size	field, 240
field:
	.zero	240
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -16(%rbp)
	jmp	.L2
.L3:
	movl	-16(%rbp), %eax
	cltq
	addq	$50, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -16(%rbp)
.L2:
	cmpl	$9, -16(%rbp)
	jle	.L3
	jmp	.L4
.L27:
	movl	$0, -16(%rbp)
	jmp	.L5
.L8:
	movl	$0, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L6:
	cmpl	$4, -20(%rbp)
	jle	.L7
	addl	$1, -16(%rbp)
.L5:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L8
	movl	$0, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L9
.L26:
	movl	$1, -8(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L10
.L17:
	movl	$0, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L11
.L16:
	addl	$1, -12(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-20(%rbp), %eax
	leal	1(%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movslq	%edx, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	je	.L12
	cmpl	$2, -12(%rbp)
	jle	.L13
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L13
	movl	$0, -8(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	addl	%eax, -4(%rbp)
	jmp	.L14
.L15:
	movl	-20(%rbp), %eax
	subl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L14:
	movl	-12(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -12(%rbp)
	testl	%eax, %eax
	jne	.L15
.L13:
	movl	$0, -12(%rbp)
.L12:
	addl	$1, -20(%rbp)
.L11:
	cmpl	$4, -20(%rbp)
	jle	.L16
	addl	$1, -16(%rbp)
.L10:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L17
	movl	$0, -20(%rbp)
	jmp	.L18
.L25:
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L19
.L24:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L20
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L21
.L23:
	subl	$1, -12(%rbp)
.L21:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L22
	cmpl	$0, -12(%rbp)
	jg	.L23
.L22:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movl	-20(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	field(%rip), %rax
	movl	%edx, (%rcx,%rax)
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L20:
	subl	$1, -16(%rbp)
.L19:
	cmpl	$0, -16(%rbp)
	jg	.L24
	addl	$1, -20(%rbp)
.L18:
	cmpl	$4, -20(%rbp)
	jle	.L25
.L9:
	cmpl	$0, -8(%rbp)
	je	.L26
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %eax
	testl	%eax, %eax
	jne	.L27
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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	field
	.bss
	.align 32
	.type	field, @object
	.size	field, 240
field:
	.zero	240
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -16(%rbp)
	jmp	.L2
.L3:
	movl	-16(%rbp), %eax
	cltq
	addq	$50, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -16(%rbp)
.L2:
	cmpl	$9, -16(%rbp)
	jle	.L3
	jmp	.L4
.L27:
	movl	$0, -16(%rbp)
	jmp	.L5
.L8:
	movl	$0, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L6:
	cmpl	$4, -20(%rbp)
	jle	.L7
	addl	$1, -16(%rbp)
.L5:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L8
	movl	$0, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L9
.L26:
	movl	$1, -8(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L10
.L17:
	movl	$0, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L11
.L16:
	addl	$1, -12(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-20(%rbp), %eax
	leal	1(%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movslq	%edx, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, %ecx
	je	.L12
	cmpl	$2, -12(%rbp)
	jle	.L13
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L13
	movl	$0, -8(%rbp)
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	imull	-12(%rbp), %eax
	addl	%eax, -4(%rbp)
	jmp	.L14
.L15:
	movl	-20(%rbp), %eax
	subl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L14:
	movl	-12(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -12(%rbp)
	testl	%eax, %eax
	jne	.L15
.L13:
	movl	$0, -12(%rbp)
.L12:
	addl	$1, -20(%rbp)
.L11:
	cmpl	$4, -20(%rbp)
	jle	.L16
	addl	$1, -16(%rbp)
.L10:
	movl	h(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L17
	movl	$0, -20(%rbp)
	jmp	.L18
.L25:
	movl	h(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L19
.L24:
	movl	-16(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L20
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L21
.L23:
	subl	$1, -12(%rbp)
.L21:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L22
	cmpl	$0, -12(%rbp)
	jg	.L23
.L22:
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-16(%rbp), %eax
	movslq	%eax, %rsi
	movl	-20(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	field(%rip), %rax
	movl	%edx, (%rcx,%rax)
	movl	-12(%rbp), %eax
	movslq	%eax, %rcx
	movl	-20(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	field(%rip), %rax
	movl	$-1, (%rdx,%rax)
.L20:
	subl	$1, -16(%rbp)
.L19:
	cmpl	$0, -16(%rbp)
	jg	.L24
	addl	$1, -20(%rbp)
.L18:
	cmpl	$4, -20(%rbp)
	jle	.L25
.L9:
	cmpl	$0, -8(%rbp)
	je	.L26
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %eax
	testl	%eax, %eax
	jne	.L27
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
