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

```asm
<extended_euclid>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %r8,-0x58(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L38
  mov    -0x58(%rbp),%rax
  mov    -0x38(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x48(%rbp),%rax
  movq   $0x1,(%rax)
  mov    -0x50(%rbp),%rax
  movq   $0x0,(%rax)
  jmp    L27
L38:
  movq   $0x1,-0x28(%rbp)
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x18(%rbp)
  movq   $0x1,-0x20(%rbp)
  lea    D7(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  lea    D87(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D20(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  lea    D7(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L20
L23:
  mov    -0x38(%rbp),%rax
  cqto
  idivq  -0x40(%rbp)
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x38(%rbp),%rax
  sub    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x10(%rbp),%rax
  imul   -0x30(%rbp),%rax
  mov    %rax,%rcx
  mov    -0x28(%rbp),%rax
  sub    %rcx,%rax
  mov    %rax,%rdx
  mov    -0x48(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x10(%rbp),%rax
  imul   -0x20(%rbp),%rax
  mov    %rax,%rcx
  mov    -0x18(%rbp),%rax
  sub    %rcx,%rax
  mov    %rax,%rdx
  mov    -0x50(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x40(%rbp),%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x48(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x20(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x50(%rbp),%rax
  mov    (%rax),%rsi
  mov    -0x48(%rbp),%rax
  mov    (%rax),%rcx
  mov    -0x8(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  mov    %rsi,%r8
  mov    %rax,%rsi
  lea    D96(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x30(%rbp),%rsi
  mov    -0x28(%rbp),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rsi,%r8
  mov    %rax,%rsi
  lea    D96(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x20(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rax,%rsi
  lea    D84(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L20:
  cmpq   $0x0,-0x40(%rbp)
  jg     L23
  mov    -0x58(%rbp),%rax
  mov    -0x38(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x48(%rbp),%rax
  mov    -0x28(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x50(%rbp),%rax
  mov    -0x18(%rbp),%rdx
  mov    %rdx,(%rax)
  lea    D7(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D18(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
L27:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: label: D7
type_guessed: string
name: unpack_data
arguments: label: D18
type_guessed: string
name: unpack_data
arguments: label: D87
type_guessed: string
name: unpack_data
arguments: label: D20
type_guessed: string
name: unpack_data
arguments: label: D96
type_guessed: string
name: unpack_data
arguments: label: D84
type_guessed: string

tool: D7: ------------------------------

tool: D18: -------------------

tool: D87: q    r    x    y    a    b    

tool: D20: x2   x1   y2   y1

tool: D96: %4ld %4ld %4ld %4ld 

tool: D84: %4ld %4ld


assistant: ```c
void extended_euclid(long a, long b, long *x, long *y, long *d) {
  long q, r, x1, x2, y1, y2;
  if (b == 0) {
    *d = a, *x = 1, *y = 0;
    return;
  }
  x2 = 1, x1 = 0, y2 = 0, y1 = 1;
  printf("------------------------------");
  printf("-------------------\n");
  printf("q    r    x    y    a    b    ");
  printf("x2   x1   y2   y1\n");
  printf("------------------------------");
  printf("-------------------\n");
  while (b > 0) {
    q = a / b, r = a - q * b;
    *x = x2 - q * x1, *y = y2 - q * y1;
    a = b, b = r;
    x2 = x1, x1 = *x, y2 = y1, y1 = *y;
    printf("%4ld %4ld %4ld %4ld ", q, r, *x, *y);
    printf("%4ld %4ld %4ld %4ld ", a, b, x2, x1);
    printf("%4ld %4ld\n", y2, y1);
  }
  *d = a, *x = x2, *y = y2;
  printf("------------------------------");
  printf("-------------------\n");
}
```