user: Please show me the C implementation that matches the assembly code listed below:

```asm
<bot>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  cmp    $0x1,%esi
  je     L965
  cmp    $0xffffffff,%esi
  je     L1583
L1156:
  pop    %rbx
  mov    %r15d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L1583:
  lea    0x1c(%rdi),%rax
  movl   $0x0,-0x44(%rsp)
  mov    %rax,-0x8(%rsp)
L1282:
  mov    $0x3,%r9d
  mov    $0x2,%r15d
  xor    %r13d,%r13d
  mov    $0xfffffffd,%ebp
  mov    $0xfffffffe,%r11d
  mov    $0xffffffff,%r12d
  mov    $0x1,%ebx
L1384:
  movslq -0x44(%rsp),%rdx
  mov    %r13d,-0x2c(%rsp)
  lea    0x0(,%r13,4),%r10
  lea    0x0(,%rdx,8),%rax
  sub    %rdx,%rax
  shl    $0x2,%rax
  lea    (%r14,%rax,1),%rdx
  mov    %rax,-0x40(%rsp)
  mov    (%rdx,%r13,4),%ecx
  cmp    $0xffffffff,%ecx
  je     L270
  cmp    $0x1,%ecx
  jne    L1249
  lea    0x1c(%r14,%rax,1),%rsi
  cmpl   $0x1,(%rsi,%r10,1)
  je     L529
L1621:
  mov    %ebx,%edi
  cmpl   $0x1,(%rdx,%rdi,4)
  je     L1862
L2005:
  cmpl   $0x1,(%rsi,%rdi,4)
  je     L970
L200:
  lea    -0x1c(%r14,%rax,1),%rdx
  movslq %r12d,%rcx
  cmpl   $0x1,(%rdx,%rcx,4)
  je     L711
L401:
  cmpl   $0x1,(%rdx,%rdi,4)
  je     L579
L669:
  cmpl   $0x1,(%rsi,%rcx,4)
  je     L2086
L1249:
  add    $0x1,%r13
  add    $0x1,%ebx
  add    $0x1,%r12d
  add    $0x1,%r11d
  add    $0x1,%ebp
  add    $0x1,%r15d
  add    $0x1,%r9d
  cmp    $0x7,%r13
  jne    L1384
  addl   $0x1,-0x44(%rsp)
  mov    -0x44(%rsp),%eax
  cmp    $0x5,%eax
  jle    L1282
  mov    (%r14),%r15d
  test   %r15d,%r15d
  jne    L1801
  jmp    L1156
  nopl   (%rax)
L270:
  lea    0x1c(%rax),%rdi
  lea    (%r14,%rdi,1),%rcx
  mov    %rdi,-0x28(%rsp)
  mov    (%rcx,%r13,4),%esi
  mov    %rcx,-0x38(%rsp)
  mov    %esi,-0x18(%rsp)
  cmp    $0xffffffff,%esi
  je     L941
L1355:
  mov    %ebx,%r8d
  mov    (%rdx,%r8,4),%ecx
  mov    %ecx,-0x10(%rsp)
  cmp    $0xffffffff,%ecx
  je     L708
L1790:
  mov    -0x38(%rsp),%rsi
  mov    (%rsi,%r8,4),%esi
  mov    %esi,-0xc(%rsp)
  cmp    $0xffffffff,%esi
  je     L2148
L1211:
  lea    -0x1c(%r14,%rax,1),%rsi
  movslq %r12d,%rcx
  mov    (%rsi,%rcx,4),%edi
  mov    %edi,-0x20(%rsp)
  cmp    $0xffffffff,%edi
  je     L585
L1746:
  cmpl   $0xffffffff,(%rsi,%r8,4)
  je     L1859
L1604:
  mov    -0x38(%rsp),%rdi
  cmpl   $0xffffffff,(%rdi,%rcx,4)
  je     L1781
L247:
  cmpl   $0xffffffff,-0x18(%rsp)
  je     L1875
L1380:
  cmpl   $0xffffffff,-0x10(%rsp)
  je     L1423
L889:
  cmpl   $0xffffffff,-0xc(%rsp)
  je     L1571
  cmpl   $0xffffffff,-0x20(%rsp)
  je     L2115
L875:
  movslq %ebx,%rax
  cmpl   $0xffffffff,(%rsi,%rax,4)
  je     L1528
L545:
  mov    -0x28(%rsp),%rdi
  lea    (%r14,%rcx,4),%rax
  cmpl   $0xffffffff,(%rax,%rdi,1)
  jne    L1249
  mov    -0x40(%rsp),%rcx
  movslq %r11d,%rax
  mov    %r11d,-0x30(%rsp)
  lea    (%r14,%rax,4),%rax
  mov    0x38(%rcx,%rax,1),%edi
  test   %edi,%edi
  jne    L1249
  cmpl   $0x3,-0x44(%rsp)
  jg     L1249
  cmp    $0x1,%r13d
  jle    L1249
L1407:
  mov    %r11d,%r15d
  jmp    L1156
  nopl   (%rax)
L965:
  movl   $0x0,-0x44(%rsp)
  lea    -0x1c(%rdi),%rbp
  mov    %rdi,-0x18(%rsp)
L1415:
  lea    -0x38(%rbp),%rax
  lea    0x54(%rbp),%rcx
  mov    $0x3,%r14d
  xor    %r13d,%r13d
  mov    %rax,-0x28(%rsp)
  lea    0x1c(%rbp),%rax
  lea    0x70(%rbp),%rdi
  mov    $0xfffffffd,%r12d
  mov    %rax,-0x20(%rsp)
  lea    0x38(%rbp),%rdx
  lea    -0x14(%rbp),%rsi
L542:
  mov    (%rax),%r9d
  mov    %r13d,%r8d
  mov    %r13d,%r10d
  cmp    $0x1,%r9d
  je     L940
  cmp    $0xffffffff,%r9d
  jne    L1592
  cmpl   $0xffffffff,(%rdx)
  je     L445
L1992:
  cmpl   $0xffffffff,0x4(%rax)
  je     L372
L1445:
  cmpl   $0xffffffff,0x4(%rdx)
  je     L1439
L905:
  cmpl   $0xffffffff,-0x4(%rbp,%r13,4)
  je     L379
L1100:
  cmpl   $0xffffffff,0x4(%rbp,%r13,4)
  je     L957
L491:
  cmpl   $0xffffffff,-0x4(%rdx)
  je     L50
L1592:
  add    $0x1,%r13
  add    $0x4,%rax
  add    $0x4,%rcx
  add    $0x4,%rdi
  add    $0x1,%r12d
  add    $0x4,%rdx
  add    $0x4,%rsi
  add    $0x1,%r14d
  cmp    $0x7,%r13
  jne    L542
  addl   $0x1,-0x44(%rsp)
  mov    -0x44(%rsp),%eax
  cmp    $0x6,%eax
  je     L802
  mov    -0x20(%rsp),%rbp
  jmp    L1415
  nopl   0x0(%rax)
L940:
  mov    (%rdx),%ebx
  cmp    $0x1,%ebx
  je     L1203
L1966:
  mov    0x4(%rax),%r9d
  cmp    $0x1,%r9d
  je     L1476
L1842:
  mov    0x4(%rdx),%r11d
  mov    %r11d,-0x40(%rsp)
  cmp    $0x1,%r11d
  je     L460
L1277:
  mov    -0x4(%rbp,%r13,4),%r15d
  mov    %r15d,-0x30(%rsp)
  cmp    $0x1,%r15d
  je     L2116
L317:
  mov    0x4(%rbp,%r13,4),%r15d
  mov    %r15d,-0x38(%rsp)
  cmp    $0x1,%r15d
  je     L497
L1719:
  mov    -0x4(%rdx),%r15d
  mov    %r15d,-0x2c(%rsp)
  cmp    $0x1,%r15d
  je     L640
L1398:
  cmp    $0x1,%ebx
  je     L1052
L373:
  cmp    $0x1,%r9d
  je     L1686
L1905:
  cmpl   $0x1,-0x40(%rsp)
  je     L327
L1296:
  cmpl   $0x1,-0x30(%rsp)
  je     L1252
L488:
  cmpl   $0x1,-0x38(%rsp)
  je     L544
L648:
  cmpl   $0x1,-0x2c(%rsp)
  jne    L1592
  lea    -0x2(%r8),%r15d
  mov    -0x8(%rcx),%r8d
  test   %r8d,%r8d
  jne    L1592
  cmpl   $0x3,-0x44(%rsp)
  jg     L1592
  cmp    $0x1,%r13d
  jle    L1592
  jmp    L1156
  nopl   0x0(%rax)
L1203:
  cmpl   $0x1,(%rcx)
  jne    L1966
  mov    (%rdi),%r15d
  test   %r15d,%r15d
  jne    L1966
  cmpl   $0x2,-0x44(%rsp)
  jg     L1966
L1828:
  mov    %r13d,%r15d
  jmp    L1156
L1476:
  cmpl   $0x1,0x8(%rax)
  jne    L1842
  mov    0xc(%rax),%r11d
  mov    %r14d,%r15d
  test   %r11d,%r11d
  jne    L1842
  cmp    $0x3,%r13d
  jle    L1156
  jmp    L1842
  nopl   0x0(%rax)
L460:
  cmpl   $0x1,0x8(%rcx)
  jne    L1277
  mov    0xc(%rdi),%r11d
  mov    %r14d,%r15d
  test   %r11d,%r11d
  jne    L1277
  cmpl   $0x2,-0x44(%rsp)
  jg     L1277
  cmp    $0x3,%r13d
  jg     L1277
  jmp    L1156
  nopl   0x0(%rax)
L2116:
  cmpl   $0x1,-0x10(%rsi)
  jne    L317
  mov    -0x28(%rsp),%r11
  mov    %r12d,%r15d
  mov    -0xc(%r11,%r13,4),%r11d
  test   %r11d,%r11d
  jne    L317
  cmpl   $0x2,-0x44(%rsp)
  jle    L317
  cmp    $0x2,%r13d
  jle    L317
  jmp    L1156
  nopw   0x0(%rax,%rax,1)
L497:
  cmpl   $0x1,(%rsi)
  jne    L1719
  mov    -0x28(%rsp),%r11
  mov    %r14d,%r15d
  mov    0xc(%r11,%r13,4),%r11d
  test   %r11d,%r11d
  jne    L1719
  cmpl   $0x2,-0x44(%rsp)
  jle    L1719
  cmp    $0x3,%r13d
  jg     L1719
  jmp    L1156
  nopl   0x0(%rax)
L640:
  cmpl   $0x1,-0x8(%rcx)
  jne    L1398
  mov    -0xc(%rdi),%r11d
  mov    %r12d,%r15d
  test   %r11d,%r11d
  jne    L1398
  cmpl   $0x2,-0x44(%rsp)
  jg     L1398
  cmp    $0x2,%r13d
  jle    L1398
  jmp    L1156
  nopl   0x0(%rax)
L445:
  cmpl   $0xffffffff,(%rcx)
  jne    L1992
  mov    (%rdi),%r15d
  test   %r15d,%r15d
  jne    L1992
  cmpl   $0x2,-0x44(%rsp)
  jg     L1992
  jmp    L1828
  nopl   (%rax)
L372:
  cmpl   $0xffffffff,0x8(%rax)
  jne    L1445
  mov    0xc(%rax),%ebx
  mov    %r14d,%r15d
  test   %ebx,%ebx
  jne    L1445
  cmp    $0x3,%r13d
  jle    L1156
  jmp    L1445
  nop
L1439:
  cmpl   $0xffffffff,0x8(%rcx)
  jne    L905
  mov    0xc(%rdi),%r11d
  mov    %r14d,%r15d
  test   %r11d,%r11d
  jne    L905
  cmpl   $0x2,-0x44(%rsp)
  jg     L905
  cmp    $0x3,%r13d
  jg     L905
  jmp    L1156
  nopl   0x0(%rax)
L379:
  cmpl   $0xffffffff,-0x10(%rsi)
  jne    L1100
  mov    -0x28(%rsp),%rbx
  mov    %r12d,%r15d
  mov    -0xc(%rbx,%r13,4),%r10d
  test   %r10d,%r10d
  jne    L1100
  cmpl   $0x2,-0x44(%rsp)
  jle    L1100
  cmp    $0x2,%r13d
  jle    L1100
  jmp    L1156
  nopw   0x0(%rax,%rax,1)
L50:
  cmpl   $0xffffffff,-0x8(%rcx)
  jne    L1592
  mov    -0xc(%rdi),%r8d
  mov    %r12d,%r15d
  test   %r8d,%r8d
  jne    L1592
  cmpl   $0x2,-0x44(%rsp)
  jg     L1592
  cmp    $0x2,%r13d
  jle    L1592
  jmp    L1156
  nopl   0x0(%rax)
L957:
  cmpl   $0xffffffff,(%rsi)
  jne    L491
  mov    -0x28(%rsp),%rbx
  mov    %r14d,%r15d
  mov    0xc(%rbx,%r13,4),%r9d
  test   %r9d,%r9d
  jne    L491
  cmpl   $0x2,-0x44(%rsp)
  jle    L491
  cmp    $0x3,%r13d
  jg     L491
  jmp    L1156
  nopl   0x0(%rax)
L1052:
  mov    (%rcx),%r15d
  test   %r15d,%r15d
  jne    L373
  cmpl   $0x3,-0x44(%rsp)
  jg     L373
  mov    %r10d,%r15d
  jmp    L1156
  nop
L1686:
  mov    0x8(%rax),%ebx
  lea    0x2(%r8),%r15d
  test   %ebx,%ebx
  jne    L1905
  cmp    $0x4,%r13d
  jg     L1905
  pop    %rbx
  mov    %r15d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L327:
  mov    0x8(%rcx),%r11d
  lea    0x2(%r8),%r15d
  test   %r11d,%r11d
  jne    L1296
  cmpl   $0x3,-0x44(%rsp)
  jg     L1296
  cmp    $0x4,%r13d
  jg     L1296
  jmp    L1156
  nopl   0x0(%rax,%rax,1)
L1252:
  mov    -0x10(%rsi),%r10d
  lea    -0x2(%r8),%r15d
  test   %r10d,%r10d
  jne    L488
  cmp    $0x1,%r13d
  jle    L488
  cmpl   $0x1,-0x44(%rsp)
  jle    L488
  jmp    L1156
  nopl   0x0(%rax,%rax,1)
L544:
  mov    (%rsi),%r9d
  lea    0x2(%r8),%r15d
  test   %r9d,%r9d
  jne    L648
  cmpl   $0x1,-0x44(%rsp)
  jle    L648
  cmp    $0x4,%r13d
  jg     L648
  jmp    L1156
  nopw   0x0(%rax,%rax,1)
L708:
  movslq %r15d,%rcx
  cmpl   $0xffffffff,(%rdx,%rcx,4)
  jne    L1790
  movslq %r9d,%rcx
  mov    %r9d,-0x30(%rsp)
  mov    (%rdx,%rcx,4),%esi
  test   %esi,%esi
  jne    L1790
  cmp    $0x3,%r13d
  jg     L1790
L1275:
  mov    %r9d,%r15d
  jmp    L1156
  nopw   0x0(%rax,%rax,1)
L941:
  lea    (%rdx,%r10,1),%rcx
  cmpl   $0xffffffff,0x38(%rcx)
  jne    L1355
  mov    0x54(%rcx),%edi
  test   %edi,%edi
  jne    L1355
  cmpl   $0x2,-0x44(%rsp)
  jg     L1355
  jmp    L1828
  nopl   0x0(%rax)
L1781:
  movslq %r11d,%rdi
  lea    (%r14,%rdi,4),%rdi
  cmpl   $0xffffffff,0x38(%rax,%rdi,1)
  jne    L247
  movslq %ebp,%rdi
  mov    %ebp,-0x30(%rsp)
  lea    (%r14,%rdi,4),%rdi
  mov    0x54(%rax,%rdi,1),%edi
  test   %edi,%edi
  jne    L247
  cmpl   $0x2,-0x44(%rsp)
  jg     L247
  cmp    $0x2,%r13d
  jle    L247
L576:
  mov    %ebp,%r15d
  jmp    L1156
  xchg   %ax,%ax
L1859:
  movslq %r15d,%r8
  lea    (%r14,%r8,4),%r8
  cmpl   $0xffffffff,-0x38(%rax,%r8,1)
  jne    L1604
  movslq %r9d,%r8
  mov    %r9d,-0x30(%rsp)
  lea    (%r14,%r8,4),%r8
  mov    -0x54(%rax,%r8,1),%r8d
  test   %r8d,%r8d
  jne    L1604
  cmpl   $0x2,-0x44(%rsp)
  jle    L1604
  cmp    $0x3,%r13d
  jg     L1604
  jmp    L1731
  nopw   0x0(%rax,%rax,1)
L585:
  movslq %r11d,%rdi
  lea    (%r14,%rdi,4),%rdi
  cmpl   $0xffffffff,-0x38(%rax,%rdi,1)
  jne    L1746
  movslq %ebp,%rdi
  mov    %ebp,-0x30(%rsp)
  lea    (%r14,%rdi,4),%rdi
  mov    -0x54(%rax,%rdi,1),%edi
  test   %edi,%edi
  jne    L1746
  cmpl   $0x2,-0x44(%rsp)
  jle    L1746
  cmp    $0x2,%r13d
  jle    L1746
  jmp    L1731
L2148:
  movslq %r15d,%rcx
  lea    (%r14,%rcx,4),%rcx
  cmpl   $0xffffffff,0x38(%rax,%rcx,1)
  jne    L1211
  movslq %r9d,%rcx
  mov    %r9d,-0x30(%rsp)
  lea    (%r14,%rcx,4),%rcx
  mov    0x54(%rax,%rcx,1),%ecx
  test   %ecx,%ecx
  jne    L1211
  cmpl   $0x2,-0x44(%rsp)
  jg     L1211
  cmp    $0x3,%r13d
  jg     L1211
L1731:
  mov    -0x30(%rsp),%r15d
  jmp    L1156
  nopl   0x0(%rax)
L529:
  lea    (%rdx,%r10,1),%rcx
  cmpl   $0x1,0x38(%rcx)
  jne    L1621
  mov    0x54(%rcx),%ecx
  test   %ecx,%ecx
  jne    L1621
  cmpl   $0x2,-0x44(%rsp)
  jg     L1621
  jmp    L1828
  nopl   0x0(%rax)
L1862:
  movslq %r15d,%rcx
  cmpl   $0x1,(%rdx,%rcx,4)
  jne    L2005
  movslq %r9d,%rcx
  mov    %r9d,-0x30(%rsp)
  mov    (%rdx,%rcx,4),%edx
  test   %edx,%edx
  jne    L2005
  cmp    $0x3,%r13d
  jle    L1275
  jmp    L2005
  nop
L970:
  movslq %r15d,%rdx
  lea    (%r14,%rdx,4),%rdx
  cmpl   $0x1,0x38(%rax,%rdx,1)
  jne    L200
  movslq %r9d,%rdx
  mov    %r9d,-0x30(%rsp)
  lea    (%r14,%rdx,4),%rdx
  mov    0x54(%rax,%rdx,1),%r10d
  test   %r10d,%r10d
  jne    L200
  cmpl   $0x2,-0x44(%rsp)
  jg     L200
  cmp    $0x3,%r13d
  jg     L200
  jmp    L1731
  cs nopw 0x0(%rax,%rax,1)
L2086:
  movslq %r11d,%rdx
  lea    (%r14,%rdx,4),%rdx
  cmpl   $0x1,0x38(%rax,%rdx,1)
  jne    L1249
  movslq %ebp,%rdx
  mov    %ebp,-0x30(%rsp)
  lea    (%r14,%rdx,4),%rdx
  mov    0x54(%rax,%rdx,1),%eax
  test   %eax,%eax
  jne    L1249
  cmpl   $0x2,-0x44(%rsp)
  jg     L1249
  cmp    $0x2,%r13d
  jle    L1249
  jmp    L576
  nopl   0x0(%rax,%rax,1)
L579:
  movslq %r15d,%rdx
  lea    (%r14,%rdx,4),%rdx
  cmpl   $0x1,-0x38(%rax,%rdx,1)
  jne    L669
  movslq %r9d,%rdx
  mov    %r9d,-0x30(%rsp)
  lea    (%r14,%rdx,4),%rdx
  mov    -0x54(%rax,%rdx,1),%edx
  test   %edx,%edx
  jne    L669
  cmpl   $0x2,-0x44(%rsp)
  jle    L669
  cmp    $0x3,%r13d
  jg     L669
  jmp    L1731
  nopl   0x0(%rax)
L711:
  movslq %r11d,%r8
  lea    (%r14,%r8,4),%r8
  cmpl   $0x1,-0x38(%rax,%r8,1)
  jne    L401
  movslq %ebp,%r8
  mov    %ebp,-0x30(%rsp)
  lea    (%r14,%r8,4),%r8
  mov    -0x54(%rax,%r8,1),%r8d
  test   %r8d,%r8d
  jne    L401
  cmpl   $0x2,-0x44(%rsp)
  jle    L401
  cmp    $0x2,%r13d
  jle    L401
  jmp    L1731
  cs nopw 0x0(%rax,%rax,1)
L1875:
  mov    0x38(%r10,%rdx,1),%eax
  test   %eax,%eax
  jne    L1380
  cmpl   $0x3,-0x44(%rsp)
  jg     L1380
  mov    -0x2c(%rsp),%r15d
  jmp    L1156
  nopw   0x0(%rax,%rax,1)
L1423:
  movslq %r15d,%rax
  mov    %r15d,-0x30(%rsp)
  mov    (%rdx,%rax,4),%eax
  test   %eax,%eax
  jne    L889
  cmp    $0x4,%r13d
  jle    L1156
  jmp    L889
  nopw   0x0(%rax,%rax,1)
L1571:
  mov    0x40(%r14,%r13,4),%eax
  mov    %r15d,-0x30(%rsp)
  test   %eax,%eax
  jne    L12
  cmp    $0x4,%r13d
  jle    L1156
L12:
  cmpl   $0xffffffff,0x38(%r14,%r13,4)
  jne    L481
  mov    0x18(%r14,%r13,4),%eax
  mov    -0x8(%rsp),%rsi
  movq   $0x54,-0x28(%rsp)
  movl   $0x2,-0x44(%rsp)
  mov    %eax,-0x20(%rsp)
  cmpl   $0xffffffff,-0x20(%rsp)
  movq   $0x38,-0x40(%rsp)
  jne    L875
L2115:
  mov    -0x40(%rsp),%rdi
  movslq %r11d,%rax
  mov    %r11d,-0x30(%rsp)
  lea    (%r14,%rax,4),%rax
  mov    -0x38(%rdi,%rax,1),%r10d
  test   %r10d,%r10d
  jne    L875
  cmpl   $0x1,-0x44(%rsp)
  jle    L875
  cmp    $0x1,%r13d
  jle    L875
  jmp    L1407
L1528:
  mov    -0x40(%rsp),%rdi
  movslq %r15d,%rax
  mov    %r15d,-0x30(%rsp)
  lea    (%r14,%rax,4),%rax
  mov    -0x38(%rdi,%rax,1),%r8d
  test   %r8d,%r8d
  jne    L545
  cmpl   $0x1,-0x44(%rsp)
  jle    L545
  cmp    $0x4,%r13d
  jg     L545
  jmp    L1156
  nopl   0x0(%rax)
L802:
  mov    -0x18(%rsp),%r14
  mov    (%r14),%r15d
  test   %r15d,%r15d
  je     L1156
L1801:
  mov    0x4(%r14),%esi
  test   %esi,%esi
  je     L800
  mov    0x8(%r14),%ecx
  test   %ecx,%ecx
  je     L1081
  mov    0xc(%r14),%edx
  test   %edx,%edx
  je     L1311
  mov    0x10(%r14),%eax
  test   %eax,%eax
  je     L1263
  cmpl   $0x1,0x14(%r14)
  sbb    %r15d,%r15d
  and    $0x5,%r15d
  jmp    L1156
L800:
  mov    $0x1,%r15d
  jmp    L1156
L1081:
  mov    $0x2,%r15d
  jmp    L1156
L1311:
  mov    $0x3,%r15d
  jmp    L1156
L1263:
  mov    $0x4,%r15d
  jmp    L1156
L481:
  movl   $0x2,-0x44(%rsp)
  jmp    L1249
```

