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_MAX 15
#define M_MAX 15000000

int memo[N_MAX][3][3],ismemoized[N_MAX][3][3];

int main(){
  int card[15],n,m,i,j,from,to,rest,cnt,ans;

  while(1){
    scanf("%d %d",&n,&m);
    ans = m+1;

    if(n==0&&m==0) return 0;

    for(i=0; i<3; i++){
      int t1,t2;
      scanf("%d",&t1);
      for(j=0; j<t1; j++){
	scanf("%d",&t2);
	card[t2-1] = i;
      }
    }

    for(i=0; i<=2; i+=2){
      from = i; cnt = 0;
      for(j=1; j<=n; j++){
	to = card[j-1];
	rest = 3-(from+to);

	switch(abs(from-to)){
	case 1:
	  cnt += move(n-j,from,rest) + 1;
	  from = rest;
	  break;
	case 2:
	  cnt += move(n-j,from,to) + move(n-j,to,from) + 2;
	  break;
	}
      }
      ans = (ans>cnt)?cnt:ans;
    }

    printf("%d\n",(ans==m+1)?-1:ans);
  }
}

int move(num,from,to){
  int rest = 3-(from+to),ans;

  if(ismemoized[num][from][to])
    return memo[num][from][to];

  if(num==0)
    ans = 0;
  else if(num==1)
    ans = abs(from-to);
  else
    switch(abs(from-to)){
    case 0:
      ans = 0;
      break;
    case 1:
      ans = move(num-1,from,rest)+move(num-1,rest,to)+1;
      break;
    case 2:
      ans = move(num,from,rest)+move(num,rest,to);
      break;
    }

  ans = (ans<=M_MAX)?ans:(M_MAX+1);

  ismemoized[num][from][to] = 1;
  memo[num][from][to] = ans;
  return ans;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 540
memo:
	.zero	540
	.globl	ismemoized
	.align 32
	.type	ismemoized, @object
	.size	ismemoized, 540
ismemoized:
	.zero	540
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.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
	pushq	%rbx
	subq	$136, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-136(%rbp), %rdx
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -108(%rbp)
	movl	-140(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-136(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	jmp	.L19
.L2:
	movl	$0, -124(%rbp)
	jmp	.L4
.L7:
	leaq	-132(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -120(%rbp)
	jmp	.L5
.L6:
	leaq	-128(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-128(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-124(%rbp), %edx
	movl	%edx, -96(%rbp,%rax,4)
	addl	$1, -120(%rbp)
.L5:
	movl	-132(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jl	.L6
	addl	$1, -124(%rbp)
.L4:
	cmpl	$2, -124(%rbp)
	jle	.L7
	movl	$0, -124(%rbp)
	jmp	.L8
.L14:
	movl	-124(%rbp), %eax
	movl	%eax, -116(%rbp)
	movl	$0, -112(%rbp)
	movl	$1, -120(%rbp)
	jmp	.L9
.L13:
	movl	-120(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-96(%rbp,%rax,4), %eax
	movl	%eax, -104(%rbp)
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -100(%rbp)
	movl	-116(%rbp), %eax
	subl	-104(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$1, %eax
	je	.L10
	cmpl	$2, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-100(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	$1, %eax
	addl	%eax, -112(%rbp)
	movl	-100(%rbp), %eax
	movl	%eax, -116(%rbp)
	jmp	.L12
.L11:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-104(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$2, %eax
	addl	%eax, -112(%rbp)
	nop
.L12:
	addl	$1, -120(%rbp)
.L9:
	movl	-140(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jle	.L13
	movl	-108(%rbp), %edx
	movl	-112(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -108(%rbp)
	addl	$2, -124(%rbp)
.L8:
	cmpl	$2, -124(%rbp)
	jle	.L14
	movl	-136(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -108(%rbp)
	je	.L15
	movl	-108(%rbp), %eax
	jmp	.L16
.L15:
	movl	$-1, %eax
.L16:
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L19:
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	move
	.type	move, @function
move:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset 3, -24
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %edx
	movl	-44(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L21
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L22
.L21:
	cmpl	$0, -36(%rbp)
	jne	.L23
	movl	$0, -24(%rbp)
	jmp	.L24
.L23:
	cmpl	$1, -36(%rbp)
	jne	.L25
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L25:
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$2, %eax
	je	.L26
	cmpl	$2, %eax
	jg	.L24
	testl	%eax, %eax
	je	.L27
	cmpl	$1, %eax
	je	.L28
	jmp	.L24
.L27:
	movl	$0, -24(%rbp)
	jmp	.L24
.L28:
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$1, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L26:
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	movl	%eax, -24(%rbp)
	nop
.L24:
	movl	-24(%rbp), %eax
	movl	$15000001, %edx
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	memo(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	move, .-move
	.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	move
	.type	move, @function
move:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%edx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	ismemoized(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	0(%r13,%r13,8), %rax
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%esi, %rbx
	leaq	(%rbx,%rbx,2), %rdx
	addq	%rdx, %rax
	addq	%r15, %rax
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	(%r14,%rax,4), %r8d
	testl	%r8d, %r8d
	jne	.L14
	testl	%edi, %edi
	jne	.L15
.L4:
	leaq	(%rbx,%rbx,2), %rdx
	leaq	0(%r13,%r13,8), %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	addq	%r15, %rax
	movl	$1, (%r14,%rax,4)
	movl	%r8d, (%rdx,%rax,4)
.L1:
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r8d, %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
.L15:
	.cfi_restore_state
	movl	%esi, %edx
	subl	%r15d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	$1, %edi
	je	.L16
	leal	(%rsi,%r15), %edx
	movl	$3, %r9d
	subl	%edx, %r9d
	cmpl	$1, %eax
	je	.L6
	cmpl	$2, %eax
	je	.L7
	xorl	%eax, %eax
	cmpl	%r15d, %esi
	cmovne	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %r8d
	jmp	.L1
	.p2align 4,,10
	.p2align 3
.L7:
	movl	%r9d, %edx
	xorl	%eax, %eax
	movl	%r9d, 12(%rsp)
	movl	%edi, 8(%rsp)
	call	move
	movl	12(%rsp), %esi
	movl	8(%rsp), %edi
	movl	%r15d, %edx
	movl	%eax, %ebp
	xorl	%eax, %eax
	call	move
	leal	0(%rbp,%rax), %r8d
	movl	$15000001, %eax
	cmpl	%eax, %r8d
	cmovg	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L6:
	leal	-1(%rdi), %ebp
	movl	%r9d, %edx
	xorl	%eax, %eax
	movl	%r9d, 12(%rsp)
	movl	%ebp, %edi
	call	move
	movl	12(%rsp), %esi
	movl	%r15d, %edx
	movl	%ebp, %edi
	movl	%eax, 8(%rsp)
	xorl	%eax, %eax
	call	move
	movl	8(%rsp), %ecx
	leal	1(%rcx,%rax), %r8d
	movl	$15000001, %eax
	cmpl	%eax, %r8d
	cmovg	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L16:
	movl	$15000001, %r8d
	cmpl	%r8d, %eax
	cmovle	%eax, %r8d
	jmp	.L4
	.cfi_endproc
.LFE24:
	.size	move, .-move
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.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
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L30:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	36(%rsp), %eax
	leal	1(%rax), %ecx
	orl	32(%rsp), %eax
	movl	%ecx, 12(%rsp)
	je	.L46
	xorl	%ebp, %ebp
	leaq	40(%rsp), %r15
	leaq	44(%rsp), %r14
.L18:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	testl	%eax, %eax
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	subl	$1, %eax
	cltq
	movl	%ebp, 48(%rsp,%rax,4)
	cmpl	%r12d, 40(%rsp)
	jg	.L19
.L21:
	addl	$1, %ebp
	cmpl	$3, %ebp
	jne	.L18
	movl	$0, 8(%rsp)
	movl	32(%rsp), %esi
.L22:
	testl	%esi, %esi
	jle	.L47
	movl	8(%rsp), %r14d
	movl	$1, %r10d
	xorl	%r13d, %r13d
	leaq	48(%rsp), %rbp
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L49:
	cmpl	$2, %eax
	jne	.L25
	movl	%esi, %edi
	movl	%r11d, %edx
	movl	%r14d, %esi
	xorl	%eax, %eax
	subl	%r10d, %edi
	call	move
	movl	32(%rsp), %edi
	movl	%r11d, %esi
	movl	%r14d, %edx
	movl	%eax, %r15d
	xorl	%eax, %eax
	subl	%r10d, %edi
	call	move
	movl	32(%rsp), %esi
	leal	2(%r15,%rax), %eax
	addl	%eax, %r13d
.L25:
	addq	$1, %r10
	cmpl	%r10d, %esi
	jl	.L48
.L26:
	movl	-4(%rbp,%r10,4), %r11d
	movl	%r14d, %edx
	subl	%r11d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	$1, %eax
	jne	.L49
	addl	%r14d, %r11d
	movl	$3, %r12d
	movl	%esi, %edi
	xorl	%eax, %eax
	subl	%r11d, %r12d
	movl	%r14d, %esi
	subl	%r10d, %edi
	addq	$1, %r10
	movl	%r12d, %edx
	movl	%r12d, %r14d
	call	move
	movl	32(%rsp), %esi
	leal	1(%r13,%rax), %r13d
	cmpl	%r10d, %esi
	jge	.L26
.L48:
	movl	12(%rsp), %eax
	cmpl	%r13d, %eax
	cmovle	%eax, %r13d
	addl	$2, 8(%rsp)
	movl	8(%rsp), %eax
	movl	%r13d, 12(%rsp)
	cmpl	$4, %eax
	jne	.L22
	movl	%r13d, %ecx
.L31:
	movl	36(%rsp), %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	addl	$1, %eax
	cmpl	%ecx, %eax
	movl	$-1, %eax
	cmovne	%ecx, %eax
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L30
.L47:
	movl	12(%rsp), %ecx
	xorl	%eax, %eax
	testl	%ecx, %ecx
	cmovle	%ecx, %eax
	movl	%eax, 12(%rsp)
	movl	%eax, %ecx
	jmp	.L31
.L46:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	addq	$136, %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
.L50:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	ismemoized
	.bss
	.align 32
	.type	ismemoized, @object
	.size	ismemoized, 540
ismemoized:
	.zero	540
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 540
memo:
	.zero	540
	.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	move
	.type	move, @function
move:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%edx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	ismemoized(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	0(%r13,%r13,8), %rax
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%esi, %rbx
	leaq	(%rbx,%rbx,2), %rdx
	addq	%rdx, %rax
	addq	%r15, %rax
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	(%r14,%rax,4), %r8d
	testl	%r8d, %r8d
	jne	.L14
	testl	%edi, %edi
	jne	.L15
.L4:
	leaq	(%rbx,%rbx,2), %rdx
	leaq	0(%r13,%r13,8), %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	addq	%r15, %rax
	movl	$1, (%r14,%rax,4)
	movl	%r8d, (%rdx,%rax,4)
.L1:
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r8d, %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
.L15:
	.cfi_restore_state
	movl	%esi, %edx
	subl	%r15d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	$1, %edi
	je	.L16
	leal	(%rsi,%r15), %edx
	movl	$3, %r9d
	subl	%edx, %r9d
	cmpl	$1, %eax
	je	.L6
	cmpl	$2, %eax
	je	.L7
	xorl	%eax, %eax
	cmpl	%r15d, %esi
	cmovne	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %r8d
	jmp	.L1
	.p2align 4,,10
	.p2align 3
.L7:
	movl	%r9d, %edx
	xorl	%eax, %eax
	movl	%r9d, 12(%rsp)
	movl	%edi, 8(%rsp)
	call	move
	movl	12(%rsp), %esi
	movl	8(%rsp), %edi
	movl	%r15d, %edx
	movl	%eax, %ebp
	xorl	%eax, %eax
	call	move
	leal	0(%rbp,%rax), %r8d
	movl	$15000001, %eax
	cmpl	%eax, %r8d
	cmovg	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L6:
	leal	-1(%rdi), %ebp
	movl	%r9d, %edx
	xorl	%eax, %eax
	movl	%r9d, 12(%rsp)
	movl	%ebp, %edi
	call	move
	movl	12(%rsp), %esi
	movl	%r15d, %edx
	movl	%ebp, %edi
	movl	%eax, 8(%rsp)
	xorl	%eax, %eax
	call	move
	movl	8(%rsp), %ecx
	leal	1(%rcx,%rax), %r8d
	movl	$15000001, %eax
	cmpl	%eax, %r8d
	cmovg	%eax, %r8d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L16:
	movl	$15000001, %r8d
	cmpl	%r8d, %eax
	cmovle	%eax, %r8d
	jmp	.L4
	.cfi_endproc
.LFE24:
	.size	move, .-move
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.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
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L30:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	36(%rsp), %eax
	leal	1(%rax), %ecx
	orl	32(%rsp), %eax
	movl	%ecx, 12(%rsp)
	je	.L46
	xorl	%ebp, %ebp
	leaq	40(%rsp), %r15
	leaq	44(%rsp), %r14
.L18:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	testl	%eax, %eax
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	subl	$1, %eax
	cltq
	movl	%ebp, 48(%rsp,%rax,4)
	cmpl	%r12d, 40(%rsp)
	jg	.L19
.L21:
	addl	$1, %ebp
	cmpl	$3, %ebp
	jne	.L18
	movl	$0, 8(%rsp)
	movl	32(%rsp), %esi
.L22:
	testl	%esi, %esi
	jle	.L47
	movl	8(%rsp), %r14d
	movl	$1, %r10d
	xorl	%r13d, %r13d
	leaq	48(%rsp), %rbp
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L49:
	cmpl	$2, %eax
	jne	.L25
	movl	%esi, %edi
	movl	%r11d, %edx
	movl	%r14d, %esi
	xorl	%eax, %eax
	subl	%r10d, %edi
	call	move
	movl	32(%rsp), %edi
	movl	%r11d, %esi
	movl	%r14d, %edx
	movl	%eax, %r15d
	xorl	%eax, %eax
	subl	%r10d, %edi
	call	move
	movl	32(%rsp), %esi
	leal	2(%r15,%rax), %eax
	addl	%eax, %r13d
.L25:
	addq	$1, %r10
	cmpl	%r10d, %esi
	jl	.L48
.L26:
	movl	-4(%rbp,%r10,4), %r11d
	movl	%r14d, %edx
	subl	%r11d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	$1, %eax
	jne	.L49
	addl	%r14d, %r11d
	movl	$3, %r12d
	movl	%esi, %edi
	xorl	%eax, %eax
	subl	%r11d, %r12d
	movl	%r14d, %esi
	subl	%r10d, %edi
	addq	$1, %r10
	movl	%r12d, %edx
	movl	%r12d, %r14d
	call	move
	movl	32(%rsp), %esi
	leal	1(%r13,%rax), %r13d
	cmpl	%r10d, %esi
	jge	.L26
.L48:
	movl	12(%rsp), %eax
	cmpl	%r13d, %eax
	cmovle	%eax, %r13d
	addl	$2, 8(%rsp)
	movl	8(%rsp), %eax
	movl	%r13d, 12(%rsp)
	cmpl	$4, %eax
	jne	.L22
	movl	%r13d, %ecx
.L31:
	movl	36(%rsp), %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	addl	$1, %eax
	cmpl	%ecx, %eax
	movl	$-1, %eax
	cmovne	%ecx, %eax
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L30
.L47:
	movl	12(%rsp), %ecx
	xorl	%eax, %eax
	testl	%ecx, %ecx
	cmovle	%ecx, %eax
	movl	%eax, 12(%rsp)
	movl	%eax, %ecx
	jmp	.L31
.L46:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	addq	$136, %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
.L50:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	ismemoized
	.bss
	.align 32
	.type	ismemoized, @object
	.size	ismemoized, 540
ismemoized:
	.zero	540
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 540
memo:
	.zero	540
	.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_MAX 15
#define M_MAX 15000000

int memo[N_MAX][3][3],ismemoized[N_MAX][3][3];

int main(){
  int card[15],n,m,i,j,from,to,rest,cnt,ans;

  while(1){
    scanf("%d %d",&n,&m);
    ans = m+1;

    if(n==0&&m==0) return 0;

    for(i=0; i<3; i++){
      int t1,t2;
      scanf("%d",&t1);
      for(j=0; j<t1; j++){
	scanf("%d",&t2);
	card[t2-1] = i;
      }
    }

    for(i=0; i<=2; i+=2){
      from = i; cnt = 0;
      for(j=1; j<=n; j++){
	to = card[j-1];
	rest = 3-(from+to);

	switch(abs(from-to)){
	case 1:
	  cnt += move(n-j,from,rest) + 1;
	  from = rest;
	  break;
	case 2:
	  cnt += move(n-j,from,to) + move(n-j,to,from) + 2;
	  break;
	}
      }
      ans = (ans>cnt)?cnt:ans;
    }

    printf("%d\n",(ans==m+1)?-1:ans);
  }
}

int move(num,from,to){
  int rest = 3-(from+to),ans;

  if(ismemoized[num][from][to])
    return memo[num][from][to];

  if(num==0)
    ans = 0;
  else if(num==1)
    ans = abs(from-to);
  else
    switch(abs(from-to)){
    case 0:
      ans = 0;
      break;
    case 1:
      ans = move(num-1,from,rest)+move(num-1,rest,to)+1;
      break;
    case 2:
      ans = move(num,from,rest)+move(num,rest,to);
      break;
    }

  ans = (ans<=M_MAX)?ans:(M_MAX+1);

  ismemoized[num][from][to] = 1;
  memo[num][from][to] = ans;
  return ans;
}
3 10
0
1 1
2 2 3
4 20
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 3
0
1 1
2 2 3
0 0
 3 8
0
1 1
2 2 3
4 7
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 6
0
1 1
2 2 3
0 0
 3 10
0
1 1
2 2 3
4 7
2 1 2
1 2
1 4
1 5
2 1 2
0
0
3 6
0
1 1
2 2 3
0 0
 3 10
0
1 1
2 2 3
4 13
2 1 2
1 3
1 4
2 5
2 1 2
0
0
3 10
0
1 1
2 2 3
0 0
 3 10
0
1 1
2 2 3
4 7
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 3
0
1 1
2 2 3
0 0
 3 10
0
1 1
2 2 3
4 7
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 6
0
1 1
2 2 3
0 0
 3 18
0
1 1
2 2 3
4 7
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 6
0
1 1
2 2 3
0 0
 3 10
0
1 1
2 2 3
4 13
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 6
0
1 1
2 2 3
0 0
 3 18
0
1 1
2 2 3
4 20
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 3
0
1 1
2 2 3
0 0
 3 18
0
1 1
2 2 3
4 20
2 1 2
1 3
1 4
1 5
2 1 2
0
0
3 3
0
1 1
2 2 6
0 0

9
3
0
-1
 -1
3
0
-1
 9
-1
0
-1
 9
3
0
9
 9
3
0
-1
 9
3
0
-1
 9
3
0
-1
 9
3
0
-1
 9
3
0
-1
 9
3
0
-1

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_MAX 15
#define M_MAX 15000000

int memo[N_MAX][3][3],ismemoized[N_MAX][3][3];

int main(){
  int card[15],n,m,i,j,from,to,rest,cnt,ans;

  while(1){
    scanf("%d %d",&n,&m);
    ans = m+1;

    if(n==0&&m==0) return 0;

    for(i=0; i<3; i++){
      int t1,t2;
      scanf("%d",&t1);
      for(j=0; j<t1; j++){
	scanf("%d",&t2);
	card[t2-1] = i;
      }
    }

    for(i=0; i<=2; i+=2){
      from = i; cnt = 0;
      for(j=1; j<=n; j++){
	to = card[j-1];
	rest = 3-(from+to);

	switch(abs(from-to)){
	case 1:
	  cnt += move(n-j,from,rest) + 1;
	  from = rest;
	  break;
	case 2:
	  cnt += move(n-j,from,to) + move(n-j,to,from) + 2;
	  break;
	}
      }
      ans = (ans>cnt)?cnt:ans;
    }

    printf("%d\n",(ans==m+1)?-1:ans);
  }
}

int move(num,from,to){
  int rest = 3-(from+to),ans;

  if(ismemoized[num][from][to])
    return memo[num][from][to];

  if(num==0)
    ans = 0;
  else if(num==1)
    ans = abs(from-to);
  else
    switch(abs(from-to)){
    case 0:
      ans = 0;
      break;
    case 1:
      ans = move(num-1,from,rest)+move(num-1,rest,to)+1;
      break;
    case 2:
      ans = move(num,from,rest)+move(num,rest,to);
      break;
    }

  ans = (ans<=M_MAX)?ans:(M_MAX+1);

  ismemoized[num][from][to] = 1;
  memo[num][from][to] = ans;
  return ans;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 540
memo:
	.zero	540
	.globl	ismemoized
	.align 32
	.type	ismemoized, @object
	.size	ismemoized, 540
ismemoized:
	.zero	540
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.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
	pushq	%rbx
	subq	$136, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-136(%rbp), %rdx
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -108(%rbp)
	movl	-140(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-136(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	jmp	.L19
.L2:
	movl	$0, -124(%rbp)
	jmp	.L4
.L7:
	leaq	-132(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -120(%rbp)
	jmp	.L5
.L6:
	leaq	-128(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-128(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-124(%rbp), %edx
	movl	%edx, -96(%rbp,%rax,4)
	addl	$1, -120(%rbp)
.L5:
	movl	-132(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jl	.L6
	addl	$1, -124(%rbp)
.L4:
	cmpl	$2, -124(%rbp)
	jle	.L7
	movl	$0, -124(%rbp)
	jmp	.L8
.L14:
	movl	-124(%rbp), %eax
	movl	%eax, -116(%rbp)
	movl	$0, -112(%rbp)
	movl	$1, -120(%rbp)
	jmp	.L9
.L13:
	movl	-120(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-96(%rbp,%rax,4), %eax
	movl	%eax, -104(%rbp)
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -100(%rbp)
	movl	-116(%rbp), %eax
	subl	-104(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$1, %eax
	je	.L10
	cmpl	$2, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-100(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	$1, %eax
	addl	%eax, -112(%rbp)
	movl	-100(%rbp), %eax
	movl	%eax, -116(%rbp)
	jmp	.L12
.L11:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-104(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$2, %eax
	addl	%eax, -112(%rbp)
	nop
.L12:
	addl	$1, -120(%rbp)
.L9:
	movl	-140(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jle	.L13
	movl	-108(%rbp), %edx
	movl	-112(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -108(%rbp)
	addl	$2, -124(%rbp)
.L8:
	cmpl	$2, -124(%rbp)
	jle	.L14
	movl	-136(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -108(%rbp)
	je	.L15
	movl	-108(%rbp), %eax
	jmp	.L16
.L15:
	movl	$-1, %eax
.L16:
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L19:
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	move
	.type	move, @function
move:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset 3, -24
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %edx
	movl	-44(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L21
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L22
.L21:
	cmpl	$0, -36(%rbp)
	jne	.L23
	movl	$0, -24(%rbp)
	jmp	.L24
.L23:
	cmpl	$1, -36(%rbp)
	jne	.L25
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L25:
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$2, %eax
	je	.L26
	cmpl	$2, %eax
	jg	.L24
	testl	%eax, %eax
	je	.L27
	cmpl	$1, %eax
	je	.L28
	jmp	.L24
.L27:
	movl	$0, -24(%rbp)
	jmp	.L24
.L28:
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$1, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L26:
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	movl	%eax, -24(%rbp)
	nop
.L24:
	movl	-24(%rbp), %eax
	movl	$15000001, %edx
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	memo(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	move, .-move
	.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	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 540
memo:
	.zero	540
	.globl	ismemoized
	.align 32
	.type	ismemoized, @object
	.size	ismemoized, 540
ismemoized:
	.zero	540
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.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
	pushq	%rbx
	subq	$136, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L17:
	leaq	-136(%rbp), %rdx
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -108(%rbp)
	movl	-140(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-136(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	jmp	.L19
.L2:
	movl	$0, -124(%rbp)
	jmp	.L4
.L7:
	leaq	-132(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -120(%rbp)
	jmp	.L5
.L6:
	leaq	-128(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-128(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-124(%rbp), %edx
	movl	%edx, -96(%rbp,%rax,4)
	addl	$1, -120(%rbp)
.L5:
	movl	-132(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jl	.L6
	addl	$1, -124(%rbp)
.L4:
	cmpl	$2, -124(%rbp)
	jle	.L7
	movl	$0, -124(%rbp)
	jmp	.L8
.L14:
	movl	-124(%rbp), %eax
	movl	%eax, -116(%rbp)
	movl	$0, -112(%rbp)
	movl	$1, -120(%rbp)
	jmp	.L9
.L13:
	movl	-120(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-96(%rbp,%rax,4), %eax
	movl	%eax, -104(%rbp)
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -100(%rbp)
	movl	-116(%rbp), %eax
	subl	-104(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$1, %eax
	je	.L10
	cmpl	$2, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-100(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	$1, %eax
	addl	%eax, -112(%rbp)
	movl	-100(%rbp), %eax
	movl	%eax, -116(%rbp)
	jmp	.L12
.L11:
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-104(%rbp), %edx
	movl	-116(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-140(%rbp), %eax
	subl	-120(%rbp), %eax
	movl	-116(%rbp), %edx
	movl	-104(%rbp), %ecx
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$2, %eax
	addl	%eax, -112(%rbp)
	nop
.L12:
	addl	$1, -120(%rbp)
.L9:
	movl	-140(%rbp), %eax
	cmpl	%eax, -120(%rbp)
	jle	.L13
	movl	-108(%rbp), %edx
	movl	-112(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -108(%rbp)
	addl	$2, -124(%rbp)
.L8:
	cmpl	$2, -124(%rbp)
	jle	.L14
	movl	-136(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -108(%rbp)
	je	.L15
	movl	-108(%rbp), %eax
	jmp	.L16
.L15:
	movl	$-1, %eax
.L16:
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L17
.L19:
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	move
	.type	move, @function
move:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset 3, -24
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %edx
	movl	-44(%rbp), %eax
	addl	%eax, %edx
	movl	$3, %eax
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L21
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L22
.L21:
	cmpl	$0, -36(%rbp)
	jne	.L23
	movl	$0, -24(%rbp)
	jmp	.L24
.L23:
	cmpl	$1, -36(%rbp)
	jne	.L25
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L25:
	movl	-40(%rbp), %eax
	subl	-44(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	$2, %eax
	je	.L26
	cmpl	$2, %eax
	jg	.L24
	testl	%eax, %eax
	je	.L27
	cmpl	$1, %eax
	je	.L28
	jmp	.L24
.L27:
	movl	$0, -24(%rbp)
	jmp	.L24
.L28:
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-36(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	movl	%ecx, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	addl	$1, %eax
	movl	%eax, -24(%rbp)
	jmp	.L24
.L26:
	movl	-20(%rbp), %edx
	movl	-40(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	movl	%eax, %ebx
	movl	-44(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	move
	addl	%ebx, %eax
	movl	%eax, -24(%rbp)
	nop
.L24:
	movl	-24(%rbp), %eax
	movl	$15000001, %edx
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	ismemoized(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-44(%rbp), %eax
	movslq	%eax, %rsi
	movl	-36(%rbp), %eax
	cltq
	movl	-40(%rbp), %edx
	movslq	%edx, %rcx
	movq	%rax, %rdx
	salq	$3, %rdx
	addq	%rax, %rdx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rcx
	leaq	memo(%rip), %rdx
	movl	-24(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	move, .-move
	.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:
