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 N 256
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

char  d[ N ][ N ];
int   n;

static
int scan (
  int x,
  int y,
  int sx,
  int sy,
  int res
  )
{
  int c;

  for ( c = 0; x >= 0 && y >= 0
            && x < n && y < n;
      x += sx, y += sy )
  {
    if ( d[ x ][ y ] == '0' )
    {
      res = MAX( res, c );
      c = 0;
      continue ;
    }

    ++c;
  }
  res = MAX( res, c );

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int res = 0;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%s", d[ i ] );
    }

    for ( i = 0; i < n; ++i )
    {
      res = scan ( 0, i, 1, 0, res );
      res = scan ( i, 0, 0, 1, res );
      res = scan ( 0, i, 1, 1, res );
      res = scan ( 0, i, 1, -1, res );
    }
    for ( i = 1; i < n; ++i )
    {
      res = scan ( i, 0, 1, 1, res );
      res = scan ( i, n - 1, 1, -1, res );
    }

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

  return ( 0 );
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 65536
d:
	.zero	65536
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$8, %rax
	addq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L4
.L3:
	addl	$1, -4(%rbp)
.L4:
	movl	-28(%rbp), %eax
	addl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	addl	%eax, -24(%rbp)
.L2:
	cmpl	$0, -20(%rbp)
	js	.L5
	cmpl	$0, -24(%rbp)
	js	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jge	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L6
.L5:
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
.L17:
	movl	$0, -4(%rbp)
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	je	.L20
	movl	$0, -8(%rbp)
	jmp	.L11
.L12:
	movl	-8(%rbp), %eax
	cltq
	salq	$8, %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L11:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L12
	movl	$0, -8(%rbp)
	jmp	.L13
.L14:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$0, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$0, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L13:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L14
	movl	$1, -8(%rbp)
	jmp	.L15
