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 head,u , tail;
int q[1000001];
int map[1001][1001];
int dis[1001][1001];
int fac[10];
int sum = 0;
int w,h,n;

void enque(int x) {
  q[tail] = x;
  if(tail == 1000000) tail = -1;
  tail++;

}

int deque() {
  int x = q[head];

  if(head == 1000000) head = -1;
  head ++;
  return x;

}

int bfs(int s,int g) {
  int i,j;
  int dx[4] = {0,-1,0,1};
  int dy[4] = {1,0,-1,0};
  int nx,ny;
  head = tail = 0;

  enque(s);

  for(j = 0;j<h;j++) {
    for(i =0;i<w;i++) {
      dis[j][i] = -1;
    }
  }

  dis[s/w][s%w] = 0;
 
  while(tail != head) {

    u = deque(); 
     
    for(i=0;i<4;i++) {

      nx = u/w + dx[i];
      ny = u%w + dy[i];
      if(nx >=0 && ny >= 0 && nx <h && ny < w) {
	if(map[nx][ny] != -2 && dis[nx][ny] == -1) {
	  dis[nx][ny] = dis[u/w][u%w]+1;
	  enque(nx*w+ny);
	}
      }
    }
  }
  // printf("dis[%d][%d] = %d\n",g/w,g%w,dis[g/w][g%w]);
  return dis[g/w][g%w];
  
  
	 
}
       

int main() {
 
  int i,j,k;
  char ch[1002];
  int start;

  scanf("%d %d %d",&h,&w,&n);


  k = 0;
  for(i=0;i<h;i++) {
 scanf("%s",ch);
    for(j=0;j<w;j++) {
     
      if(ch[j] == 'S') {
	start = i*w+j;
	map[i][j] = 0;
      }
      else if(ch[j] == '.') map[i][j] = -1;
      else if(ch[j] == 'X') map[i][j] = -2;
      else {
	map[i][j] = ch[j] - '0';
	fac[ch[j]-'0'] = i*w+j;
      }
    }
  }

  /* for(j=0;j<h;j++) {
    for(i=0;i<w;i++) {
      printf("%d ",map[j][i]);
    }
    printf("\n");
    }*/

  for(i=1;i<=n;i++) {

    sum += bfs(start,fac[i]);
    start = fac[i];

  }

  printf("%d\n",sum);

  return 0;

}

  ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	head
	.bss
	.align 4
	.type	head, @object
	.size	head, 4
head:
	.zero	4
	.globl	u
	.align 4
	.type	u, @object
	.size	u, 4
u:
	.zero	4
	.globl	tail
	.align 4
	.type	tail, @object
	.size	tail, 4
tail:
	.zero	4
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4000004
q:
	.zero	4000004
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 4008004
map:
	.zero	4008004
	.globl	dis
	.align 32
	.type	dis, @object
	.size	dis, 4008004
dis:
	.zero	4008004
	.globl	fac
	.align 32
	.type	fac, @object
	.size	fac, 40
fac:
	.zero	40
	.globl	sum
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.globl	enque
	.type	enque, @function
