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

```asm
<ai_roadfromvert>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  xor    %r13d,%r13d
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  mov    %esi,%ebx
  lea    0x1(%rbp),%r14d
  mov    %ebx,%edi
  sub    $0x58,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  lea    0x30(%rsp),%rsi
  mov    %rsi,0x8(%rsp)
  call   <ai_surroundingverts@plt>
  lea    0x4(%rbp),%eax
  mov    %eax,0x18(%rsp)
L75:
  mov    %r14d,%eax
  sar    $0x1f,%eax
  shr    $0x1e,%eax
  lea    (%r14,%rax,1),%r15d
  and    $0x3,%r15d
  sub    %eax,%r15d
  mov    %r15d,%edi
  call   <data_getroadlen@plt>
  cmp    %r13d,%eax
  jg     L27
L16:
  add    $0x1,%r14d
  cmp    0x18(%rsp),%r14d
  jne    L75
  mov    %ebx,%edi
  call   <data_poslegal@plt>
  movl   $0x0,0x20(%rsp)
  mov    %rax,%r8
  xor    %eax,%eax
  test   %r8,%r8
  jne    L41
L139:
  mov    $0x4,%edx
  mov    0x8(%rsp),%r15
  mov    %ebp,0x1c(%rsp)
  lea    0x3c(%rsp),%r14
  cmp    %edx,%r13d
  movl   $0x0,0x8(%rsp)
  cmovge %r13d,%edx
  movl   $0x0,0x18(%rsp)
  mov    %edx,0x24(%rsp)
  mov    $0x5,%edx
  sub    %eax,%edx
  mov    %edx,0x28(%rsp)
L90:
  mov    (%r15),%esi
  mov    %ebx,%edi
  call   <road_freeedge@plt>
  test   %rax,%rax
  jne    L165
L69:
  add    $0x4,%r15
  cmp    %r15,%r14
  jne    L90
  mov    0x8(%rsp),%eax
  mov    %eax,(%r12)
  mov    0x18(%rsp),%eax
  mov    %eax,0x4(%r12)
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L127
  add    $0x58,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L27:
  mov    %r15d,%edi
  call   <data_getroadlen@plt>
  mov    %eax,%r13d
  jmp    L16
L165:
  mov    0x1c(%rsp),%r13d
  xor    %edx,%edx
  mov    %r12,%rsi
  mov    %r13d,%edi
  call   <data_hypotheticalroadlength@plt>
  movd   (%r15),%xmm1
  mov    %r13d,%edi
  mov    %r12,%rsi
  movd   %ebx,%xmm0
  mov    $0x1,%edx
  mov    %eax,%ebp
  punpckldq %xmm1,%xmm0
  movq   %xmm0,(%r12)
  call   <data_hypotheticalroadlength@plt>
  mov    0x24(%rsp),%ecx
  mov    (%r15),%edi
  cmp    %ebp,%ecx
  cmovge %ecx,%ebp
  cmp    %eax,%ebp
  mov    0x20(%rsp),%eax
  cmovl  0x28(%rsp),%eax
  mov    %eax,0x2c(%rsp)
  call   <data_poslegal@plt>
  test   %rax,%rax
  jne    L29
L77:
  mov    (%r15),%edi
  mov    %r14,%rsi
  mov    %r14,%rbp
  xor    %r13d,%r13d
  call   <ai_surroundingverts@plt>
  lea    0x48(%rsp),%rax
  mov    %rax,0x10(%rsp)
L106:
  mov    0x0(%rbp),%esi
  mov    (%r15),%edi
  call   <road_freeedge@plt>
  test   %rax,%rax
  jne    L81
L40:
  add    $0x4,%rbp
  cmp    0x10(%rsp),%rbp
  jne    L106
  imul   %r13d,%r13d
  add    0x2c(%rsp),%r13d
  cmp    0x18(%rsp),%r13d
  jle    L69
  mov    (%r15),%eax
  mov    %r13d,0x18(%rsp)
  mov    %eax,0x8(%rsp)
  jmp    L69
  nopl   0x0(%rax,%rax,1)
L81:
  mov    0x0(%rbp),%edi
  call   <data_poslegal@plt>
  test   %rax,%rax
  je     L40
  mov    0x0(%rbp),%esi
  mov    0x1c(%rsp),%edi
  call   <ai_vertweight@plt>
  cmp    %r13d,%eax
  jle    L40
  mov    0x0(%rbp),%esi
  mov    0x1c(%rsp),%edi
  call   <ai_vertweight@plt>
  mov    %eax,%r13d
  jmp    L40
  nop
L41:
  mov    %ebx,%esi
  mov    %ebp,%edi
  call   <ai_vertweight@plt>
  imul   %eax,%eax
  mov    %eax,%ecx
  neg    %ecx
  mov    %ecx,0x20(%rsp)
  jmp    L139
  nopl   0x0(%rax)
L29:
  mov    0x1c(%rsp),%r13d
  mov    (%r15),%esi
  mov    %r13d,%edi
  call   <ai_vertweight@plt>
  mov    (%r15),%esi
  mov    %r13d,%edi
  mov    %eax,%ebp
  call   <ai_vertweight@plt>
  imul   %eax,%ebp
  mov    0x2c(%rsp),%eax
  lea    (%rax,%rbp,2),%eax
  mov    %eax,0x2c(%rsp)
  jmp    L77
L127:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int *ai_roadfromvert(int player, int vert, int ret[2]) {
  int i, j, weight, w;
  int maxweight = 0;
  int dest = 0;
  int sur[3];
  ai_surroundingverts(vert, sur);
  int handicap = 0;
  int roadlen, newroadlen, nextlongest;
  nextlongest = 0;
  for (j = 1; j < 4; j++) {
    if (data_getroadlen((player + j) % 4) > nextlongest) {
      nextlongest = data_getroadlen((player + j) % 4);
    }
  }
  if (data_poslegal(vert)) {
    handicap = ai_vertweight(player, vert);
    handicap *= handicap;
  }
  for (i = 0; i < 3; i++) {
    weight = handicap * -1;
    if (road_freeedge(vert, sur[i])) {
      roadlen = data_hypotheticalroadlength(player, ret, 0);
      ret[0] = vert;
      ret[1] = sur[i];
      newroadlen = data_hypotheticalroadlength(player, ret, 1);
      if (newroadlen >= 5 && newroadlen > nextlongest && newroadlen > roadlen) {
        weight += 5;
      }
      if (data_poslegal(sur[i]))
        weight += ai_vertweight(player, sur[i]) * ai_vertweight(player, sur[i]) * 2;
      int sur2[3];
      ai_surroundingverts(sur[i], sur2);
      w = 0;
      for (j = 0; j < 3; j++) {
        if (road_freeedge(sur[i], sur2[j]) && data_poslegal(sur2[j]))
          if (ai_vertweight(player, sur2[j]) > w)
            w = ai_vertweight(player, sur2[j]);
      }
      weight += w * w;
      if (weight > maxweight) {
        maxweight = weight;
        dest = sur[i];
      }
    }
  }
  ret[0] = dest;
  ret[1] = maxweight;
  return ret;
}
```