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

```asm
<GetModulationValue>:
  endbr64
  mov    %edi,%eax
  mov    %edx,%r10d
  mov    0x8(%rsp),%rdi
  mov    %esi,%edx
  and    $0x3,%edx
  not    %esi
  add    %esi,%esi
  and    $0x4,%esi
  or     %esi,%edx
  mov    %edx,%r11d
  test   %r10d,%r10d
  je     L62
  mov    %eax,%esi
  and    $0x7,%esi
  not    %eax
  mov    %eax,%edx
  add    %edx,%edx
  and    $0x8,%edx
  mov    %esi,%eax
  or     %edx,%eax
  movl   $0x0,(%rdi)
  movslq %r11d,%rdx
  shl    $0x6,%rdx
  mov    %rdx,%r10
  movslq %eax,%rdx
  lea    (%r8,%rdx,4),%rdx
  mov    (%rdx,%r10,1),%esi
  test   %esi,%esi
  je     L80
  mov    %r11d,%edx
  xor    %eax,%edx
  test   $0x1,%dl
  jne    L40
  cltq
  lea    (%rcx,%rax,4),%rax
  movslq (%rax,%r10,1),%rdx
  lea    D50(%rip),%rax
  mov    (%rax,%rdx,4),%eax
  jmp    L99
L62:
  mov    %eax,%esi
  and    $0x3,%esi
  not    %eax
  mov    %eax,%edx
  add    %edx,%edx
  and    $0x4,%edx
  mov    %esi,%eax
  or     %edx,%eax
  movl   $0x0,(%rdi)
  movslq %r11d,%rdx
  shl    $0x6,%rdx
  mov    %rdx,%r10
  movslq %eax,%rdx
  lea    (%r8,%rdx,4),%rdx
  cmpl   $0x0,(%rdx,%r10,1)
  jne    L89
L80:
  cltq
  lea    (%rcx,%rax,4),%rax
  movslq (%rax,%r10,1),%rdx
  lea    D50(%rip),%rax
  mov    (%rax,%rdx,4),%eax
L99:
  mov    %eax,(%r9)
  ret
L40:
  cmp    $0x1,%esi
  je     L28
  cmp    $0x2,%esi
  je     L41
  lea    D50(%rip),%rsi
  cltq
  lea    (%rcx,%rax,4),%rax
  add    %r10,%rax
  movslq -0x40(%rax),%rcx
  movslq 0x40(%rax),%rax
  mov    (%rsi,%rax,4),%edx
  add    (%rsi,%rcx,4),%edx
  add    $0x1,%edx
  mov    %edx,%eax
  shr    $0x1f,%eax
  add    %edx,%eax
  sar    %eax
  jmp    L99
L28:
  lea    (%rcx,%r10,1),%rdi
  lea    D50(%rip),%rsi
  movslq %eax,%rdx
  lea    (%rcx,%rdx,4),%rdx
  add    %r10,%rdx
  movslq -0x40(%rdx),%rcx
  movslq 0x40(%rdx),%rdx
  mov    (%rsi,%rdx,4),%edx
  add    (%rsi,%rcx,4),%edx
  lea    -0x1(%rax),%ecx
  movslq %ecx,%rcx
  movslq (%rdi,%rcx,4),%rcx
  add    (%rsi,%rcx,4),%edx
  add    $0x1,%eax
  cltq
  movslq (%rdi,%rax,4),%rax
  add    (%rsi,%rax,4),%edx
  lea    0x5(%rdx),%eax
  add    $0x2,%edx
  cmovns %edx,%eax
  sar    $0x2,%eax
  jmp    L99
L41:
  lea    (%rcx,%r10,1),%rdx
  lea    D50(%rip),%rsi
  lea    -0x1(%rax),%ecx
  movslq %ecx,%rcx
  movslq (%rdx,%rcx,4),%rcx
  add    $0x1,%eax
  cltq
  movslq (%rdx,%rax,4),%rax
  mov    (%rsi,%rax,4),%edx
  add    (%rsi,%rcx,4),%edx
  add    $0x1,%edx
  mov    %edx,%eax
  shr    $0x1f,%eax
  add    %edx,%eax
  sar    %eax
  jmp    L99
L89:
  cltq
  lea    (%rcx,%rax,4),%rax
  mov    (%rax,%r10,1),%edx
  movslq %edx,%rcx
  lea    D6(%rip),%rax
  mov    (%rax,%rcx,4),%eax
  cmp    $0x2,%edx
  sete   %dl
  movzbl %dl,%edx
  mov    %edx,(%rdi)
  jmp    L99
```

tool_calls: name: read_data
arguments: label: D50
data_type: string
name: read_data
arguments: label: D6
data_type: string

tool: 

tool: 

assistant: ```c
void GetModulationValue(int x, int y, const int Do2bitMode, const int ModulationVals[8][16], const int ModulationModes[8][16], int *Mod, int *DoPT) {
  static const int RepVals0[4] = {0, 3, 5, 8};
  static const int RepVals1[4] = {0, 4, 4, 8};
  int ModVal;
  y = (y & 0x3) | ((~y & 0x2) << 1);
  if (Do2bitMode)
    x = (x & 0x7) | ((~x & 0x4) << 1);
  else
    x = (x & 0x3) | ((~x & 0x2) << 1);
  *DoPT = 0;
  if (ModulationModes[y][x] == 0) {
    ModVal = RepVals0[ModulationVals[y][x]];
  } else if (Do2bitMode) {
    if (((x ^ y) & 1) == 0)
      ModVal = RepVals0[ModulationVals[y][x]];
    else if (ModulationModes[y][x] == 1) {
      ModVal = (RepVals0[ModulationVals[y - 1][x]] + RepVals0[ModulationVals[y + 1][x]] + RepVals0[ModulationVals[y][x - 1]] + RepVals0[ModulationVals[y][x + 1]] + 2) / 4;
    } else if (ModulationModes[y][x] == 2) {
      ModVal = (RepVals0[ModulationVals[y][x - 1]] + RepVals0[ModulationVals[y][x + 1]] + 1) / 2;
    } else {
      ModVal = (RepVals0[ModulationVals[y - 1][x]] + RepVals0[ModulationVals[y + 1][x]] + 1) / 2;
    }
  } else {
    ModVal = RepVals1[ModulationVals[y][x]];
    *DoPT = ModulationVals[y][x] == (2);
  }
  *Mod = ModVal;
}
```