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

```asm
<get_BZ_triplets_at_q>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  lea    0x0(,%r9,4),%edi
  push   %r13
  movslq %r9d,%r13
  push   %r12
  mov    %r8,%r12
  push   %rbp
  movslq %esi,%rbp
  push   %rbx
  mov    %rcx,%rbx
  sub    $0xb8,%rsp
  mov    0xf0(%rsp),%rsi
  mov    %rdx,0x28(%rsp)
  mov    %rsi,0x30(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0xa8(%rsp)
  mov    (%rsi),%eax
  mov    %r9d,0x8(%rsp)
  add    %eax,%eax
  mov    %eax,0x74(%rsp)
  mov    0x4(%rsi),%eax
  add    %eax,%eax
  mov    %eax,0x78(%rsp)
  mov    0x8(%rsi),%eax
  add    %eax,%eax
  mov    %eax,0x7c(%rsp)
  call   <malloc@plt>
  mov    0x8(%rsp),%r9d
  mov    %rax,0x50(%rsp)
  test   %r9d,%r9d
  jle    L92
  mov    %rax,%rsi
  xor    %edx,%edx
  xor    %eax,%eax
  nopl   (%rax)
L61:
  cmp    %eax,(%r12,%rax,4)
  jne    L68
  movslq %edx,%rcx
  add    $0x1,%edx
  mov    %eax,(%rsi,%rcx,4)
L68:
  add    $0x1,%rax
  cmp    %r13,%rax
  jne    L61
  mov    %edx,0x5c(%rsp)
  test   %edx,%edx
  je     L101
  mov    0x28(%rsp),%rsi
  lea    0x0(%rbp,%rbp,2),%rax
  lea    0x74(%rsp),%r13
  mov    %r14,0x18(%rsp)
  lea    0x80(%rsp),%rbp
  mov    %r13,%r14
  lea    (%rsi,%rax,4),%r12
  mov    0x50(%rsp),%rsi
  lea    -0x1(%rdx),%eax
  mov    %rbp,%r15
  lea    0x4(%rsi,%rax,4),%rax
  mov    %rsi,0x10(%rsp)
  mov    %rax,0x38(%rsp)
  lea    0xa4(%rsp),%rax
  mov    %rax,0x8(%rsp)
  lea    0x68(%rsp),%rax
  mov    %rax,0x40(%rsp)
  lea    0x8c(%rsp),%rax
  mov    %rax,0x48(%rsp)
  nopl   (%rax)
L16:
  mov    0x10(%rsp),%rax
  mov    %rax,%rsi
  add    $0x4,%rax
  mov    %rax,0x10(%rsp)
  cmp    %rax,%r15
  jae    L79
  cmp    0x48(%rsp),%rsi
  jb     L131
L79:
  mov    (%r12),%rax
  mov    0x28(%rsp),%rdi
  mov    %rax,(%r15)
  mov    0x8(%r12),%eax
  mov    %eax,0x8(%r15)
  xor    %eax,%eax
L65:
  movslq (%rsi),%rdx
  movslq %eax,%rcx
  lea    (%rdx,%rdx,2),%rdx
  lea    (%rdi,%rdx,4),%rdx
  mov    (%rdx,%rcx,4),%ecx
  mov    (%r12,%rax,4),%edx
  neg    %edx
  mov    %ecx,0xc(%r15,%rax,4)
  sub    %ecx,%edx
  mov    %edx,0x18(%r15,%rax,4)
  add    $0x1,%rax
  cmp    $0x3,%rax
  jne    L65
L103:
  mov    0x30(%rsp),%r13
  mov    $0x2,%ebp
L47:
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %rbx,%rdx
  mov    %ebp,%esi
  mov    %r15,%rdi
  call   <get_third_q_of_triplets_at_q@plt>
  test   %rax,%rax
  je     L32
  sub    $0x1,%ebp
  jae    L47
L32:
  mov    0x18(%rsp),%r13
  mov    %r12,0x20(%rsp)
  mov    %r14,%r12
  mov    %r15,%rbp
  mov    %r13,%r14
  mov    %rbx,%r13
  mov    0x40(%rsp),%rbx
L139:
  mov    0x0(%rbp),%eax
  mov    %r12,%rsi
  mov    %rbx,%rdi
  add    $0xc,%rbp
  add    $0x4,%r14
  add    %eax,%eax
  mov    %eax,0x68(%rsp)
  mov    -0x8(%rbp),%eax
  add    %eax,%eax
  mov    %eax,0x6c(%rsp)
  mov    -0x4(%rbp),%eax
  add    %eax,%eax
  mov    %eax,0x70(%rsp)
  call   <kpt_get_grid_point_double_mesh@plt>
  mov    0x0(%r13,%rax,4),%eax
  mov    %eax,-0x4(%r14)
  cmp    0x8(%rsp),%rbp
  jne    L139
  mov    %r12,%r14
  mov    0x38(%rsp),%rdi
  mov    0x20(%rsp),%r12
  mov    %r13,%rbx
  addq   $0xc,0x18(%rsp)
  cmp    %rdi,0x10(%rsp)
  jne    L16
L101:
  mov    0x50(%rsp),%rdi
  call   <free@plt>
  mov    0xa8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L108
  mov    0x5c(%rsp),%eax
  add    $0xb8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L131:
  mov    0x28(%rsp),%r9
  mov    %r15,%rcx
  xor    %edx,%edx
L9:
  mov    (%r12,%rdx,4),%eax
  movslq %edx,%r8
  add    $0x1,%rdx
  add    $0x4,%rcx
  mov    %eax,-0x4(%rcx)
  movslq (%rsi),%rdi
  neg    %eax
  lea    (%rdi,%rdi,2),%rdi
  lea    (%r9,%rdi,4),%rdi
  mov    (%rdi,%r8,4),%edi
  sub    %edi,%eax
  mov    %edi,0x8(%rcx)
  mov    %eax,0x14(%rcx)
  cmp    $0x3,%rdx
  jne    L9
  jmp    L103
L92:
  movl   $0x0,0x5c(%rsp)
  jmp    L101
L108:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int get_BZ_triplets_at_q(int triplets[][3], const int grid_point, int bz_grid_address[][3], const int bz_map[], const int map_triplets[], const int num_map_triplets, const int mesh[3]) {
  int i, j, k, num_ir;
  int bz_address[3][3], bz_address_double[3], bzmesh[3];
  int *ir_grid_points;
  for (i = 0; i < 3; i++) {
    bzmesh[i] = mesh[i] * 2;
  }
  num_ir = 0;
  ir_grid_points = (int *)malloc(sizeof(int) * num_map_triplets);
  for (i = 0; i < num_map_triplets; i++) {
    if (map_triplets[i] == i) {
      ir_grid_points[num_ir] = i;
      num_ir++;
    }
  }
#pragma omp parallel for private(j, k, bz_address, bz_address_double)
  for (i = 0; i < num_ir; i++) {
    for (j = 0; j < 3; j++) {
      bz_address[0][j] = bz_grid_address[grid_point][j];
      bz_address[1][j] = bz_grid_address[ir_grid_points[i]][j];
      bz_address[2][j] = -bz_address[0][j] - bz_address[1][j];
    }
    for (j = 2; j > -1; j--) {
      if (get_third_q_of_triplets_at_q(bz_address, j, bz_map, mesh, bzmesh) == 0) {
        break;
      }
    }
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 3; k++) {
        bz_address_double[k] = bz_address[j][k] * 2;
      }
      triplets[i][j] = bz_map[kpt_get_grid_point_double_mesh(bz_address_double, bzmesh)];
    }
  }
  free(ir_grid_points);
  return num_ir;
}
```