assistant: ```c
int bot(int grid[6][7], int move) {
  int i, j, t;
  if (move == 1) {
    for (i = 0; i < 6; i++) {
      for (j = 0; j < 7; j++) {
        if (grid[i][j] == 1 && grid[i + 1][j] == 1 && grid[i + 2][j] == 1 && grid[i + 3][j] == 0 && i < 3) {
          return j;
        } else if (grid[i][j] == 1 && grid[i][j + 1] == 1 && grid[i][j + 2] == 1 && grid[i][j + 3] == 0 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j + 1] == 1 && grid[i + 2][j + 2] == 1 && grid[i + 3][j + 3] == 0 && i < 3 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i - 1][j - 1] == 1 && grid[i - 2][j - 2] == 1 && grid[i - 3][j - 3] == 0 && i > 2 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == 1 && grid[i - 1][j + 1] == 1 && grid[i - 2][j + 2] == 1 && grid[i - 3][j + 3] == 0 && i > 2 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j - 1] == 1 && grid[i + 2][j - 2] == 1 && grid[i + 3][j - 3] == 0 && i < 3 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j] == -1 && grid[i + 2][j] == -1 && grid[i + 3][j] == 0 && i < 3) {
          return j;
        } else if (grid[i][j] == -1 && grid[i][j + 1] == -1 && grid[i][j + 2] == -1 && grid[i][j + 3] == 0 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j + 1] == -1 && grid[i + 2][j + 2] == -1 && grid[i + 3][j + 3] == 0 && i < 3 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i - 1][j - 1] == -1 && grid[i - 2][j - 2] == -1 && grid[i - 3][j - 3] == 0 && i > 2 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == -1 && grid[i - 1][j + 1] == -1 && grid[i - 2][j + 2] == -1 && grid[i - 3][j + 3] == 0 && i > 2 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j - 1] == -1 && grid[i + 2][j - 2] == -1 && grid[i + 3][j - 3] == 0 && i < 3 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j] == 1 && grid[i + 2][j] == 0 && i < 4) {
          return j;
        } else if (grid[i][j] == 1 && grid[i][j + 1] == 1 && grid[i][j + 2] == 0 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == 1 && grid[i + 1][j + 1] == 1 && grid[i + 2][j + 2] == 0 && i < 4 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == 1 && grid[i - 1][j - 1] == 1 && grid[i - 2][j - 2] == 0 && j > 1 && i > 1) {
          return j - 2;
        } else if (grid[i][j] == 1 && grid[i - 1][j + 1] == 1 && grid[i - 2][j + 2] == 0 && i > 1 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == 1 && grid[i + 1][j - 1] == 1 && grid[i + 2][j - 2] == 0 && i < 4 && j > 1) {
          return j - 2;
        }
      }
    }
    for (t = 0; t < 6; t++)
      if (grid[0][t] == 0)
        return t;
    return 0;
  } else if (move == -1) {
    for (i = 0; i < 6; i++) {
      for (j = 0; j < 7; j++) {
        if (grid[i][j] == -1 && grid[i + 1][j] == -1 && grid[i + 2][j] == -1 && grid[i + 3][j] == 0 && i < 3) {
          return j;
        } else if (grid[i][j] == -1 && grid[i][j + 1] == -1 && grid[i][j + 2] == -1 && grid[i][j + 3] == 0 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j + 1] == -1 && grid[i + 2][j + 2] == -1 && grid[i + 3][j + 3] == 0 && i < 3 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i - 1][j - 1] == -1 && grid[i - 2][j - 2] == -1 && grid[i - 3][j - 3] == 0 && i > 2 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == -1 && grid[i - 1][j + 1] == -1 && grid[i - 2][j + 2] == -1 && grid[i - 3][j + 3] == 0 && i > 2 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j - 1] == -1 && grid[i + 2][j - 2] == -1 && grid[i + 3][j - 3] == 0 && i < 3 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j] == 1 && grid[i + 2][j] == 1 && grid[i + 3][j] == 0 && i < 3) {
          return j;
        } else if (grid[i][j] == 1 && grid[i][j + 1] == 1 && grid[i][j + 2] == 1 && grid[i][j + 3] == 0 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j + 1] == 1 && grid[i + 2][j + 2] == 1 && grid[i + 3][j + 3] == 0 && i < 3 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i - 1][j - 1] == 1 && grid[i - 2][j - 2] == 1 && grid[i - 3][j - 3] == 0 && i > 2 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == 1 && grid[i - 1][j + 1] == 1 && grid[i - 2][j + 2] == 1 && grid[i - 3][j + 3] == 0 && i > 2 && j < 4) {
          return j + 3;
        } else if (grid[i][j] == 1 && grid[i + 1][j - 1] == 1 && grid[i + 2][j - 2] == 1 && grid[i + 3][j - 3] == 0 && i < 3 && j > 2) {
          return j - 3;
        } else if (grid[i][j] == -1 && grid[i + 1][j] == -1 && grid[i + 2][j] == 0 && i < 4) {
          return j;
        } else if (grid[i][j] == -1 && grid[i][j + 1] == -1 && grid[i][j + 2] == 0 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == -1 && grid[i + 1][j + 1] == -1 && grid[i = 2][j + 2] == 0 && i < 4 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == -1 && grid[i - 1][j - 1] == -1 && grid[i - 2][j - 2] == 0 && i > 1 && j > 1) {
          return j - 2;
        } else if (grid[i][j] == -1 && grid[i - 1][j + 1] == -1 && grid[i - 2][j + 2] == 0 && i > 1 && j < 5) {
          return j + 2;
        } else if (grid[i][j] == -1 && grid[i + 1][j - 1] == -1 && grid[i + 2][j - 2] == 0 && i < 4 && j > 1) {
          return j - 2;
        }
      }
    }
    for (t = 0; t < 6; t++)
      if (grid[0][t] == 0)
        return t;
    return 0;
  }
}
```