user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<gen_wave>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r14
  mov    %esi,%ebp
  mov    %edx,0xc(%rsp)
  mov    %ecx,%r12d
  mov    $0x0,%r13d
  mov    $0x0,%ebx
  jmp    L123
L142:
  cmp    $0x3,%ebp
  jne    L5
  addss  %xmm0,%xmm0
  movss  D14(%rip),%xmm1
  subss  %xmm0,%xmm1
  pxor   %xmm7,%xmm7
  cvtss2sd %xmm1,%xmm7
  movsd  %xmm7,(%rsp)
  jmp    L5
L17:
  addss  %xmm0,%xmm0
  cvttss2si %xmm0,%eax
  test   $0x1,%al
  je     L101
  xorps  D77(%rip),%xmm0
L101:
  pxor   %xmm5,%xmm5
  cvtss2sd %xmm0,%xmm5
  movsd  %xmm5,(%rsp)
L5:
  cmp    $0x2,%r12d
  je     L75
  cmp    $0x3,%r12d
  je     L32
  cmp    $0x1,%r12d
  je     L57
L56:
  movsd  (%rsp),%xmm0
  mulsd  D57(%rip),%xmm0
  addsd  (%r14,%rbx,8),%xmm0
  movsd  %xmm0,(%r14,%rbx,8)
  add    $0x1,%rbx
  add    0xc(%rsp),%r13d
  cmp    $0x400,%rbx
  je     L23
L123:
  mov    %ebx,%r15d
  mov    %ebx,0x8(%rsp)
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  divsd  D29(%rip),%xmm0
  cvtsd2ss %xmm0,%xmm0
  cmp    $0x2,%ebp
  je     L70
  jg     L142
  test   %ebp,%ebp
  je     L17
  cmp    $0x1,%ebp
  jne    L5
  addss  %xmm0,%xmm0
  cvttss2si %xmm0,%eax
  and    $0x1,%eax
  pxor   %xmm6,%xmm6
  cvtsi2sd %eax,%xmm6
  movsd  %xmm6,(%rsp)
  jmp    L5
L70:
  cvtss2sd %xmm0,%xmm0
  mulsd  D89(%rip),%xmm0
  cvtsd2ss %xmm0,%xmm0
  call   <sin@plt>
  movsd  %xmm0,(%rsp)
  jmp    L5
L57:
  pxor   %xmm1,%xmm1
  cvtsi2sdl 0x8(%rsp),%xmm1
  mulsd  D10(%rip),%xmm1
  movsd  D9(%rip),%xmm0
  subsd  %xmm1,%xmm0
  mulsd  (%rsp),%xmm0
  movsd  %xmm0,(%rsp)
  jmp    L56
L75:
  neg    %r15d
  pxor   %xmm0,%xmm0
  cvtsi2sd %r15d,%xmm0
  mulsd  D10(%rip),%xmm0
  cvttsd2si %xmm0,%edi
  call   <sqrt@plt>
  mov    %eax,%edx
  mov    $0x1,%eax
  sub    %edx,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  mulsd  (%rsp),%xmm0
  movsd  %xmm0,(%rsp)
  jmp    L56
L32:
  pxor   %xmm0,%xmm0
  cvtsi2sdl 0x8(%rsp),%xmm0
  mulsd  D58(%rip),%xmm0
  cvttsd2si %xmm0,%edi
  call   <sqrt@plt>
  mov    %eax,%edx
  mov    $0x1,%eax
  sub    %edx,%eax
  pxor   %xmm0,%xmm0
  cvtsi2sd %eax,%xmm0
  mulsd  (%rsp),%xmm0
  movsd  %xmm0,(%rsp)
  jmp    L56
L23:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: parse_data
arguments: tag: D14
type: byte[4]
name: parse_data
arguments: tag: D77
type: byte[16]
name: parse_data
arguments: tag: D57
type: byte[8]
name: parse_data
arguments: tag: D29
type: f64
name: parse_data
arguments: tag: D89
type: f64
name: parse_data
arguments: tag: D10
type: byte[8]
name: parse_data
arguments: tag: D9
type: byte[8]
name: parse_data
arguments: tag: D58
type: byte[8]

tool: {"D14": [0x00,0x00,0x80,0x3f]}

tool: {"D77": [0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]}

tool: {"D57": [0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x40]}

tool: D29: 8000

tool: D89: 6.28

tool: {"D10": [0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x3f]}

tool: {"D9": [0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f]}

tool: {"D58": [0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x40]}

assistant: ```c
void gen_wave(int8_t *arr, uint8_t type, uint16_t freq, uint8_t lfo_type, uint8_t lfo_coef) {
  int i;
  float x;
  double cv;
  for (i = 0; i < 1024; i++) {
    x = i * freq / 8000.0;
    switch (type) {
    case 0:
      cv = (int)(x * 2) % 2 ? -2 * x : 2 * x;
      break;
    case 1:
      cv = (int)(x * 2) % 2 ? 1 : 0;
      break;
    case 2:
      cv = sin(x * 6.28);
      break;
    case 3:
      cv = 1 - 2 * x;
      break;
    }
    switch (lfo_type) {
    case 1:
      cv *= (1 - i / (double)1024);
      break;
    case 2:
      cv *= (1 - sqrt(-i / (double)1024));
      break;
    case 3:
      cv *= (1 - sqrt(i * (double)(1024)));
      break;
    }
    arr[i] += cv * 128;
  }
}
```