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<assert.h>

#define  N_MAX  60

int ans[2000];

/* ???????????????????¢????????????? */
int check(int p, int s[N_MAX]);

int main(void){

  int n = -1, p = -1;
  int st_num[N_MAX];
  int count = 0;
  int sum_st;
  int kill = 0;
  int i, j;
  
  while(1){

    /* ????????? */
    for(j = 0; j < 60; j++) {
      st_num[j] = 0;
    }
    i = 0;
    kill = 0;
    
    scanf("%d %d", &n, &p);

    if(n == 0 && p == 0) break;

    assert(n != 0 && p != 0);
    assert(n > 2);
    assert(p > 1);

    sum_st = p;
    
    while(1){

      if(p > 0){
	p--;
	st_num[i]++;
	
	/* ???????¢???? */
	if(check(p, st_num) != 0) break;
		
      }
      else if(p == 0 && st_num[i] > 0){
	p = st_num[i];
	st_num[i] = 0;
      }

      assert(p >= 0);

      /* ???????????? */
      //printf("p = %d ", p);
      //printf("st_num[%d] = %d ", i, st_num[i]);
      //printf("kill = %d\n", kill);

      int sum = p;      
      for(j = 0; j < n; j++){
	sum = sum + st_num[j];
      }
      //printf("sum = %d\n", sum);
      assert(sum == sum_st);
      
      /* ???????????¢?????? */
      if(kill > 1000000){
	i = 0;
	break;
      }
      
      i++;
      i = i % n;	

      kill++;
    }

    assert(count >= 0);

    ans[count++] = i;

    assert(ans[count-1] < n);

    /* ???????????? */
    //printf("test2\n");
  }

  /* ??????????????? */
  for(i = 0; i < count; i++){
    printf("%d\n", ans[i]);
  }
  
  return 0;
}

int check(int p, int s[N_MAX]){

  int flag = 0;
  int i;

  if(p != 0)
    flag = 334;
  
  for(i = 0; i < N_MAX; i++){
    if(s[i] != 0){
      flag++;
    }
  }
  
  if(flag == 1)
    return 1;
  else
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 8000
ans:
	.zero	8000
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"/tmp/tmp2jnbhpca/temp.c"
.LC2:
	.string	"n != 0 && p != 0"
.LC3:
	.string	"n > 2"
.LC4:
	.string	"p > 1"
.LC5:
	.string	"p >= 0"
.LC6:
	.string	"sum == sum_st"
.LC7:
	.string	"count >= 0"
.LC8:
	.string	"ans[count-1] < n"
.LC9:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$288, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$-1, -288(%rbp)
	movl	$-1, -284(%rbp)
	movl	$0, -280(%rbp)
	movl	$0, -276(%rbp)
.L21:
	movl	$0, -268(%rbp)
	jmp	.L2
.L3:
	movl	-268(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
	addl	$1, -268(%rbp)
.L2:
	cmpl	$59, -268(%rbp)
	jle	.L3
	movl	$0, -272(%rbp)
	movl	$0, -276(%rbp)
	leaq	-284(%rbp), %rdx
	leaq	-288(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	je	.L28
.L4:
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	je	.L6
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L27
.L6:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$33, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L27:
	movl	-288(%rbp), %eax
	cmpl	$2, %eax
	jg	.L8
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$34, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L8:
	movl	-284(%rbp), %eax
	cmpl	$1, %eax
	jg	.L9
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$35, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L9:
	movl	-284(%rbp), %eax
	movl	%eax, -260(%rbp)
.L18:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jle	.L10
	movl	-284(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-272(%rbp), %eax
	cltq
	movl	%edx, -256(%rbp,%rax,4)
	movl	-284(%rbp), %eax
	leaq	-256(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	check
	testl	%eax, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
.L11:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jns	.L13
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$54, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L13:
	movl	-284(%rbp), %eax
	movl	%eax, -264(%rbp)
	movl	$0, -268(%rbp)
	jmp	.L14
.L15:
	movl	-268(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	addl	%eax, -264(%rbp)
	addl	$1, -268(%rbp)
.L14:
	movl	-288(%rbp), %eax
	cmpl	%eax, -268(%rbp)
	jl	.L15
	movl	-264(%rbp), %eax
	cmpl	-260(%rbp), %eax
	je	.L16
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$66, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC6(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L16:
	cmpl	$1000000, -276(%rbp)
	jle	.L17
	movl	$0, -272(%rbp)
	jmp	.L12
.L17:
	addl	$1, -272(%rbp)
	movl	-288(%rbp), %ecx
	movl	-272(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, -272(%rbp)
	addl	$1, -276(%rbp)
	jmp	.L18
.L12:
	cmpl	$0, -280(%rbp)
	jns	.L19
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$80, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC7(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L19:
	movl	-280(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -280(%rbp)
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ans(%rip), %rdx
	movl	-272(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-280(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-288(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L21
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$84, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC8(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L28:
	nop
	movl	$0, -272(%rbp)
	jmp	.L22
.L23:
	movl	-272(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC9(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -272(%rbp)
.L22:
	movl	-272(%rbp), %eax
	cmpl	-280(%rbp), %eax
	jl	.L23
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	check
	.type	check, @function
check:
.LFB1:
	.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)
	movq	%rsi, -32(%rbp)
	movl	$0, -8(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L30
	movl	$334, -8(%rbp)
.L30:
	movl	$0, -4(%rbp)
	jmp	.L31
.L33:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L32
	addl	$1, -8(%rbp)
.L32:
	addl	$1, -4(%rbp)
.L31:
	cmpl	$59, -4(%rbp)
	jle	.L33
	cmpl	$1, -8(%rbp)
	jne	.L34
	movl	$1, %eax
	jmp	.L35
.L34:
	movl	$0, %eax
.L35:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
	.type	__PRETTY_FUNCTION__.0, @object
	.size	__PRETTY_FUNCTION__.0, 5
__PRETTY_FUNCTION__.0:
	.string	"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 %d"
.LC1:
	.string	"/tmp/tmp2jnbhpca/temp.c"
.LC2:
	.string	"n != 0 && p != 0"
.LC3:
	.string	"n > 2"
.LC4:
	.string	"p > 1"
.LC6:
	.string	"p >= 0"
.LC7:
	.string	"sum == sum_st"
.LC8:
	.string	"ans[count-1] < n"
.LC9:
	.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
	movl	$1, %ebx
	subq	$312, %rsp
	.cfi_def_cfa_offset 368
	movq	%fs:40, %rax
	movq	%rax, 296(%rsp)
	xorl	%eax, %eax
	leaq	ans(%rip), %rax
	movl	$-1, 40(%rsp)
	movq	%rax, 24(%rsp)
	movq	%rax, %rbp
	leaq	48(%rsp), %rax
	movq	%rax, 16(%rsp)
	leaq	44(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	40(%rsp), %rax
	movl	$-1, 44(%rsp)
	movq	%rax, (%rsp)
.L22:
	movq	16(%rsp), %rdi
	xorl	%eax, %eax
	movl	$30, %ecx
	movq	(%rsp), %rsi
	movq	8(%rsp), %rdx
	leal	-1(%rbx), %r12d
	rep stosq
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %esi
	movdqa	.LC5(%rip), %xmm2
	testl	%esi, %esi
	jne	.L2
	movl	44(%rsp), %eax
	testl	%eax, %eax
	je	.L81
.L3:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$33, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__assert_fail@PLT
	.p2align 4,,10
	.p2align 3
.L2:
	movl	44(%rsp), %r10d
	testl	%r10d, %r10d
	je	.L3
	cmpl	$2, %esi
	jle	.L82
	cmpl	$1, %r10d
	jle	.L7
	movl	%esi, %r12d
	movl	%esi, %edi
	movl	%r10d, %r8d
	movl	$1000002, %r9d
	andl	$-4, %r12d
	shrl	$2, %edi
	xorl	%r14d, %r14d
	xorl	%edx, %edx
	pxor	%xmm1, %xmm1
	movslq	%r12d, %r13
	leal	1(%r12), %r11d
	.p2align 4,,10
	.p2align 3
.L8:
	testl	%r8d, %r8d
	jg	.L83
	je	.L84
	testb	%r14b, %r14b
	je	.L16
	movl	%r8d, 44(%rsp)
.L16:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$54, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC6(%rip), %rdi
	call	__assert_fail@PLT
	.p2align 4,,10
	.p2align 3
.L83:
	movslq	%edx, %rax
	movdqa	%xmm1, %xmm3
	movdqa	%xmm1, %xmm0
	subl	$1, %r8d
	addl	$1, 48(%rsp,%rax,4)
	movl	%r8d, %eax
	negl	%eax
	sbbl	%ecx, %ecx
	andl	$334, %ecx
	pcmpeqd	48(%rsp), %xmm3
	pcmpeqd	64(%rsp), %xmm0
	pcmpeqd	%xmm1, %xmm3
	pandn	%xmm2, %xmm0
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	80(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	96(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	112(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	128(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	144(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	160(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	176(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	192(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	208(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	224(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	240(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	256(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	272(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$8, %xmm3
	paddd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$4, %xmm3
	paddd	%xmm3, %xmm0
	movd	%xmm0, %eax
	addl	%ecx, %eax
	cmpl	$1, %eax
	je	.L11
.L79:
	movl	$1, %r14d
.L12:
	cmpl	$3, %esi
	je	.L85
	movdqa	48(%rsp), %xmm0
	cmpl	$1, %edi
	jbe	.L14
	paddd	64(%rsp), %xmm0
	cmpl	$2, %edi
	je	.L14
	paddd	80(%rsp), %xmm0
	cmpl	$3, %edi
	je	.L14
	paddd	96(%rsp), %xmm0
	cmpl	$4, %edi
	je	.L14
	paddd	112(%rsp), %xmm0
	cmpl	$5, %edi
	je	.L14
	paddd	128(%rsp), %xmm0
	cmpl	$6, %edi
	je	.L14
	paddd	144(%rsp), %xmm0
	cmpl	$7, %edi
	je	.L14
	paddd	160(%rsp), %xmm0
	cmpl	$8, %edi
	je	.L14
	paddd	176(%rsp), %xmm0
	cmpl	$9, %edi
	je	.L14
	paddd	192(%rsp), %xmm0
	cmpl	$10, %edi
	je	.L14
	paddd	208(%rsp), %xmm0
	cmpl	$11, %edi
	je	.L14
	paddd	224(%rsp), %xmm0
	cmpl	$12, %edi
	je	.L14
	paddd	240(%rsp), %xmm0
	cmpl	$13, %edi
	je	.L14
	paddd	256(%rsp), %xmm0
	cmpl	$14, %edi
	je	.L14
	paddd	272(%rsp), %xmm0
	.p2align 4,,10
	.p2align 3
.L14:
	movdqa	%xmm0, %xmm3
	psrldq	$8, %xmm3
	paddd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$4, %xmm3
	paddd	%xmm3, %xmm0
	movd	%xmm0, %ecx
	addl	%r8d, %ecx
	cmpl	%r12d, %esi
	je	.L17
	addl	48(%rsp,%r13,4), %ecx
	movl	%r11d, %r15d
	cmpl	%r11d, %esi
	jle	.L17
.L28:
	movslq	%r15d, %rax
	addl	$1, %r15d
	addl	48(%rsp,%rax,4), %ecx
	cmpl	%r15d, %esi
	jle	.L17
	movslq	%r15d, %r15
	addl	48(%rsp,%r15,4), %ecx
.L17:
	cmpl	%ecx, %r10d
	jne	.L86
	subl	$1, %r9d
	je	.L20
	leal	1(%rdx), %eax
	cltd
	idivl	%esi
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L84:
	movslq	%edx, %rcx
	movl	48(%rsp,%rcx,4), %eax
	testl	%eax, %eax
	jle	.L12
	movl	$0, 48(%rsp,%rcx,4)
	movl	%eax, %r8d
	jmp	.L79
.L11:
	movl	%r8d, 44(%rsp)
	movl	%edx, 0(%rbp)
	cmpl	%edx, %esi
	jle	.L21
.L26:
	addl	$1, %ebx
	addq	$4, %rbp
	jmp	.L22
.L85:
	movl	48(%rsp), %ecx
	movl	$1, %r15d
	addl	%r8d, %ecx
	jmp	.L28
.L20:
	testb	%r14b, %r14b
	je	.L25
	movl	%r8d, 44(%rsp)
.L25:
	movl	$0, 0(%rbp)
	jmp	.L26
.L81:
	testl	%r12d, %r12d
	je	.L24
	leal	-2(%rbx), %edx
	leaq	4+ans(%rip), %rax
	movq	24(%rsp), %r12
	leaq	(%rax,%rdx,4), %rbp
	leaq	.LC9(%rip), %rbx
.L23:
	movl	(%r12), %edx
	movq	%rbx, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %r12
	call	__printf_chk@PLT
	cmpq	%rbp, %r12
	jne	.L23
.L24:
	movq	296(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L87
	addq	$312, %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
.L86:
	.cfi_restore_state
	testb	%r14b, %r14b
	je	.L19
	movl	%r8d, 44(%rsp)
.L19:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$66, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC7(%rip), %rdi
	call	__assert_fail@PLT
.L82:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$34, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC3(%rip), %rdi
	call	__assert_fail@PLT
.L87:
	call	__stack_chk_fail@PLT
.L21:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$84, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC8(%rip), %rdi
	call	__assert_fail@PLT
.L7:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$35, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC4(%rip), %rdi
	call	__assert_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	movdqu	(%rsi), %xmm2
	pxor	%xmm1, %xmm1
	movdqu	16(%rsi), %xmm0
	testl	%edi, %edi
	movl	$334, %eax
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm0
	pandn	.LC5(%rip), %xmm0
	cmovne	%eax, %edi
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	32(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	48(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	64(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	80(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	96(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	112(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	128(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	144(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	160(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	176(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	192(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	208(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	224(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm2, %xmm1
	psubd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %eax
	addl	%edi, %eax
	cmpl	$1, %eax
	sete	%al
	movzbl	%al, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.section	.rodata
	.type	__PRETTY_FUNCTION__.0, @object
	.size	__PRETTY_FUNCTION__.0, 5
__PRETTY_FUNCTION__.0:
	.string	"main"
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 8000
ans:
	.zero	8000
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC5:
	.long	1
	.long	1
	.long	1
	.long	1
	.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 %d"
.LC1:
	.string	"/tmp/tmp2jnbhpca/temp.c"
.LC2:
	.string	"n != 0 && p != 0"
.LC3:
	.string	"n > 2"
.LC4:
	.string	"p > 1"
.LC6:
	.string	"p >= 0"
.LC7:
	.string	"sum == sum_st"
.LC8:
	.string	"ans[count-1] < n"
.LC9:
	.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
	movl	$1, %ebx
	subq	$312, %rsp
	.cfi_def_cfa_offset 368
	movq	%fs:40, %rax
	movq	%rax, 296(%rsp)
	xorl	%eax, %eax
	leaq	ans(%rip), %rax
	movl	$-1, 40(%rsp)
	movq	%rax, 24(%rsp)
	movq	%rax, %rbp
	leaq	48(%rsp), %rax
	movq	%rax, 16(%rsp)
	leaq	44(%rsp), %rax
	movq	%rax, 8(%rsp)
	leaq	40(%rsp), %rax
	movl	$-1, 44(%rsp)
	movq	%rax, (%rsp)
.L22:
	movq	16(%rsp), %rdi
	xorl	%eax, %eax
	movl	$30, %ecx
	movq	(%rsp), %rsi
	movq	8(%rsp), %rdx
	leal	-1(%rbx), %r12d
	rep stosq
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %esi
	movdqa	.LC5(%rip), %xmm2
	testl	%esi, %esi
	jne	.L2
	movl	44(%rsp), %eax
	testl	%eax, %eax
	je	.L81
.L3:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$33, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__assert_fail@PLT
	.p2align 4,,10
	.p2align 3
.L2:
	movl	44(%rsp), %r10d
	testl	%r10d, %r10d
	je	.L3
	cmpl	$2, %esi
	jle	.L82
	cmpl	$1, %r10d
	jle	.L7
	movl	%esi, %r12d
	movl	%esi, %edi
	movl	%r10d, %r8d
	movl	$1000002, %r9d
	andl	$-4, %r12d
	shrl	$2, %edi
	xorl	%r14d, %r14d
	xorl	%edx, %edx
	pxor	%xmm1, %xmm1
	movslq	%r12d, %r13
	leal	1(%r12), %r11d
	.p2align 4,,10
	.p2align 3
.L8:
	testl	%r8d, %r8d
	jg	.L83
	je	.L84
	testb	%r14b, %r14b
	je	.L16
	movl	%r8d, 44(%rsp)
.L16:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$54, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC6(%rip), %rdi
	call	__assert_fail@PLT
	.p2align 4,,10
	.p2align 3
.L83:
	movslq	%edx, %rax
	movdqa	%xmm1, %xmm3
	movdqa	%xmm1, %xmm0
	subl	$1, %r8d
	addl	$1, 48(%rsp,%rax,4)
	movl	%r8d, %eax
	negl	%eax
	sbbl	%ecx, %ecx
	andl	$334, %ecx
	pcmpeqd	48(%rsp), %xmm3
	pcmpeqd	64(%rsp), %xmm0
	pcmpeqd	%xmm1, %xmm3
	pandn	%xmm2, %xmm0
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	80(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	96(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	112(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	128(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	144(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	160(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	176(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	192(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	208(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	224(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	240(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	256(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm1, %xmm3
	pcmpeqd	272(%rsp), %xmm3
	pcmpeqd	%xmm1, %xmm3
	psubd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$8, %xmm3
	paddd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$4, %xmm3
	paddd	%xmm3, %xmm0
	movd	%xmm0, %eax
	addl	%ecx, %eax
	cmpl	$1, %eax
	je	.L11
.L79:
	movl	$1, %r14d
.L12:
	cmpl	$3, %esi
	je	.L85
	movdqa	48(%rsp), %xmm0
	cmpl	$1, %edi
	jbe	.L14
	paddd	64(%rsp), %xmm0
	cmpl	$2, %edi
	je	.L14
	paddd	80(%rsp), %xmm0
	cmpl	$3, %edi
	je	.L14
	paddd	96(%rsp), %xmm0
	cmpl	$4, %edi
	je	.L14
	paddd	112(%rsp), %xmm0
	cmpl	$5, %edi
	je	.L14
	paddd	128(%rsp), %xmm0
	cmpl	$6, %edi
	je	.L14
	paddd	144(%rsp), %xmm0
	cmpl	$7, %edi
	je	.L14
	paddd	160(%rsp), %xmm0
	cmpl	$8, %edi
	je	.L14
	paddd	176(%rsp), %xmm0
	cmpl	$9, %edi
	je	.L14
	paddd	192(%rsp), %xmm0
	cmpl	$10, %edi
	je	.L14
	paddd	208(%rsp), %xmm0
	cmpl	$11, %edi
	je	.L14
	paddd	224(%rsp), %xmm0
	cmpl	$12, %edi
	je	.L14
	paddd	240(%rsp), %xmm0
	cmpl	$13, %edi
	je	.L14
	paddd	256(%rsp), %xmm0
	cmpl	$14, %edi
	je	.L14
	paddd	272(%rsp), %xmm0
	.p2align 4,,10
	.p2align 3
.L14:
	movdqa	%xmm0, %xmm3
	psrldq	$8, %xmm3
	paddd	%xmm3, %xmm0
	movdqa	%xmm0, %xmm3
	psrldq	$4, %xmm3
	paddd	%xmm3, %xmm0
	movd	%xmm0, %ecx
	addl	%r8d, %ecx
	cmpl	%r12d, %esi
	je	.L17
	addl	48(%rsp,%r13,4), %ecx
	movl	%r11d, %r15d
	cmpl	%r11d, %esi
	jle	.L17
.L28:
	movslq	%r15d, %rax
	addl	$1, %r15d
	addl	48(%rsp,%rax,4), %ecx
	cmpl	%r15d, %esi
	jle	.L17
	movslq	%r15d, %r15
	addl	48(%rsp,%r15,4), %ecx
.L17:
	cmpl	%ecx, %r10d
	jne	.L86
	subl	$1, %r9d
	je	.L20
	leal	1(%rdx), %eax
	cltd
	idivl	%esi
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L84:
	movslq	%edx, %rcx
	movl	48(%rsp,%rcx,4), %eax
	testl	%eax, %eax
	jle	.L12
	movl	$0, 48(%rsp,%rcx,4)
	movl	%eax, %r8d
	jmp	.L79
.L11:
	movl	%r8d, 44(%rsp)
	movl	%edx, 0(%rbp)
	cmpl	%edx, %esi
	jle	.L21
.L26:
	addl	$1, %ebx
	addq	$4, %rbp
	jmp	.L22
.L85:
	movl	48(%rsp), %ecx
	movl	$1, %r15d
	addl	%r8d, %ecx
	jmp	.L28
.L20:
	testb	%r14b, %r14b
	je	.L25
	movl	%r8d, 44(%rsp)
.L25:
	movl	$0, 0(%rbp)
	jmp	.L26
.L81:
	testl	%r12d, %r12d
	je	.L24
	leal	-2(%rbx), %edx
	leaq	4+ans(%rip), %rax
	movq	24(%rsp), %r12
	leaq	(%rax,%rdx,4), %rbp
	leaq	.LC9(%rip), %rbx
.L23:
	movl	(%r12), %edx
	movq	%rbx, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %r12
	call	__printf_chk@PLT
	cmpq	%rbp, %r12
	jne	.L23
.L24:
	movq	296(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L87
	addq	$312, %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
.L86:
	.cfi_restore_state
	testb	%r14b, %r14b
	je	.L19
	movl	%r8d, 44(%rsp)
.L19:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$66, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC7(%rip), %rdi
	call	__assert_fail@PLT
.L82:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$34, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC3(%rip), %rdi
	call	__assert_fail@PLT
.L87:
	call	__stack_chk_fail@PLT
.L21:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$84, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC8(%rip), %rdi
	call	__assert_fail@PLT
.L7:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rcx
	movl	$35, %edx
	leaq	.LC1(%rip), %rsi
	leaq	.LC4(%rip), %rdi
	call	__assert_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	movdqu	(%rsi), %xmm2
	pxor	%xmm1, %xmm1
	movdqu	16(%rsi), %xmm0
	testl	%edi, %edi
	movl	$334, %eax
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm0
	pandn	.LC5(%rip), %xmm0
	cmovne	%eax, %edi
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	32(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	48(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	64(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	80(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	96(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	112(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	128(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	144(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	160(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	176(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	192(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	208(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm1, %xmm2
	psubd	%xmm2, %xmm0
	movdqu	224(%rsi), %xmm2
	pcmpeqd	%xmm1, %xmm2
	pcmpeqd	%xmm2, %xmm1
	psubd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %eax
	addl	%edi, %eax
	cmpl	$1, %eax
	sete	%al
	movzbl	%al, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.section	.rodata
	.type	__PRETTY_FUNCTION__.0, @object
	.size	__PRETTY_FUNCTION__.0, 5
__PRETTY_FUNCTION__.0:
	.string	"main"
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 8000
ans:
	.zero	8000
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC5:
	.long	1
	.long	1
	.long	1
	.long	1
	.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<assert.h>

#define  N_MAX  60

int ans[2000];

/* ???????????????????¢????????????? */
int check(int p, int s[N_MAX]);

int main(void){

  int n = -1, p = -1;
  int st_num[N_MAX];
  int count = 0;
  int sum_st;
  int kill = 0;
  int i, j;
  
  while(1){

    /* ????????? */
    for(j = 0; j < 60; j++) {
      st_num[j] = 0;
    }
    i = 0;
    kill = 0;
    
    scanf("%d %d", &n, &p);

    if(n == 0 && p == 0) break;

    assert(n != 0 && p != 0);
    assert(n > 2);
    assert(p > 1);

    sum_st = p;
    
    while(1){

      if(p > 0){
	p--;
	st_num[i]++;
	
	/* ???????¢???? */
	if(check(p, st_num) != 0) break;
		
      }
      else if(p == 0 && st_num[i] > 0){
	p = st_num[i];
	st_num[i] = 0;
      }

      assert(p >= 0);

      /* ???????????? */
      //printf("p = %d ", p);
      //printf("st_num[%d] = %d ", i, st_num[i]);
      //printf("kill = %d\n", kill);

      int sum = p;      
      for(j = 0; j < n; j++){
	sum = sum + st_num[j];
      }
      //printf("sum = %d\n", sum);
      assert(sum == sum_st);
      
      /* ???????????¢?????? */
      if(kill > 1000000){
	i = 0;
	break;
      }
      
      i++;
      i = i % n;	

      kill++;
    }

    assert(count >= 0);

    ans[count++] = i;

    assert(ans[count-1] < n);

    /* ???????????? */
    //printf("test2\n");
  }

  /* ??????????????? */
  for(i = 0; i < count; i++){
    printf("%d\n", ans[i]);
  }
  
  return 0;
}

int check(int p, int s[N_MAX]){

  int flag = 0;
  int i;

  if(p != 0)
    flag = 334;
  
  for(i = 0; i < N_MAX; i++){
    if(s[i] != 0){
      flag++;
    }
  }
  
  if(flag == 1)
    return 1;
  else
    return 0;
}
3 2
3 3
3 50
10 29
57 32
50 2
50 50
0 0
 3 2
3 3
4 50
10 29
57 32
50 2
50 50
0 0

1
0
1
5
31
1
13
 1
0
3
5
31
1
13

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<assert.h>

#define  N_MAX  60

int ans[2000];

/* ???????????????????¢????????????? */
int check(int p, int s[N_MAX]);

int main(void){

  int n = -1, p = -1;
  int st_num[N_MAX];
  int count = 0;
  int sum_st;
  int kill = 0;
  int i, j;
  
  while(1){

    /* ????????? */
    for(j = 0; j < 60; j++) {
      st_num[j] = 0;
    }
    i = 0;
    kill = 0;
    
    scanf("%d %d", &n, &p);

    if(n == 0 && p == 0) break;

    assert(n != 0 && p != 0);
    assert(n > 2);
    assert(p > 1);

    sum_st = p;
    
    while(1){

      if(p > 0){
	p--;
	st_num[i]++;
	
	/* ???????¢???? */
	if(check(p, st_num) != 0) break;
		
      }
      else if(p == 0 && st_num[i] > 0){
	p = st_num[i];
	st_num[i] = 0;
      }

      assert(p >= 0);

      /* ???????????? */
      //printf("p = %d ", p);
      //printf("st_num[%d] = %d ", i, st_num[i]);
      //printf("kill = %d\n", kill);

      int sum = p;      
      for(j = 0; j < n; j++){
	sum = sum + st_num[j];
      }
      //printf("sum = %d\n", sum);
      assert(sum == sum_st);
      
      /* ???????????¢?????? */
      if(kill > 1000000){
	i = 0;
	break;
      }
      
      i++;
      i = i % n;	

      kill++;
    }

    assert(count >= 0);

    ans[count++] = i;

    assert(ans[count-1] < n);

    /* ???????????? */
    //printf("test2\n");
  }

  /* ??????????????? */
  for(i = 0; i < count; i++){
    printf("%d\n", ans[i]);
  }
  
  return 0;
}

int check(int p, int s[N_MAX]){

  int flag = 0;
  int i;

  if(p != 0)
    flag = 334;
  
  for(i = 0; i < N_MAX; i++){
    if(s[i] != 0){
      flag++;
    }
  }
  
  if(flag == 1)
    return 1;
  else
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 8000
ans:
	.zero	8000
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"/tmp/tmp2jnbhpca/temp.c"
.LC2:
	.string	"n != 0 && p != 0"
.LC3:
	.string	"n > 2"
.LC4:
	.string	"p > 1"
.LC5:
	.string	"p >= 0"
.LC6:
	.string	"sum == sum_st"
.LC7:
	.string	"count >= 0"
.LC8:
	.string	"ans[count-1] < n"
.LC9:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$288, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$-1, -288(%rbp)
	movl	$-1, -284(%rbp)
	movl	$0, -280(%rbp)
	movl	$0, -276(%rbp)
.L21:
	movl	$0, -268(%rbp)
	jmp	.L2
.L3:
	movl	-268(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
	addl	$1, -268(%rbp)
.L2:
	cmpl	$59, -268(%rbp)
	jle	.L3
	movl	$0, -272(%rbp)
	movl	$0, -276(%rbp)
	leaq	-284(%rbp), %rdx
	leaq	-288(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	je	.L28
.L4:
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	je	.L6
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L27
.L6:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$33, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L27:
	movl	-288(%rbp), %eax
	cmpl	$2, %eax
	jg	.L8
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$34, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L8:
	movl	-284(%rbp), %eax
	cmpl	$1, %eax
	jg	.L9
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$35, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L9:
	movl	-284(%rbp), %eax
	movl	%eax, -260(%rbp)
.L18:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jle	.L10
	movl	-284(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-272(%rbp), %eax
	cltq
	movl	%edx, -256(%rbp,%rax,4)
	movl	-284(%rbp), %eax
	leaq	-256(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	check
	testl	%eax, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
.L11:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jns	.L13
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$54, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L13:
	movl	-284(%rbp), %eax
	movl	%eax, -264(%rbp)
	movl	$0, -268(%rbp)
	jmp	.L14
.L15:
	movl	-268(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	addl	%eax, -264(%rbp)
	addl	$1, -268(%rbp)
.L14:
	movl	-288(%rbp), %eax
	cmpl	%eax, -268(%rbp)
	jl	.L15
	movl	-264(%rbp), %eax
	cmpl	-260(%rbp), %eax
	je	.L16
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$66, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC6(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L16:
	cmpl	$1000000, -276(%rbp)
	jle	.L17
	movl	$0, -272(%rbp)
	jmp	.L12
.L17:
	addl	$1, -272(%rbp)
	movl	-288(%rbp), %ecx
	movl	-272(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, -272(%rbp)
	addl	$1, -276(%rbp)
	jmp	.L18
.L12:
	cmpl	$0, -280(%rbp)
	jns	.L19
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$80, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC7(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L19:
	movl	-280(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -280(%rbp)
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ans(%rip), %rdx
	movl	-272(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-280(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-288(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L21
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$84, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC8(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L28:
	nop
	movl	$0, -272(%rbp)
	jmp	.L22
.L23:
	movl	-272(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC9(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -272(%rbp)
.L22:
	movl	-272(%rbp), %eax
	cmpl	-280(%rbp), %eax
	jl	.L23
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	check
	.type	check, @function
check:
.LFB1:
	.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)
	movq	%rsi, -32(%rbp)
	movl	$0, -8(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L30
	movl	$334, -8(%rbp)
.L30:
	movl	$0, -4(%rbp)
	jmp	.L31
.L33:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L32
	addl	$1, -8(%rbp)
.L32:
	addl	$1, -4(%rbp)
.L31:
	cmpl	$59, -4(%rbp)
	jle	.L33
	cmpl	$1, -8(%rbp)
	jne	.L34
	movl	$1, %eax
	jmp	.L35
.L34:
	movl	$0, %eax
.L35:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
	.type	__PRETTY_FUNCTION__.0, @object
	.size	__PRETTY_FUNCTION__.0, 5
__PRETTY_FUNCTION__.0:
	.string	"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.
val
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 8000
ans:
	.zero	8000
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"/tmp/tmp2jnbhpca/temp.c"
.LC2:
	.string	"n != 0 && p != 0"
.LC3:
	.string	"n > 2"
.LC4:
	.string	"p > 1"
.LC5:
	.string	"p >= 0"
.LC6:
	.string	"sum == sum_st"
.LC7:
	.string	"count >= 0"
.LC8:
	.string	"ans[count-1] < n"
.LC9:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$288, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$-1, -288(%rbp)
	movl	$-1, -284(%rbp)
	movl	$0, -280(%rbp)
	movl	$0, -276(%rbp)
.L21:
	movl	$0, -268(%rbp)
	jmp	.L2
.L3:
	movl	-268(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
	addl	$1, -268(%rbp)
.L2:
	cmpl	$59, -268(%rbp)
	jle	.L3
	movl	$0, -272(%rbp)
	movl	$0, -276(%rbp)
	leaq	-284(%rbp), %rdx
	leaq	-288(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	je	.L28
.L4:
	movl	-288(%rbp), %eax
	testl	%eax, %eax
	je	.L6
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L27
.L6:
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$33, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L27:
	movl	-288(%rbp), %eax
	cmpl	$2, %eax
	jg	.L8
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$34, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L8:
	movl	-284(%rbp), %eax
	cmpl	$1, %eax
	jg	.L9
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$35, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L9:
	movl	-284(%rbp), %eax
	movl	%eax, -260(%rbp)
.L18:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jle	.L10
	movl	-284(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	leal	1(%rax), %edx
	movl	-272(%rbp), %eax
	cltq
	movl	%edx, -256(%rbp,%rax,4)
	movl	-284(%rbp), %eax
	leaq	-256(%rbp), %rdx
	movq	%rdx, %rsi
	movl	%eax, %edi
	call	check
	testl	%eax, %eax
	je	.L11
	jmp	.L12
.L10:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L11
	movl	-272(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	movl	%eax, -284(%rbp)
	movl	-272(%rbp), %eax
	cltq
	movl	$0, -256(%rbp,%rax,4)
.L11:
	movl	-284(%rbp), %eax
	testl	%eax, %eax
	jns	.L13
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$54, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L13:
	movl	-284(%rbp), %eax
	movl	%eax, -264(%rbp)
	movl	$0, -268(%rbp)
	jmp	.L14
.L15:
	movl	-268(%rbp), %eax
	cltq
	movl	-256(%rbp,%rax,4), %eax
	addl	%eax, -264(%rbp)
	addl	$1, -268(%rbp)
.L14:
	movl	-288(%rbp), %eax
	cmpl	%eax, -268(%rbp)
	jl	.L15
	movl	-264(%rbp), %eax
	cmpl	-260(%rbp), %eax
	je	.L16
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$66, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC6(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L16:
	cmpl	$1000000, -276(%rbp)
	jle	.L17
	movl	$0, -272(%rbp)
	jmp	.L12
.L17:
	addl	$1, -272(%rbp)
	movl	-288(%rbp), %ecx
	movl	-272(%rbp), %eax
	cltd
	idivl	%ecx
	movl	%edx, -272(%rbp)
	addl	$1, -276(%rbp)
	jmp	.L18
.L12:
	cmpl	$0, -280(%rbp)
	jns	.L19
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$80, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC7(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L19:
	movl	-280(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -280(%rbp)
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ans(%rip), %rdx
	movl	-272(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-280(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-288(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L21
	leaq	__PRETTY_FUNCTION__.0(%rip), %rax
	movq	%rax, %rcx
	movl	$84, %edx
	leaq	.LC1(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC8(%rip), %rax
	movq	%rax, %rdi
	call	__assert_fail@PLT
.L28:
	nop
	movl	$0, -272(%rbp)
	jmp	.L22
.L23:
	movl	-272(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC9(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -272(%rbp)
.L22:
	movl	-272(%rbp), %eax
	cmpl	-280(%rbp), %eax
	jl	.L23
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	check
	.type	check, @function
check:
.LFB1:
	.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)
	movq	%rsi, -32(%rbp)
	movl	$0, -8(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L30
	movl	$334, -8(%rbp)
.L30:
	movl	$0, -4(%rbp)
	jmp	.L31
.L33:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L32
	addl	$1, -8(%rbp)
.L32:
	addl	$1, -4(%rbp)
.L31:
	cmpl	$59, -4(%rbp)
	jle	.L33
	cmpl	$1, -8(%rbp)
	jne	.L34
	movl	$1, %eax
	jmp	.L35
.L34:
	movl	$0, %eax
.L35:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
	.type	__PRETTY_FUNCTION__.0, @object
	.size	__PRETTY_FUNCTION__.0, 5
__PRETTY_FUNCTION__.0:
	.string	"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:
