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

```asm
<getXY>:
  endbr64
  push   %r15
  mov    %rdi,%r10
  mov    %edx,%r8d
  mov    $0x1,%r11d
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  test   %ecx,%ecx
  jne    L5
  shl    $0x4,%r8d
  mov    $0xf,%r11d
  sub    %edx,%r8d
L5:
  movswl 0x0(%rbp),%esi
  cmp    $0x8,%ebx
  mov    $0x1e,%eax
  mov    $0x50,%r12d
  cmovne %eax,%r12d
  lea    D20(%rip),%rdi
  mov    %esi,%eax
  cltd
  mov    %r12d,%r13d
  idiv   %ebx
  sub    %ecx,%r13d
  imul   %ebx,%r13d
  mov    %r13d,%r9d
  add    %ecx,%eax
  test   %edx,%edx
  lea    D36(%rip),%rcx
  lea    D31(%rip),%rdx
  cmove  %rcx,%rdx
  sub    $0x8,%rsp
  mov    %r12d,%ecx
  push   %rsi
  mov    %r10,%rsi
  push   %rdx
  mov    %r11d,%edx
  push   %rax
  xor    %eax,%eax
  call   <printf@plt>
  add    $0x20,%rsp
  xor    %eax,%eax
  call   <getLine@plt>
  movslq %eax,%r12
  cmpb   $0x0,(%r12)
  jne    L75
  movzwl 0x0(%rbp),%r14d
L16:
  mov    %r14w,0x0(%rbp)
  mov    %r12,%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L23
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L75:
  lea    0x10(%rsp),%rsi
  xor    %edx,%edx
  mov    %r12,%rdi
  xor    %eax,%eax
  call   <strtol@plt>
  mov    %eax,%r14d
  mov    0x10(%rsp),%rax
  cmp    %r12,%rax
  je     L44
  movsbl (%rax),%r15d
  mov    %r15d,%edi
  mov    %r15b,0xf(%rsp)
  call   <toupper@plt>
  movzbl 0xf(%rsp),%edx
  test   %dl,%dl
  jne    L70
L34:
  mov    %r15d,%edi
  call   <toupper@plt>
  cmp    $0x50,%eax
  je     L47
  sub    $0x1,%r14d
  imul   %ebx,%r14d
L47:
  cmp    %r13d,%r14d
  jle    L16
  lea    D10(%rip),%rdi
  movzwl 0x0(%rbp),%r14d
  call   <puts@plt>
  jmp    L16
  nopl   0x0(%rax)
L70:
  cmp    $0x50,%eax
  je     L47
L44:
  lea    D21(%rip),%rdi
  movswl 0x0(%rbp),%r14d
  call   <puts@plt>
  mov    0x10(%rsp),%rax
  movsbl (%rax),%r15d
  jmp    L34
L23:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_tag: D20
data_type: string
name: read_data
arguments: data_tag: D36
data_type: string
name: read_data
arguments: data_tag: D31
data_type: string
name: read_data
arguments: data_tag: D10
data_type: string
name: read_data
arguments: data_tag: D21
data_type: string

tool: D20: %s (%d..%d) or (%dp..%dp) [%d%s or %dp]: 

tool: 

tool: D31: +

tool: D10: ???2

tool: D21: ???1

assistant: ```c
void getXY(char *what, short *locp, int scale, int abs) {
  char *line, *end;
  int val;
  int min = abs ? 1 : 15;
  int minp = min * scale;
  int max = scale == 8 ? 80 : 30;
  int maxp = (max - abs) * scale;
  int loc = *locp / scale + abs;
  char *plus = *locp % scale ? "+" : "";
  printf("%s (%d..%d) or (%dp..%dp) [%d%s or %dp]: ", what, min, max, minp, maxp, loc, plus, (int)*locp);
  line = getLine();
  if (!*line)
    val = *locp;
  else {
    val = strtol(line, &end, 0);
    if (line == end || (*end && toupper(*end) != 'P')) {
      val = *locp;
      printf("???1\n");
    }
    if (toupper(*end) != 'P')
      val = (val - 1) * scale;
    if (val > maxp) {
      val = *locp;
      printf("???2\n");
    }
  }
  *locp = val;
  free(line);
}
```