enque:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	tail(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	q(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	tail(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L2
	movl	$-1, tail(%rip)
.L2:
	movl	tail(%rip), %eax
	addl	$1, %eax
	movl	%eax, tail(%rip)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	enque, .-enque
	.globl	deque
	.type	deque, @function
deque:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	head(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	head(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L4
	movl	$-1, head(%rip)
.L4:
	movl	head(%rip), %eax
	addl	$1, %eax
	movl	%eax, head(%rip)
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	deque, .-deque
	.globl	bfs
	.type	bfs, @function
bfs:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movl	%esi, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -48(%rbp)
	movl	$-1, -44(%rbp)
	movl	$0, -40(%rbp)
	movl	$1, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$0, -28(%rbp)
	movl	$-1, -24(%rbp)
	movl	$0, -20(%rbp)
	movl	$0, tail(%rip)
	movl	tail(%rip), %eax
	movl	%eax, head(%rip)
	movl	-68(%rbp), %eax
	movl	%eax, %edi
	call	enque
	movl	$0, -60(%rbp)
	jmp	.L7
.L10:
	movl	$0, -64(%rbp)
	jmp	.L8
.L9:
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movl	-60(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -64(%rbp)
.L8:
	movl	w(%rip), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L9
	addl	$1, -60(%rbp)
.L7:
	movl	h(%rip), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L10
	movl	w(%rip), %edi
	movl	-68(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-68(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L11
.L15:
	movl	$0, %eax
	call	deque
	movl	%eax, u(%rip)
	movl	$0, -64(%rbp)
	jmp	.L12
.L14:
	movl	u(%rip), %eax
	movl	w(%rip), %edi
	cltd
	idivl	%edi
	movl	%eax, %edx
	movl	-64(%rbp), %eax
	cltq
	movl	-48(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -56(%rbp)
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	-64(%rbp), %eax
	cltq
	movl	-32(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -52(%rbp)
	cmpl	$0, -56(%rbp)
	js	.L13
	cmpl	$0, -52(%rbp)
	js	.L13
	movl	h(%rip), %eax
	cmpl	%eax, -56(%rbp)
	jge	.L13
	movl	w(%rip), %eax
	cmpl	%eax, -52(%rbp)
	jge	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-2, %eax
	je	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L13
	movl	u(%rip), %eax
	movl	w(%rip), %esi
	cltd
	idivl	%esi
	movl	%eax, %esi
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-56(%rbp), %eax
	movl	%eax, %edx
	movl	-52(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edi
	call	enque
.L13:
	addl	$1, -64(%rbp)
.L12:
	cmpl	$3, -64(%rbp)
	jle	.L14
.L11:
	movl	tail(%rip), %edx
	movl	head(%rip), %eax
	cmpl	%eax, %edx
	jne	.L15
	movl	w(%rip), %edi
	movl	-72(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-72(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bfs, .-bfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1040, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1028(%rbp)
	movl	$0, -1040(%rbp)
	jmp	.L19
.L26:
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1036(%rbp)
	jmp	.L20
.L25:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$83, %al
	jne	.L21
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %edx
	movl	-1036(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -1032(%rbp)
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L22
.L21:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$46, %al
	jne	.L23
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-1, (%rdx,%rax)
	jmp	.L22
.L23:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$88, %al
	jne	.L24
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-2, (%rdx,%rax)
	jmp	.L22
.L24:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %ecx
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %ecx
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	subl	$48, %eax
	movl	-1036(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L22:
	addl	$1, -1036(%rbp)
.L20:
	movl	w(%rip), %eax
	cmpl	%eax, -1036(%rbp)
	jl	.L25
	addl	$1, -1040(%rbp)
.L19:
	movl	h(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jl	.L26
	movl	$1, -1040(%rbp)
	jmp	.L27
.L28:
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-1032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	bfs
	movl	sum(%rip), %edx
	addl	%edx, %eax
	movl	%eax, sum(%rip)
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -1032(%rbp)
	addl	$1, -1040(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jle	.L28
	movl	sum(%rip), %eax
	movl	%eax, %esi
	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	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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	enque
	.type	enque, @function
enque:
.LFB39:
	.cfi_startproc
	endbr64
	movslq	tail(%rip), %rcx
	leaq	q(%rip), %rax
	movl	$0, %edx
	movl	%edi, (%rax,%rcx,4)
	cmpl	$1000000, %ecx
	leal	1(%rcx), %eax
	cmove	%edx, %eax
	movl	%eax, tail(%rip)
	ret
	.cfi_endproc
.LFE39:
	.size	enque, .-enque
	.p2align 4
	.globl	deque
	.type	deque, @function
deque:
.LFB40:
	.cfi_startproc
	endbr64
	movslq	head(%rip), %rcx
	leaq	q(%rip), %rax
	movl	$0, %edx
	movl	(%rax,%rcx,4), %r8d
	cmpl	$1000000, %ecx
	leal	1(%rcx), %eax
	cmove	%edx, %eax
	movl	%eax, head(%rip)
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	deque, .-deque
	.p2align 4
	.globl	bfs
	.type	bfs, @function
bfs:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	dis(%rip), %r15
	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
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%edi, q(%rip)
	movl	w(%rip), %ebx
	movl	h(%rip), %r12d
	movl	%esi, 12(%rsp)
	movl	$1, tail(%rip)
	testl	%r12d, %r12d
	jle	.L9
	testl	%ebx, %ebx
	jle	.L9
	leal	-1(%r12), %r13d
	leaq	4004(%r15), %rax
	movslq	%ebx, %r14
	movq	%r15, %rcx
	imulq	$4004, %r13, %r13
	salq	$2, %r14
	addq	%rax, %r13
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rdi
	movq	%r14, %rdx
	movl	$255, %esi
	call	memset@PLT
	movq	%rax, %rcx
	addq	$4004, %rcx
	cmpq	%r13, %rcx
	jne	.L10
.L9:
	movl	%ebp, %eax
	movl	$1, %r10d
	movb	$0, 8(%rsp)
	xorl	%ecx, %ecx
	cltd
	leaq	q(%rip), %r11
	movl	%r10d, %r14d
	idivl	%ebx
	cltq
	movslq	%edx, %rdx
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	movl	$0, (%r15,%rax,4)
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L13:
	movl	%edx, %r8d
	cmpl	%ebx, %edx
	leal	-1(%rax), %r9d
	notl	%r8d
	setl	%sil
	movl	%r9d, %r10d
	shrl	$31, %r8d
	notl	%r10d
	andl	%r8d, %esi
	cmpl	%r9d, %r12d
	setg	%r8b
	shrl	$31, %r10d
	andl	%r10d, %r8d
	andb	%sil, %r8b
	jne	.L47
.L15:
	movl	%edx, %r9d
	leal	-1(%rdx), %r8d
	negl	%r9d
	shrl	$31, %r9d
	andl	%r9d, %edi
	cmpl	%ebx, %r8d
	setl	%r9b
	andb	%r9b, %dil
	jne	.L48
.L17:
	leal	1(%rax), %edi
	movl	%edi, %r8d
	notl	%r8d
	shrl	$31, %r8d
	andl	%r8d, %esi
	cmpl	%edi, %r12d
	setg	%r8b
	andb	%r8b, %sil
	jne	.L49
.L19:
	cmpl	%ecx, %r14d
	je	.L50
.L21:
	movslq	%ecx, %rax
	cmpl	$1000000, %ecx
	movl	(%r11,%rax,4), %ebp
	movl	$-1, %eax
	cmove	%eax, %ecx
.L11:
	movl	%ebp, %eax
	addl	$1, %ecx
	cltd
	idivl	%ebx
	movl	%eax, %esi
	cmpl	%eax, %r12d
	leal	1(%rdx), %r8d
	notl	%esi
	setg	%dil
	shrl	$31, %esi
	andl	%esi, %edi
	movl	%r8d, %esi
	notl	%esi
	shrl	$31, %esi
	andl	%edi, %esi
	cmpl	%ebx, %r8d
	setl	%r9b
	andb	%r9b, %sil
	je	.L13
	movslq	%eax, %r9
	movslq	%r8d, %r10
	leaq	map(%rip), %r13
	imulq	$1001, %r9, %r9
	addq	%r9, %r10
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L13
	cmpl	$-1, (%r15,%r10,4)
	jne	.L13
	movslq	%edx, %r13
	addq	%r13, %r9
	movl	%eax, %r13d
	imull	%ebx, %r13d
	movl	(%r15,%r9,4), %r9d
	addl	$1, %r9d
	movl	%r9d, 8(%rsp)
	addl	%r8d, %r13d
	xorl	%r9d, %r9d
	leal	1(%r14), %r8d
	cmpl	$1000000, %r14d
	cmove	%r9d, %r8d
	movl	8(%rsp), %r9d
	movb	%sil, 8(%rsp)
	movl	%r9d, (%r15,%r10,4)
	movslq	%r14d, %r9
	movl	%r8d, %r14d
	movl	%r13d, (%r11,%r9,4)
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L49:
	movslq	%edi, %r8
	movslq	%edx, %r10
	imulq	$1001, %r8, %r8
	movq	%r10, (%rsp)
	addq	%r10, %r8
	leaq	map(%rip), %r10
	cmpl	$-2, (%r10,%r8,4)
	je	.L19
	cmpl	$-1, (%r15,%r8,4)
	jne	.L19
	cltq
	imull	%ebx, %edi
	movb	%sil, 8(%rsp)
	imulq	$1001, %rax, %rax
	addq	(%rsp), %rax
	movl	(%r15,%rax,4), %r9d
	leal	1(%r14), %eax
	addl	%edx, %edi
	xorl	%edx, %edx
	addl	$1, %r9d
	cmpl	$1000000, %r14d
	cmove	%edx, %eax
	movslq	%r14d, %rdx
	movl	%r9d, (%r15,%r8,4)
	movl	%edi, (%r11,%rdx,4)
	movl	%eax, %r14d
	cmpl	%ecx, %r14d
	jne	.L21
	.p2align 4,,10
	.p2align 3
.L50:
	cmpb	$0, 8(%rsp)
	movl	%ebp, u(%rip)
	movl	%r14d, head(%rip)
	je	.L22
	movl	%r14d, tail(%rip)
.L22:
	movl	12(%rsp), %eax
	cltd
	idivl	%ebx
	cltq
	movslq	%edx, %rdx
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	movl	(%r15,%rax,4), %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L48:
	.cfi_restore_state
	movslq	%eax, %r9
	movslq	%r8d, %r10
	leaq	map(%rip), %r13
	imulq	$1001, %r9, %r9
	addq	%r9, %r10
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L17
	cmpl	$-1, (%r15,%r10,4)
	jne	.L17
	movslq	%edx, %r13
	addq	%r13, %r9
	movl	%eax, %r13d
	imull	%ebx, %r13d
	movl	(%r15,%r9,4), %r9d
	addl	$1, %r9d
	movl	%r9d, 8(%rsp)
	addl	%r8d, %r13d
	xorl	%r9d, %r9d
	leal	1(%r14), %r8d
	cmpl	$1000000, %r14d
	cmove	%r9d, %r8d
	movl	8(%rsp), %r9d
	movb	%dil, 8(%rsp)
	movl	%r9d, (%r15,%r10,4)
	movslq	%r14d, %r9
	movl	%r8d, %r14d
	movl	%r13d, (%r11,%r9,4)
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L47:
	movslq	%r9d, %r10
	movslq	%edx, %r13
	imulq	$1001, %r10, %r10
	movq	%r13, (%rsp)
	addq	%r13, %r10
	leaq	map(%rip), %r13
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L15
	cmpl	$-1, (%r15,%r10,4)
	jne	.L15
	movslq	%eax, %r13
	imull	%ebx, %r9d
	imulq	$1001, %r13, %r13
	addq	(%rsp), %r13
	movl	(%r15,%r13,4), %r13d
	addl	%edx, %r9d
	addl	$1, %r13d
	movl	%r9d, (%rsp)
	leal	1(%r14), %r9d
	movl	%r13d, 8(%rsp)
	xorl	%r13d, %r13d
	cmpl	$1000000, %r14d
	cmove	%r13d, %r9d
	movl	8(%rsp), %r13d
	movb	%r8b, 8(%rsp)
	movl	%r13d, (%r15,%r10,4)
	movslq	%r14d, %r10
	movl	(%rsp), %r14d
	movl	%r14d, (%r11,%r10,4)
	movl	%r9d, %r14d
	jmp	.L15
	.cfi_endproc
.LFE41:
	.size	bfs, .-bfs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	w(%rip), %rdx
	leaq	n(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	h(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1032, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1016(%rsp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %edx
	testl	%edx, %edx
	jle	.L52
	leaq	map(%rip), %r13
	xorl	%r12d, %r12d
	movq	%rsp, %r15
	leaq	.LC1(%rip), %rbx
	leaq	fac(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L59:
	movq	%rbx, %rdi
	movq	%r15, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	w(%rip), %edi
	testl	%edi, %edi
	jle	.L53
	movl	%r12d, %edx
	movq	%r15, %rcx
	movq	%r13, %rsi
	imull	%edi, %edx
	addl	%edx, %edi
	jmp	.L58
	.p2align 4,,10
	.p2align 3
.L54:
	cmpb	$46, %al
	je	.L68
	cmpb	$88, %al
	je	.L69
	subl	$48, %eax
	movl	%eax, (%rsi)
	cltq
	movl	%edx, (%r14,%rax,4)
.L55:
	addl	$1, %edx
	addq	$1, %rcx
	addq	$4, %rsi
	cmpl	%edi, %edx
	je	.L53
.L58:
	movsbl	(%rcx), %eax
	cmpb	$83, %al
	jne	.L54
	movl	%edx, %ebp
	addl	$1, %edx
	movl	$0, (%rsi)
	addq	$1, %rcx
	addq	$4, %rsi
	cmpl	%edi, %edx
	jne	.L58
.L53:
	addl	$1, %r12d
	addq	$4004, %r13
	cmpl	%r12d, h(%rip)
	jg	.L59
.L52:
	movl	n(%rip), %eax
	testl	%eax, %eax
	jle	.L60
	movl	$1, %ebx
	leaq	fac(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L61:
	movl	(%r12,%rbx,4), %esi
	movl	%ebp, %edi
	call	bfs
	movl	(%r12,%rbx,4), %ebp
	addl	sum(%rip), %eax
	addq	$1, %rbx
	cmpl	%ebx, n(%rip)
	movl	%eax, sum(%rip)
	jge	.L61
.L62:
	movl	%eax, %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	1016(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$1032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L68:
	.cfi_restore_state
	movl	$-1, (%rsi)
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L69:
	movl	$-2, (%rsi)
	jmp	.L55
.L60:
	movl	sum(%rip), %eax
	jmp	.L62
.L70:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	sum
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	fac
	.align 32
	.type	fac, @object
	.size	fac, 40
fac:
	.zero	40
	.globl	dis
	.align 32
	.type	dis, @object
	.size	dis, 4008004
dis:
	.zero	4008004
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 4008004
map:
	.zero	4008004
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4000004
q:
	.zero	4000004
	.globl	tail
	.align 4
	.type	tail, @object
	.size	tail, 4
tail:
	.zero	4
	.globl	u
	.align 4
	.type	u, @object
	.size	u, 4
u:
	.zero	4
	.globl	head
	.align 4
	.type	head, @object
	.size	head, 4
head:
	.zero	4
	.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	enque
	.type	enque, @function
enque:
.LFB39:
	.cfi_startproc
	endbr64
	movslq	tail(%rip), %rcx
	leaq	q(%rip), %rax
	movl	$0, %edx
	movl	%edi, (%rax,%rcx,4)
	cmpl	$1000000, %ecx
	leal	1(%rcx), %eax
	cmove	%edx, %eax
	movl	%eax, tail(%rip)
	ret
	.cfi_endproc
.LFE39:
	.size	enque, .-enque
	.p2align 4
	.globl	deque
	.type	deque, @function
deque:
.LFB40:
	.cfi_startproc
	endbr64
	movslq	head(%rip), %rcx
	leaq	q(%rip), %rax
	movl	$0, %edx
	movl	(%rax,%rcx,4), %r8d
	cmpl	$1000000, %ecx
	leal	1(%rcx), %eax
	cmove	%edx, %eax
	movl	%eax, head(%rip)
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	deque, .-deque
	.p2align 4
	.globl	bfs
	.type	bfs, @function
bfs:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	dis(%rip), %r15
	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
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%edi, q(%rip)
	movl	w(%rip), %ebx
	movl	h(%rip), %r12d
	movl	%esi, 12(%rsp)
	movl	$1, tail(%rip)
	testl	%r12d, %r12d
	jle	.L9
	testl	%ebx, %ebx
	jle	.L9
	leal	-1(%r12), %r13d
	leaq	4004(%r15), %rax
	movslq	%ebx, %r14
	movq	%r15, %rcx
	imulq	$4004, %r13, %r13
	salq	$2, %r14
	addq	%rax, %r13
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rdi
	movq	%r14, %rdx
	movl	$255, %esi
	call	memset@PLT
	movq	%rax, %rcx
	addq	$4004, %rcx
	cmpq	%r13, %rcx
	jne	.L10
.L9:
	movl	%ebp, %eax
	movl	$1, %r10d
	movb	$0, 8(%rsp)
	xorl	%ecx, %ecx
	cltd
	leaq	q(%rip), %r11
	movl	%r10d, %r14d
	idivl	%ebx
	cltq
	movslq	%edx, %rdx
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	movl	$0, (%r15,%rax,4)
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L13:
	movl	%edx, %r8d
	cmpl	%ebx, %edx
	leal	-1(%rax), %r9d
	notl	%r8d
	setl	%sil
	movl	%r9d, %r10d
	shrl	$31, %r8d
	notl	%r10d
	andl	%r8d, %esi
	cmpl	%r9d, %r12d
	setg	%r8b
	shrl	$31, %r10d
	andl	%r10d, %r8d
	andb	%sil, %r8b
	jne	.L47
.L15:
	movl	%edx, %r9d
	leal	-1(%rdx), %r8d
	negl	%r9d
	shrl	$31, %r9d
	andl	%r9d, %edi
	cmpl	%ebx, %r8d
	setl	%r9b
	andb	%r9b, %dil
	jne	.L48
.L17:
	leal	1(%rax), %edi
	movl	%edi, %r8d
	notl	%r8d
	shrl	$31, %r8d
	andl	%r8d, %esi
	cmpl	%edi, %r12d
	setg	%r8b
	andb	%r8b, %sil
	jne	.L49
.L19:
	cmpl	%ecx, %r14d
	je	.L50
.L21:
	movslq	%ecx, %rax
	cmpl	$1000000, %ecx
	movl	(%r11,%rax,4), %ebp
	movl	$-1, %eax
	cmove	%eax, %ecx
.L11:
	movl	%ebp, %eax
	addl	$1, %ecx
	cltd
	idivl	%ebx
	movl	%eax, %esi
	cmpl	%eax, %r12d
	leal	1(%rdx), %r8d
	notl	%esi
	setg	%dil
	shrl	$31, %esi
	andl	%esi, %edi
	movl	%r8d, %esi
	notl	%esi
	shrl	$31, %esi
	andl	%edi, %esi
	cmpl	%ebx, %r8d
	setl	%r9b
	andb	%r9b, %sil
	je	.L13
	movslq	%eax, %r9
	movslq	%r8d, %r10
	leaq	map(%rip), %r13
	imulq	$1001, %r9, %r9
	addq	%r9, %r10
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L13
	cmpl	$-1, (%r15,%r10,4)
	jne	.L13
	movslq	%edx, %r13
	addq	%r13, %r9
	movl	%eax, %r13d
	imull	%ebx, %r13d
	movl	(%r15,%r9,4), %r9d
	addl	$1, %r9d
	movl	%r9d, 8(%rsp)
	addl	%r8d, %r13d
	xorl	%r9d, %r9d
	leal	1(%r14), %r8d
	cmpl	$1000000, %r14d
	cmove	%r9d, %r8d
	movl	8(%rsp), %r9d
	movb	%sil, 8(%rsp)
	movl	%r9d, (%r15,%r10,4)
	movslq	%r14d, %r9
	movl	%r8d, %r14d
	movl	%r13d, (%r11,%r9,4)
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L49:
	movslq	%edi, %r8
	movslq	%edx, %r10
	imulq	$1001, %r8, %r8
	movq	%r10, (%rsp)
	addq	%r10, %r8
	leaq	map(%rip), %r10
	cmpl	$-2, (%r10,%r8,4)
	je	.L19
	cmpl	$-1, (%r15,%r8,4)
	jne	.L19
	cltq
	imull	%ebx, %edi
	movb	%sil, 8(%rsp)
	imulq	$1001, %rax, %rax
	addq	(%rsp), %rax
	movl	(%r15,%rax,4), %r9d
	leal	1(%r14), %eax
	addl	%edx, %edi
	xorl	%edx, %edx
	addl	$1, %r9d
	cmpl	$1000000, %r14d
	cmove	%edx, %eax
	movslq	%r14d, %rdx
	movl	%r9d, (%r15,%r8,4)
	movl	%edi, (%r11,%rdx,4)
	movl	%eax, %r14d
	cmpl	%ecx, %r14d
	jne	.L21
	.p2align 4,,10
	.p2align 3
.L50:
	cmpb	$0, 8(%rsp)
	movl	%ebp, u(%rip)
	movl	%r14d, head(%rip)
	je	.L22
	movl	%r14d, tail(%rip)
.L22:
	movl	12(%rsp), %eax
	cltd
	idivl	%ebx
	cltq
	movslq	%edx, %rdx
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	movl	(%r15,%rax,4), %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L48:
	.cfi_restore_state
	movslq	%eax, %r9
	movslq	%r8d, %r10
	leaq	map(%rip), %r13
	imulq	$1001, %r9, %r9
	addq	%r9, %r10
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L17
	cmpl	$-1, (%r15,%r10,4)
	jne	.L17
	movslq	%edx, %r13
	addq	%r13, %r9
	movl	%eax, %r13d
	imull	%ebx, %r13d
	movl	(%r15,%r9,4), %r9d
	addl	$1, %r9d
	movl	%r9d, 8(%rsp)
	addl	%r8d, %r13d
	xorl	%r9d, %r9d
	leal	1(%r14), %r8d
	cmpl	$1000000, %r14d
	cmove	%r9d, %r8d
	movl	8(%rsp), %r9d
	movb	%dil, 8(%rsp)
	movl	%r9d, (%r15,%r10,4)
	movslq	%r14d, %r9
	movl	%r8d, %r14d
	movl	%r13d, (%r11,%r9,4)
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L47:
	movslq	%r9d, %r10
	movslq	%edx, %r13
	imulq	$1001, %r10, %r10
	movq	%r13, (%rsp)
	addq	%r13, %r10
	leaq	map(%rip), %r13
	cmpl	$-2, 0(%r13,%r10,4)
	je	.L15
	cmpl	$-1, (%r15,%r10,4)
	jne	.L15
	movslq	%eax, %r13
	imull	%ebx, %r9d
	imulq	$1001, %r13, %r13
	addq	(%rsp), %r13
	movl	(%r15,%r13,4), %r13d
	addl	%edx, %r9d
	addl	$1, %r13d
	movl	%r9d, (%rsp)
	leal	1(%r14), %r9d
	movl	%r13d, 8(%rsp)
	xorl	%r13d, %r13d
	cmpl	$1000000, %r14d
	cmove	%r13d, %r9d
	movl	8(%rsp), %r13d
	movb	%r8b, 8(%rsp)
	movl	%r13d, (%r15,%r10,4)
	movslq	%r14d, %r10
	movl	(%rsp), %r14d
	movl	%r14d, (%r11,%r10,4)
	movl	%r9d, %r14d
	jmp	.L15
	.cfi_endproc
.LFE41:
	.size	bfs, .-bfs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	w(%rip), %rdx
	leaq	n(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	h(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1032, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1016(%rsp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	h(%rip), %edx
	testl	%edx, %edx
	jle	.L52
	leaq	map(%rip), %r13
	xorl	%r12d, %r12d
	movq	%rsp, %r15
	leaq	.LC1(%rip), %rbx
	leaq	fac(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L59:
	movq	%rbx, %rdi
	movq	%r15, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	w(%rip), %edi
	testl	%edi, %edi
	jle	.L53
	movl	%r12d, %edx
	movq	%r15, %rcx
	movq	%r13, %rsi
	imull	%edi, %edx
	addl	%edx, %edi
	jmp	.L58
	.p2align 4,,10
	.p2align 3
.L54:
	cmpb	$46, %al
	je	.L68
	cmpb	$88, %al
	je	.L69
	subl	$48, %eax
	movl	%eax, (%rsi)
	cltq
	movl	%edx, (%r14,%rax,4)
.L55:
	addl	$1, %edx
	addq	$1, %rcx
	addq	$4, %rsi
	cmpl	%edi, %edx
	je	.L53
.L58:
	movsbl	(%rcx), %eax
	cmpb	$83, %al
	jne	.L54
	movl	%edx, %ebp
	addl	$1, %edx
	movl	$0, (%rsi)
	addq	$1, %rcx
	addq	$4, %rsi
	cmpl	%edi, %edx
	jne	.L58
.L53:
	addl	$1, %r12d
	addq	$4004, %r13
	cmpl	%r12d, h(%rip)
	jg	.L59
.L52:
	movl	n(%rip), %eax
	testl	%eax, %eax
	jle	.L60
	movl	$1, %ebx
	leaq	fac(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L61:
	movl	(%r12,%rbx,4), %esi
	movl	%ebp, %edi
	call	bfs
	movl	(%r12,%rbx,4), %ebp
	addl	sum(%rip), %eax
	addq	$1, %rbx
	cmpl	%ebx, n(%rip)
	movl	%eax, sum(%rip)
	jge	.L61
.L62:
	movl	%eax, %edx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	1016(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$1032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L68:
	.cfi_restore_state
	movl	$-1, (%rsi)
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L69:
	movl	$-2, (%rsi)
	jmp	.L55
.L60:
	movl	sum(%rip), %eax
	jmp	.L62
.L70:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	sum
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	fac
	.align 32
	.type	fac, @object
	.size	fac, 40
fac:
	.zero	40
	.globl	dis
	.align 32
	.type	dis, @object
	.size	dis, 4008004
dis:
	.zero	4008004
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 4008004
map:
	.zero	4008004
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4000004
q:
	.zero	4000004
	.globl	tail
	.align 4
	.type	tail, @object
	.size	tail, 4
tail:
	.zero	4
	.globl	u
	.align 4
	.type	u, @object
	.size	u, 4
u:
	.zero	4
	.globl	head
	.align 4
	.type	head, @object
	.size	head, 4
head:
	.zero	4
	.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 head,u , tail;
int q[1000001];
int map[1001][1001];
int dis[1001][1001];
int fac[10];
int sum = 0;
int w,h,n;

void enque(int x) {
  q[tail] = x;
  if(tail == 1000000) tail = -1;
  tail++;

}

int deque() {
  int x = q[head];

  if(head == 1000000) head = -1;
  head ++;
  return x;

}

int bfs(int s,int g) {
  int i,j;
  int dx[4] = {0,-1,0,1};
  int dy[4] = {1,0,-1,0};
  int nx,ny;
  head = tail = 0;

  enque(s);

  for(j = 0;j<h;j++) {
    for(i =0;i<w;i++) {
      dis[j][i] = -1;
    }
  }

  dis[s/w][s%w] = 0;
 
  while(tail != head) {

    u = deque(); 
     
    for(i=0;i<4;i++) {

      nx = u/w + dx[i];
      ny = u%w + dy[i];
      if(nx >=0 && ny >= 0 && nx <h && ny < w) {
	if(map[nx][ny] != -2 && dis[nx][ny] == -1) {
	  dis[nx][ny] = dis[u/w][u%w]+1;
	  enque(nx*w+ny);
	}
      }
    }
  }
  // printf("dis[%d][%d] = %d\n",g/w,g%w,dis[g/w][g%w]);
  return dis[g/w][g%w];
  
  
	 
}
       

int main() {
 
  int i,j,k;
  char ch[1002];
  int start;

  scanf("%d %d %d",&h,&w,&n);


  k = 0;
  for(i=0;i<h;i++) {
 scanf("%s",ch);
    for(j=0;j<w;j++) {
     
      if(ch[j] == 'S') {
	start = i*w+j;
	map[i][j] = 0;
      }
      else if(ch[j] == '.') map[i][j] = -1;
      else if(ch[j] == 'X') map[i][j] = -2;
      else {
	map[i][j] = ch[j] - '0';
	fac[ch[j]-'0'] = i*w+j;
      }
    }
  }

  /* for(j=0;j<h;j++) {
    for(i=0;i<w;i++) {
      printf("%d ",map[j][i]);
    }
    printf("\n");
    }*/

  for(i=1;i<=n;i++) {

    sum += bfs(start,fac[i]);
    start = fac[i];

  }

  printf("%d\n",sum);

  return 0;

}

  
3 3 1
S..
...
..1

4

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 head,u , tail;
int q[1000001];
int map[1001][1001];
int dis[1001][1001];
int fac[10];
int sum = 0;
int w,h,n;

void enque(int x) {
  q[tail] = x;
  if(tail == 1000000) tail = -1;
  tail++;

}

int deque() {
  int x = q[head];

  if(head == 1000000) head = -1;
  head ++;
  return x;

}

int bfs(int s,int g) {
  int i,j;
  int dx[4] = {0,-1,0,1};
  int dy[4] = {1,0,-1,0};
  int nx,ny;
  head = tail = 0;

  enque(s);

  for(j = 0;j<h;j++) {
    for(i =0;i<w;i++) {
      dis[j][i] = -1;
    }
  }

  dis[s/w][s%w] = 0;
 
  while(tail != head) {

    u = deque(); 
     
    for(i=0;i<4;i++) {

      nx = u/w + dx[i];
      ny = u%w + dy[i];
      if(nx >=0 && ny >= 0 && nx <h && ny < w) {
	if(map[nx][ny] != -2 && dis[nx][ny] == -1) {
	  dis[nx][ny] = dis[u/w][u%w]+1;
	  enque(nx*w+ny);
	}
      }
    }
  }
  // printf("dis[%d][%d] = %d\n",g/w,g%w,dis[g/w][g%w]);
  return dis[g/w][g%w];
  
  
	 
}
       

int main() {
 
  int i,j,k;
  char ch[1002];
  int start;

  scanf("%d %d %d",&h,&w,&n);


  k = 0;
  for(i=0;i<h;i++) {
 scanf("%s",ch);
    for(j=0;j<w;j++) {
     
      if(ch[j] == 'S') {
	start = i*w+j;
	map[i][j] = 0;
      }
      else if(ch[j] == '.') map[i][j] = -1;
      else if(ch[j] == 'X') map[i][j] = -2;
      else {
	map[i][j] = ch[j] - '0';
	fac[ch[j]-'0'] = i*w+j;
      }
    }
  }

  /* for(j=0;j<h;j++) {
    for(i=0;i<w;i++) {
      printf("%d ",map[j][i]);
    }
    printf("\n");
    }*/

  for(i=1;i<=n;i++) {

    sum += bfs(start,fac[i]);
    start = fac[i];

  }

  printf("%d\n",sum);

  return 0;

}

  ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	head
	.bss
	.align 4
	.type	head, @object
	.size	head, 4
head:
	.zero	4
	.globl	u
	.align 4
	.type	u, @object
	.size	u, 4
u:
	.zero	4
	.globl	tail
	.align 4
	.type	tail, @object
	.size	tail, 4
tail:
	.zero	4
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4000004
q:
	.zero	4000004
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 4008004
map:
	.zero	4008004
	.globl	dis
	.align 32
	.type	dis, @object
	.size	dis, 4008004
dis:
	.zero	4008004
	.globl	fac
	.align 32
	.type	fac, @object
	.size	fac, 40
fac:
	.zero	40
	.globl	sum
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.globl	enque
	.type	enque, @function
enque:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	tail(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	q(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	tail(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L2
	movl	$-1, tail(%rip)
.L2:
	movl	tail(%rip), %eax
	addl	$1, %eax
	movl	%eax, tail(%rip)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	enque, .-enque
	.globl	deque
	.type	deque, @function
deque:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	head(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	head(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L4
	movl	$-1, head(%rip)
.L4:
	movl	head(%rip), %eax
	addl	$1, %eax
	movl	%eax, head(%rip)
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	deque, .-deque
	.globl	bfs
	.type	bfs, @function
bfs:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movl	%esi, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -48(%rbp)
	movl	$-1, -44(%rbp)
	movl	$0, -40(%rbp)
	movl	$1, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$0, -28(%rbp)
	movl	$-1, -24(%rbp)
	movl	$0, -20(%rbp)
	movl	$0, tail(%rip)
	movl	tail(%rip), %eax
	movl	%eax, head(%rip)
	movl	-68(%rbp), %eax
	movl	%eax, %edi
	call	enque
	movl	$0, -60(%rbp)
	jmp	.L7
.L10:
	movl	$0, -64(%rbp)
	jmp	.L8
.L9:
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movl	-60(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -64(%rbp)
.L8:
	movl	w(%rip), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L9
	addl	$1, -60(%rbp)
.L7:
	movl	h(%rip), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L10
	movl	w(%rip), %edi
	movl	-68(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-68(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L11
.L15:
	movl	$0, %eax
	call	deque
	movl	%eax, u(%rip)
	movl	$0, -64(%rbp)
	jmp	.L12
.L14:
	movl	u(%rip), %eax
	movl	w(%rip), %edi
	cltd
	idivl	%edi
	movl	%eax, %edx
	movl	-64(%rbp), %eax
	cltq
	movl	-48(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -56(%rbp)
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	-64(%rbp), %eax
	cltq
	movl	-32(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -52(%rbp)
	cmpl	$0, -56(%rbp)
	js	.L13
	cmpl	$0, -52(%rbp)
	js	.L13
	movl	h(%rip), %eax
	cmpl	%eax, -56(%rbp)
	jge	.L13
	movl	w(%rip), %eax
	cmpl	%eax, -52(%rbp)
	jge	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-2, %eax
	je	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L13
	movl	u(%rip), %eax
	movl	w(%rip), %esi
	cltd
	idivl	%esi
	movl	%eax, %esi
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-56(%rbp), %eax
	movl	%eax, %edx
	movl	-52(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edi
	call	enque
.L13:
	addl	$1, -64(%rbp)
.L12:
	cmpl	$3, -64(%rbp)
	jle	.L14
.L11:
	movl	tail(%rip), %edx
	movl	head(%rip), %eax
	cmpl	%eax, %edx
	jne	.L15
	movl	w(%rip), %edi
	movl	-72(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-72(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bfs, .-bfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1040, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1028(%rbp)
	movl	$0, -1040(%rbp)
	jmp	.L19
.L26:
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1036(%rbp)
	jmp	.L20
.L25:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$83, %al
	jne	.L21
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %edx
	movl	-1036(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -1032(%rbp)
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L22
.L21:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$46, %al
	jne	.L23
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-1, (%rdx,%rax)
	jmp	.L22
.L23:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$88, %al
	jne	.L24
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-2, (%rdx,%rax)
	jmp	.L22
.L24:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %ecx
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %ecx
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	subl	$48, %eax
	movl	-1036(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L22:
	addl	$1, -1036(%rbp)
.L20:
	movl	w(%rip), %eax
	cmpl	%eax, -1036(%rbp)
	jl	.L25
	addl	$1, -1040(%rbp)
.L19:
	movl	h(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jl	.L26
	movl	$1, -1040(%rbp)
	jmp	.L27
.L28:
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-1032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	bfs
	movl	sum(%rip), %edx
	addl	%edx, %eax
	movl	%eax, sum(%rip)
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -1032(%rbp)
	addl	$1, -1040(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jle	.L28
	movl	sum(%rip), %eax
	movl	%eax, %esi
	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	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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	head
	.bss
	.align 4
	.type	head, @object
	.size	head, 4
head:
	.zero	4
	.globl	u
	.align 4
	.type	u, @object
	.size	u, 4
u:
	.zero	4
	.globl	tail
	.align 4
	.type	tail, @object
	.size	tail, 4
tail:
	.zero	4
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4000004
q:
	.zero	4000004
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 4008004
map:
	.zero	4008004
	.globl	dis
	.align 32
	.type	dis, @object
	.size	dis, 4008004
dis:
	.zero	4008004
	.globl	fac
	.align 32
	.type	fac, @object
	.size	fac, 40
fac:
	.zero	40
	.globl	sum
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.text
	.globl	enque
	.type	enque, @function
enque:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	tail(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	q(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	tail(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L2
	movl	$-1, tail(%rip)
.L2:
	movl	tail(%rip), %eax
	addl	$1, %eax
	movl	%eax, tail(%rip)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	enque, .-enque
	.globl	deque
	.type	deque, @function
deque:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	head(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	head(%rip), %eax
	cmpl	$1000000, %eax
	jne	.L4
	movl	$-1, head(%rip)
.L4:
	movl	head(%rip), %eax
	addl	$1, %eax
	movl	%eax, head(%rip)
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	deque, .-deque
	.globl	bfs
	.type	bfs, @function
bfs:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$80, %rsp
	movl	%edi, -68(%rbp)
	movl	%esi, -72(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -48(%rbp)
	movl	$-1, -44(%rbp)
	movl	$0, -40(%rbp)
	movl	$1, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$0, -28(%rbp)
	movl	$-1, -24(%rbp)
	movl	$0, -20(%rbp)
	movl	$0, tail(%rip)
	movl	tail(%rip), %eax
	movl	%eax, head(%rip)
	movl	-68(%rbp), %eax
	movl	%eax, %edi
	call	enque
	movl	$0, -60(%rbp)
	jmp	.L7
.L10:
	movl	$0, -64(%rbp)
	jmp	.L8
.L9:
	movl	-64(%rbp), %eax
	movslq	%eax, %rdx
	movl	-60(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$-1, (%rdx,%rax)
	addl	$1, -64(%rbp)
.L8:
	movl	w(%rip), %eax
	cmpl	%eax, -64(%rbp)
	jl	.L9
	addl	$1, -60(%rbp)
.L7:
	movl	h(%rip), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L10
	movl	w(%rip), %edi
	movl	-68(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-68(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L11
.L15:
	movl	$0, %eax
	call	deque
	movl	%eax, u(%rip)
	movl	$0, -64(%rbp)
	jmp	.L12
.L14:
	movl	u(%rip), %eax
	movl	w(%rip), %edi
	cltd
	idivl	%edi
	movl	%eax, %edx
	movl	-64(%rbp), %eax
	cltq
	movl	-48(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -56(%rbp)
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	-64(%rbp), %eax
	cltq
	movl	-32(%rbp,%rax,4), %eax
	addl	%edx, %eax
	movl	%eax, -52(%rbp)
	cmpl	$0, -56(%rbp)
	js	.L13
	cmpl	$0, -52(%rbp)
	js	.L13
	movl	h(%rip), %eax
	cmpl	%eax, -56(%rbp)
	jge	.L13
	movl	w(%rip), %eax
	cmpl	%eax, -52(%rbp)
	jge	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-2, %eax
	je	.L13
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	jne	.L13
	movl	u(%rip), %eax
	movl	w(%rip), %esi
	cltd
	idivl	%esi
	movl	%eax, %esi
	movl	u(%rip), %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movl	-56(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-56(%rbp), %eax
	movl	%eax, %edx
	movl	-52(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edi
	call	enque
.L13:
	addl	$1, -64(%rbp)
.L12:
	cmpl	$3, -64(%rbp)
	jle	.L14
.L11:
	movl	tail(%rip), %edx
	movl	head(%rip), %eax
	cmpl	%eax, %edx
	jne	.L15
	movl	w(%rip), %edi
	movl	-72(%rbp), %eax
	cltd
	idivl	%edi
	movl	%eax, %esi
	movl	w(%rip), %ecx
	movl	-72(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, %eax
	movslq	%eax, %rdx
	movslq	%esi, %rax
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dis(%rip), %rax
	movl	(%rdx,%rax), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bfs, .-bfs
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$1040, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1028(%rbp)
	movl	$0, -1040(%rbp)
	jmp	.L19
.L26:
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -1036(%rbp)
	jmp	.L20
.L25:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$83, %al
	jne	.L21
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %edx
	movl	-1036(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -1032(%rbp)
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$0, (%rdx,%rax)
	jmp	.L22
.L21:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$46, %al
	jne	.L23
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-1, (%rdx,%rax)
	jmp	.L22
.L23:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	cmpb	$88, %al
	jne	.L24
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	$-2, (%rdx,%rax)
	jmp	.L22
.L24:
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %ecx
	movl	-1036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-1040(%rbp), %eax
	cltq
	imulq	$1001, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	map(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	w(%rip), %eax
	imull	-1040(%rbp), %eax
	movl	%eax, %ecx
	movl	-1036(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %eax
	movsbl	%al, %eax
	subl	$48, %eax
	movl	-1036(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L22:
	addl	$1, -1036(%rbp)
.L20:
	movl	w(%rip), %eax
	cmpl	%eax, -1036(%rbp)
	jl	.L25
	addl	$1, -1040(%rbp)
.L19:
	movl	h(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jl	.L26
	movl	$1, -1040(%rbp)
	jmp	.L27
.L28:
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-1032(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	bfs
	movl	sum(%rip), %edx
	addl	%edx, %eax
	movl	%eax, sum(%rip)
	movl	-1040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	fac(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -1032(%rbp)
	addl	$1, -1040(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -1040(%rbp)
	jle	.L28
	movl	sum(%rip), %eax
	movl	%eax, %esi
	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	.L30
	call	__stack_chk_fail@PLT
.L30:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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:
