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

```asm
<selectTrade>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x24(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L24
L119:
  movl   $0x0,-0x1c(%rbp)
  jmp    L133
L300:
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x1c(%rbp),%eax
  cltq
  mov    (%rdx,%rax,4),%ecx
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  neg    %ecx
  mov    -0x1c(%rbp),%eax
  cltq
  mov    %ecx,(%rdx,%rax,4)
  addl   $0x1,-0x1c(%rbp)
L133:
  cmpl   $0x4,-0x1c(%rbp)
  jle    L300
  addl   $0x1,-0x20(%rbp)
L24:
  cmpl   $0x3,-0x20(%rbp)
  jle    L119
  movl   $0x0,-0x20(%rbp)
  jmp    L211
L102:
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    0x14(%rax),%eax
  cmp    $0x3,%eax
  jne    L307
  movl   $0x0,-0x1c(%rbp)
  jmp    L230
L260:
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    0x14(%rax),%edx
  mov    -0x1c(%rbp),%eax
  cltq
  mov    %edx,-0x14(%rbp,%rax,4)
  addl   $0x1,-0x1c(%rbp)
L230:
  mov    -0x1c(%rbp),%eax
  cmp    -0x20(%rbp),%eax
  jl     L260
  mov    -0x20(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x1c(%rbp)
  jmp    L2
L116:
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    -0x1c(%rbp),%edx
  lea    -0x1(%rdx),%ecx
  mov    0x14(%rax),%edx
  movslq %ecx,%rax
  mov    %edx,-0x14(%rbp,%rax,4)
  addl   $0x1,-0x1c(%rbp)
L2:
  cmpl   $0x3,-0x1c(%rbp)
  jle    L116
L307:
  addl   $0x1,-0x20(%rbp)
L211:
  cmpl   $0x3,-0x20(%rbp)
  jle    L102
L261:
  mov    -0x24(%rbp),%eax
  cltq
  mov    -0x14(%rbp,%rax,4),%eax
  test   %eax,%eax
  jle    L137
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L173
  mov    -0x24(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x18(%rbp)
  jmp    L161
L173:
  mov    -0x24(%rbp),%eax
  mov    %eax,-0x18(%rbp)
L161:
  mov    $0x0,%esi
  mov    $0x0,%edi
  call   <trade_up@plt>
  mov    -0x18(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  add    %rax,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rax,%rdx
  mov    -0x3c(%rbp),%eax
  mov    %eax,%esi
  mov    %rdx,%rdi
  call   <setup@plt>
  mov    -0x3c(%rbp),%eax
  mov    %eax,%edi
  call   <data_refresh@plt>
  mov    $0x0,%eax
  call   <trade_refresh@plt>
  mov    $0x0,%edi
  call   <io_printmap@plt>
  mov    $0x0,%eax
  call   <io_printtrade@plt>
  jmp    L64
L137:
  mov    -0x3c(%rbp),%eax
  mov    %eax,%edi
  call   <trade_down@plt>
  mov    $0x0,%edi
  call   <io_printmap@plt>
L64:
  mov    -0x3c(%rbp),%edx
  mov    -0x24(%rbp),%ecx
  lea    -0x14(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <io_selectTrade@plt>
  mov    $0x0,%eax
  call   <io_getkey@plt>
  cmp    $0x74,%eax
  je     L100
  cmp    $0x74,%eax
  jg     L239
  cmp    $0x63,%eax
  je     L258
  cmp    $0x63,%eax
  jg     L239
  cmp    $0x4,%eax
  je     L100
  cmp    $0x4,%eax
  jg     L239
  test   %eax,%eax
  je     L82
  cmp    $0x1,%eax
  je     L208
  jmp    L239
L82:
  mov    -0x24(%rbp),%eax
  add    $0x2,%eax
  movslq %eax,%rdx
  imul   $0x55555556,%rdx,%rdx
  shr    $0x20,%rdx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  mov    %edx,-0x24(%rbp)
  mov    -0x24(%rbp),%ecx
  mov    %ecx,%edx
  add    %edx,%edx
  add    %ecx,%edx
  sub    %edx,%eax
  mov    %eax,-0x24(%rbp)
  jmp    L80
L208:
  mov    -0x24(%rbp),%eax
  add    $0x1,%eax
  movslq %eax,%rdx
  imul   $0x55555556,%rdx,%rdx
  shr    $0x20,%rdx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  mov    %edx,-0x24(%rbp)
  mov    -0x24(%rbp),%ecx
  mov    %ecx,%edx
  add    %edx,%edx
  add    %ecx,%edx
  sub    %edx,%eax
  mov    %eax,-0x24(%rbp)
  jmp    L80
L100:
  mov    -0x24(%rbp),%eax
  cmp    -0x3c(%rbp),%eax
  jl     L50
  addl   $0x1,-0x24(%rbp)
L50:
  mov    -0x24(%rbp),%eax
  jmp    L276
L258:
  mov    $0xffffffff,%eax
  jmp    L276
L239:
  nop
L80:
  mov    -0x3c(%rbp),%eax
  mov    %eax,%edi
  call   <trade_down@plt>
  jmp    L261
L276:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L284
  call   <__stack_chk_fail@plt>
L284:
  leave
  ret
```

assistant: ```c
int selectTrade(int accepted[4][6], int player) {
  int cursor = 0;
  int i, j, accepted2[3];
  for (i = 0; i < 4; i++)
    for (j = 0; j < 5; j++) {
      accepted[i][j] *= -1;
    }
  for (i = 0; i < 4; i++)
    if (accepted[i][5] == 3) {
      for (j = 0; j < i; j++)
        accepted2[j] = accepted[j][5];
      for (j = i + 1; j < 4; j++)
        accepted2[j - 1] = accepted[j][5];
    }
  while (1) {
    if (accepted2[cursor] > 0) {
      int cursplayer;
      if (cursor >= player)
        cursplayer = cursor + 1;
      else
        cursplayer = cursor;
      trade_up(0, 0);
      setup(accepted[cursplayer], player);
      data_refresh(player);
      trade_refresh();
      io_printmap(0);
      io_printtrade();
    } else {
      trade_down(player);
      io_printmap(0);
    }
    io_selectTrade(accepted2, cursor, player);
    switch (io_getkey()) {
    case 0:
      cursor = (cursor + 2) % 3;
      break;
    case 1:
      cursor = (cursor + 1) % 3;
      break;
    case 4:
    case 't':
      if (cursor >= player)
        cursor++;
      return cursor;
      break;
    case 'c':
      return -1;
    default:
      break;
    }
    trade_down(player);
  }
}
```