.L16:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	n(%rip), %eax
	leal	-1(%rax), %esi
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L15:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L16
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L20:
	nop
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.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
	leaq	n(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
.L32:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %ecx
	testl	%ecx, %ecx
	je	.L2
	jle	.L33
	leaq	d(%rip), %r13
	xorl	%r14d, %r14d
	movq	%r13, %r15
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movl	n(%rip), %ecx
	addq	$256, %r15
	cmpl	%r14d, %ecx
	jg	.L4
	testl	%ecx, %ecx
	jle	.L51
	leal	-1(%rcx), %r9d
	leaq	1+d(%rip), %rax
	xorl	%r14d, %r14d
	xorl	%r8d, %r8d
	movq	%r9, %rdi
	leaq	(%rax,%r9), %rsi
	addq	$255, %rax
	salq	$8, %rdi
	addq	%rax, %rdi
	.p2align 4,,10
	.p2align 3
.L21:
	movq	%r13, %rax
	xorl	%edx, %edx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L7:
	addq	$256, %rax
	addl	$1, %edx
	cmpq	%rdi, %rax
	je	.L52
.L9:
	cmpb	$48, (%rax)
	jne	.L7
	cmpl	%edx, %r14d
	cmovl	%edx, %r14d
	addq	$256, %rax
	xorl	%edx, %edx
	cmpq	%rdi, %rax
	jne	.L9
.L52:
	cmpl	%edx, %r14d
	movq	%rsi, %rax
	cmovl	%edx, %r14d
	subq	%r9, %rax
	xorl	%edx, %edx
	subq	$1, %rax
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L10:
	addq	$1, %rax
	addl	$1, %edx
	cmpq	%rsi, %rax
	je	.L53
.L12:
	cmpb	$48, (%rax)
	jne	.L10
	cmpl	%edx, %r14d
	cmovl	%edx, %r14d
	addq	$1, %rax
	xorl	%edx, %edx
	cmpq	%rsi, %rax
	jne	.L12
.L53:
	cmpl	%edx, %r14d
	movq	%r13, %r10
	cmovl	%edx, %r14d
	xorl	%r11d, %r11d
	xorl	%eax, %eax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L15:
	addl	$1, %r11d
.L16:
	addl	$1, %eax
	addq	$257, %r10
	leal	(%rax,%r8), %edx
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	cmpl	%edx, %ecx
	jle	.L54
.L13:
	cmpb	$48, (%r10)
	jne	.L15
	cmpl	%r11d, %r14d
	cmovl	%r11d, %r14d
	xorl	%r11d, %r11d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L54:
	cmpl	%r11d, %r14d
	movq	%r13, %rdx
	cmovl	%r11d, %r14d
	xorl	%r10d, %r10d
	xorl	%eax, %eax
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L18:
	addl	$1, %eax
	addl	$1, %r10d
	addq	$255, %rdx
	cmpl	%eax, %r8d
	js	.L34
.L55:
	cmpl	%eax, %ecx
	jle	.L34
.L14:
	cmpb	$48, (%rdx)
	jne	.L18
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %eax
	xorl	%r10d, %r10d
	addq	$255, %rdx
	cmpl	%eax, %r8d
	jns	.L55
	.p2align 4,,10
	.p2align 3
.L34:
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %r8d
	addq	$1, %r13
	addq	$1, %rdi
	addq	$256, %rsi
	cmpl	%r8d, %ecx
	jne	.L21
.L3:
	cmpl	$1, %ecx
	jle	.L6
	leal	-1(%rcx), %r13d
	leal	1(%rcx), %edi
	movl	$1, %r8d
	movslq	%ecx, %r11
	leaq	256+d(%rip), %r9
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%r9, %rdx
	movl	%r8d, %eax
	xorl	%esi, %esi
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L23:
	addl	$1, %eax
	addl	$1, %esi
	cmpl	%eax, %ecx
	jle	.L25
.L56:
	addq	$257, %rdx
	cmpl	%eax, %edi
	je	.L25
.L26:
	cmpb	$48, (%rdx)
	jne	.L23
	cmpl	%esi, %r14d
	cmovl	%esi, %r14d
	addl	$1, %eax
	xorl	%esi, %esi
	cmpl	%eax, %ecx
	jg	.L56
	.p2align 4,,10
	.p2align 3
.L25:
	cmpl	%esi, %r14d
	movl	%r13d, %eax
	cmovl	%esi, %r14d
	leaq	(%r11,%r9), %rsi
	xorl	%r10d, %r10d
	jmp	.L27
	.p2align 4,,10
	.p2align 3
.L28:
	addl	$1, %r10d
.L29:
	subl	$1, %eax
	addq	$255, %rsi
	movl	%eax, %edx
	notl	%edx
	shrl	$31, %edx
	cmpl	%eax, %ecx
	setg	%r15b
	testb	%dl, %r15b
	je	.L31
	movl	%edi, %edx
	subl	%eax, %edx
	subl	$1, %edx
	cmpl	%edx, %ecx
	jle	.L31
.L27:
	cmpb	$48, -1(%rsi)
	jne	.L28
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	xorl	%r10d, %r10d
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L31:
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %r8d
	addl	$1, %edi
	addq	$256, %r9
	cmpl	%r8d, %ecx
	jne	.L22
.L6:
	movl	%r14d, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L32
.L2:
	addq	$8, %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
.L33:
	.cfi_restore_state
	xorl	%r14d, %r14d
	jmp	.L3
.L51:
	xorl	%r14d, %r14d
	jmp	.L6
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 65536
d:
	.zero	65536
	.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	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.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
	leaq	n(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
.L32:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %ecx
	testl	%ecx, %ecx
	je	.L2
	jle	.L33
	leaq	d(%rip), %r13
	xorl	%r14d, %r14d
	movq	%r13, %r15
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movl	n(%rip), %ecx
	addq	$256, %r15
	cmpl	%r14d, %ecx
	jg	.L4
	testl	%ecx, %ecx
	jle	.L51
	leal	-1(%rcx), %r9d
	leaq	1+d(%rip), %rax
	xorl	%r14d, %r14d
	xorl	%r8d, %r8d
	movq	%r9, %rdi
	leaq	(%rax,%r9), %rsi
	addq	$255, %rax
	salq	$8, %rdi
	addq	%rax, %rdi
	.p2align 4,,10
	.p2align 3
.L21:
	movq	%r13, %rax
	xorl	%edx, %edx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L7:
	addq	$256, %rax
	addl	$1, %edx
	cmpq	%rdi, %rax
	je	.L52
.L9:
	cmpb	$48, (%rax)
	jne	.L7
	cmpl	%edx, %r14d
	cmovl	%edx, %r14d
	addq	$256, %rax
	xorl	%edx, %edx
	cmpq	%rdi, %rax
	jne	.L9
.L52:
	cmpl	%edx, %r14d
	movq	%rsi, %rax
	cmovl	%edx, %r14d
	subq	%r9, %rax
	xorl	%edx, %edx
	subq	$1, %rax
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L10:
	addq	$1, %rax
	addl	$1, %edx
	cmpq	%rsi, %rax
	je	.L53
.L12:
	cmpb	$48, (%rax)
	jne	.L10
	cmpl	%edx, %r14d
	cmovl	%edx, %r14d
	addq	$1, %rax
	xorl	%edx, %edx
	cmpq	%rsi, %rax
	jne	.L12
.L53:
	cmpl	%edx, %r14d
	movq	%r13, %r10
	cmovl	%edx, %r14d
	xorl	%r11d, %r11d
	xorl	%eax, %eax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L15:
	addl	$1, %r11d
.L16:
	addl	$1, %eax
	addq	$257, %r10
	leal	(%rax,%r8), %edx
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	cmpl	%edx, %ecx
	jle	.L54
.L13:
	cmpb	$48, (%r10)
	jne	.L15
	cmpl	%r11d, %r14d
	cmovl	%r11d, %r14d
	xorl	%r11d, %r11d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L54:
	cmpl	%r11d, %r14d
	movq	%r13, %rdx
	cmovl	%r11d, %r14d
	xorl	%r10d, %r10d
	xorl	%eax, %eax
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L18:
	addl	$1, %eax
	addl	$1, %r10d
	addq	$255, %rdx
	cmpl	%eax, %r8d
	js	.L34
.L55:
	cmpl	%eax, %ecx
	jle	.L34
.L14:
	cmpb	$48, (%rdx)
	jne	.L18
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %eax
	xorl	%r10d, %r10d
	addq	$255, %rdx
	cmpl	%eax, %r8d
	jns	.L55
	.p2align 4,,10
	.p2align 3
.L34:
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %r8d
	addq	$1, %r13
	addq	$1, %rdi
	addq	$256, %rsi
	cmpl	%r8d, %ecx
	jne	.L21
.L3:
	cmpl	$1, %ecx
	jle	.L6
	leal	-1(%rcx), %r13d
	leal	1(%rcx), %edi
	movl	$1, %r8d
	movslq	%ecx, %r11
	leaq	256+d(%rip), %r9
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%r9, %rdx
	movl	%r8d, %eax
	xorl	%esi, %esi
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L23:
	addl	$1, %eax
	addl	$1, %esi
	cmpl	%eax, %ecx
	jle	.L25
.L56:
	addq	$257, %rdx
	cmpl	%eax, %edi
	je	.L25
.L26:
	cmpb	$48, (%rdx)
	jne	.L23
	cmpl	%esi, %r14d
	cmovl	%esi, %r14d
	addl	$1, %eax
	xorl	%esi, %esi
	cmpl	%eax, %ecx
	jg	.L56
	.p2align 4,,10
	.p2align 3
.L25:
	cmpl	%esi, %r14d
	movl	%r13d, %eax
	cmovl	%esi, %r14d
	leaq	(%r11,%r9), %rsi
	xorl	%r10d, %r10d
	jmp	.L27
	.p2align 4,,10
	.p2align 3
.L28:
	addl	$1, %r10d
.L29:
	subl	$1, %eax
	addq	$255, %rsi
	movl	%eax, %edx
	notl	%edx
	shrl	$31, %edx
	cmpl	%eax, %ecx
	setg	%r15b
	testb	%dl, %r15b
	je	.L31
	movl	%edi, %edx
	subl	%eax, %edx
	subl	$1, %edx
	cmpl	%edx, %ecx
	jle	.L31
.L27:
	cmpb	$48, -1(%rsi)
	jne	.L28
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	xorl	%r10d, %r10d
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L31:
	cmpl	%r10d, %r14d
	cmovl	%r10d, %r14d
	addl	$1, %r8d
	addl	$1, %edi
	addq	$256, %r9
	cmpl	%r8d, %ecx
	jne	.L22
.L6:
	movl	%r14d, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L32
.L2:
	addq	$8, %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
.L33:
	.cfi_restore_state
	xorl	%r14d, %r14d
	jmp	.L3
.L51:
	xorl	%r14d, %r14d
	jmp	.L6
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 32
	.type	d, @object
	.size	d, 65536
d:
	.zero	65536
	.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 N 256
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

char  d[ N ][ N ];
int   n;

static
int scan (
  int x,
  int y,
  int sx,
  int sy,
  int res
  )
{
  int c;

  for ( c = 0; x >= 0 && y >= 0
            && x < n && y < n;
      x += sx, y += sy )
  {
    if ( d[ x ][ y ] == '0' )
    {
      res = MAX( res, c );
      c = 0;
      continue ;
    }

    ++c;
  }
  res = MAX( res, c );

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int res = 0;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%s", d[ i ] );
    }

    for ( i = 0; i < n; ++i )
    {
      res = scan ( 0, i, 1, 0, res );
      res = scan ( i, 0, 0, 1, res );
      res = scan ( 0, i, 1, 1, res );
      res = scan ( 0, i, 1, -1, res );
    }
    for ( i = 1; i < n; ++i )
    {
      res = scan ( i, 0, 1, 1, res );
      res = scan ( i, n - 1, 1, -1, res );
    }

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

  return ( 0 );
}
5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01001010
10100010
10000001
2
01
00
3
000
000
000
0
 5
01011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01001010
10100000
10000001
0
01
00
3
000
000
000
0
 5
01011
00101
01100
10101
00010
8
11000001
10110111
01100111
10111010
10111111
01001010
10100000
10000000
0
01
00
3
001
100
000
0
 5
01011
00000
01000
10101
01010
8
11010001
10110111
01100011
01111010
11111111
01101000
10100010
10000101
0
0
1
6
000
100
000
0
 5
01011
10000
01000
10001
01010
8
11010001
10110111
01100011
01111010
11111111
01101000
10100010
10000101
0
0
1
6
000
100
000
0
 5
00011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01001010
10100010
10000001
2
01
00
3
000
010
000
0
 5
01011
00100
01000
10101
01010
8
11010001
10110111
01100111
01111010
11011111
01001010
10100000
10000001
0
0
1
3
000
000
000
0
 5
01011
00101
01000
10101
00010
8
11000001
10110111
01100111
01111010
11111111
01001010
10100010
10000001
2
01
00
3
000
011
000
0
 5
01011
00101
01000
10101
00010
8
11100001
10110111
01100111
01111010
11111111
01000010
10100000
10000001
2
01
00
0
000
000
000
0
 5
01010
00101
01000
10101
00010
8
10000001
10110111
01100011
01111010
11111110
01001010
10110000
10000001
0
0
00
1
000
010
100
0

4
8
1
0
 4
8
 4
6
 3
8
 2
8
 4
8
1
1
 4
5
 4
8
1
2
 4
8
1
 4
7

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 N 256
#define MAX(A,B) \
  ( (A) > (B) ? (A) : (B) )

char  d[ N ][ N ];
int   n;

static
int scan (
  int x,
  int y,
  int sx,
  int sy,
  int res
  )
{
  int c;

  for ( c = 0; x >= 0 && y >= 0
            && x < n && y < n;
      x += sx, y += sy )
  {
    if ( d[ x ][ y ] == '0' )
    {
      res = MAX( res, c );
      c = 0;
      continue ;
    }

    ++c;
  }
  res = MAX( res, c );

  return ( res );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int res = 0;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      scanf ( "%s", d[ i ] );
    }

    for ( i = 0; i < n; ++i )
    {
      res = scan ( 0, i, 1, 0, res );
      res = scan ( i, 0, 0, 1, res );
      res = scan ( 0, i, 1, 1, res );
      res = scan ( 0, i, 1, -1, res );
    }
    for ( i = 1; i < n; ++i )
    {
      res = scan ( i, 0, 1, 1, res );
      res = scan ( i, n - 1, 1, -1, res );
    }

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

  return ( 0 );
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 65536
d:
	.zero	65536
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$8, %rax
	addq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L4
.L3:
	addl	$1, -4(%rbp)
.L4:
	movl	-28(%rbp), %eax
	addl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	addl	%eax, -24(%rbp)
.L2:
	cmpl	$0, -20(%rbp)
	js	.L5
	cmpl	$0, -24(%rbp)
	js	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jge	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L6
.L5:
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
.L17:
	movl	$0, -4(%rbp)
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	je	.L20
	movl	$0, -8(%rbp)
	jmp	.L11
.L12:
	movl	-8(%rbp), %eax
	cltq
	salq	$8, %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L11:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L12
	movl	$0, -8(%rbp)
	jmp	.L13
.L14:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$0, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$0, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L13:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L14
	movl	$1, -8(%rbp)
	jmp	.L15
.L16:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	n(%rip), %eax
	leal	-1(%rax), %esi
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L15:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L16
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L20:
	nop
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 65536
d:
	.zero	65536
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$8, %rax
	addq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L4
.L3:
	addl	$1, -4(%rbp)
.L4:
	movl	-28(%rbp), %eax
	addl	%eax, -20(%rbp)
	movl	-32(%rbp), %eax
	addl	%eax, -24(%rbp)
.L2:
	cmpl	$0, -20(%rbp)
	js	.L5
	cmpl	$0, -24(%rbp)
	js	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jge	.L5
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L6
.L5:
	movl	-36(%rbp), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, -36(%rbp)
	movl	-36(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
.L17:
	movl	$0, -4(%rbp)
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	je	.L20
	movl	$0, -8(%rbp)
	jmp	.L11
.L12:
	movl	-8(%rbp), %eax
	cltq
	salq	$8, %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L11:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L12
	movl	$0, -8(%rbp)
	jmp	.L13
.L14:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$0, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$0, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %esi
	movl	$0, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L13:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L14
	movl	$1, -8(%rbp)
	jmp	.L15
.L16:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	$0, %esi
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	movl	n(%rip), %eax
	leal	-1(%rax), %esi
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %r8d
	movl	$-1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	scan
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L15:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L16
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L20:
	nop
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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:
