user: Converte this assembly snippet into its equivalent C code:

```asm
<gsa_walk>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  push   %rbx
  movslq %esi,%rbx
  mov    %ebx,%edi
  mov    %rbx,%rbp
  imul   %ebx,%edi
  sub    $0x48,%rsp
  mov    %edx,0x14(%rsp)
  mov    %rcx,0x28(%rsp)
  shl    $0x2,%edi
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  call   <malloc@plt>
  test   %ebx,%ebx
  mov    %rax,%r15
  setg   %al
  xor    %edi,%edi
  test   %r12d,%r12d
  setg   %dil
  and    %eax,%edi
  call   <assert@plt>
  test   %r15,%r15
  je     L36
L22:
  test   %ebp,%ebp
  jle    L96
  lea    0x0(,%rbx,4),%r13
  mov    %r15,%rcx
  xor    %r12d,%r12d
  nopw   0x0(%rax,%rax,1)
L87:
  mov    %rcx,%rdi
  mov    %r13,%rdx
  xor    %esi,%esi
  add    $0x1,%r12d
  call   <memset@plt>
  mov    %rax,%rcx
  add    %r13,%rcx
  cmp    %r12d,%ebp
  jne    L87
L96:
  mov    %ebp,%r13d
  shr    $0x1f,%r13d
  add    %ebp,%r13d
  sar    %r13d
  movslq %r13d,%rax
  mov    %r13d,0x34(%rsp)
  imul   %rax,%rbx
  shl    $0x2,%rax
  mov    %r13d,0x30(%rsp)
  lea    (%rax,%rbx,4),%rax
  movl   $0x1,(%r15,%rax,1)
  mov    0x14(%rsp),%eax
  test   %eax,%eax
  jle    L109
  lea    0x34(%rsp),%rax
  pxor   %xmm3,%xmm3
  xor    %r12d,%r12d
  mov    %rax,0x20(%rsp)
  lea    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
  movsd  %xmm3,0x8(%rsp)
  jmp    L56
  nopl   0x0(%rax)
L97:
  cmp    %r12d,0x14(%rsp)
  jle    L111
L56:
  test   %r14,%r14
  je     L63
  mov    0x34(%rsp),%ecx
  mov    0x30(%rsp),%edx
  lea    D12(%rip),%rsi
  mov    %r14,%rdi
  call   <fprintf@plt>
L63:
  mov    0x30(%rsp),%edi
  mov    $0x2,%esi
  add    $0x1,%r12d
  sub    %r13d,%edi
  call   <pow@plt>
  mov    0x34(%rsp),%edi
  mov    $0x2,%esi
  mov    %rax,%rbx
  sub    %r13d,%edi
  call   <pow@plt>
  pxor   %xmm0,%xmm0
  mov    0x20(%rsp),%rcx
  mov    %ebp,%esi
  add    %rax,%rbx
  mov    0x18(%rsp),%rdx
  mov    %r15,%rdi
  cvtsi2sd %rbx,%xmm0
  addsd  0x8(%rsp),%xmm0
  movsd  %xmm0,0x8(%rsp)
  call   <take_next_step@plt>
  test   %eax,%eax
  jne    L97
L111:
  mov    0x28(%rsp),%rax
  test   %rax,%rax
  je     L15
  pxor   %xmm1,%xmm1
  movsd  0x8(%rsp),%xmm0
  cvtsi2sd %r12d,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
L15:
  mov    %r15,%rdi
  call   <free@plt>
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L36:
  lea    D13(%rip),%rdi
  call   <perror@plt>
  xor    %eax,%eax
  call   <abort@plt>
  jmp    L22
L109:
  pxor   %xmm4,%xmm4
  xor    %r12d,%r12d
  movsd  %xmm4,0x8(%rsp)
  jmp    L111
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D12
type: string
name: extract_symbolic_data
arguments: label: D13
type: string

tool: D12: %d %d


tool: D13: malloc() lattice

assistant: ```c
int gsa_walk(FILE *fout, int dim, int nsteps, double *pdist) {
  bool(*lattice)[dim] = malloc(dim * dim * sizeof(bool));
  int asteps;
  int i, j;
  int last_x, last_y;
  double sum_r2;
  bool alive;
  assert(dim > 0 && nsteps > 0);
  if (lattice == NULL) {
    perror("malloc() lattice");
    abort();
  }
  for (i = 0; i < dim; i++) {
    for (j = 0; j < dim; j++) {
      lattice[i][j] = false;
    }
  }
  alive = true;
  last_x = last_y = dim / 2;
  lattice[last_x][last_y] = true;
  asteps = 0;
  sum_r2 = 0;
  while (alive && asteps < nsteps) {
    if (fout != NULL) {
      fprintf(fout, "%d %d\n", last_x, last_y);
    }
    sum_r2 += pow(last_x - dim / 2, 2) + pow(last_y - dim / 2, 2);
    alive = take_next_step((bool *)lattice, dim, &last_x, &last_y);
    asteps++;
  }
  if (pdist != NULL) {
    *pdist = sum_r2 / asteps;
  }
  free(lattice);
  return asteps;
}
```