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

```asm
<checkdict>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %rcx,-0x40(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x18(%rbp)
  lea    D2(%rip),%rax
  mov    %rax,%rsi
  lea    D1(%rip),%rax
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x10(%rbp)
  lea    -0x1c(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  lea    D39(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fscanf@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  jmp    L29
L4:
  mov    -0x1c(%rbp),%edx
  mov    -0x18(%rbp),%eax
  add    %edx,%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,-0x14(%rbp)
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L51
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rsi
  lea    D10(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rcx
  mov    -0x40(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  lea    D10(%rip),%rsi
  mov    %rax,%rdi
  call   <fprintf@plt>
  mov    $0x1,%eax
  jmp    L52
L51:
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jle    L30
  mov    -0x14(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,-0x18(%rbp)
  jmp    L29
L30:
  mov    -0x14(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jns    L29
  mov    -0x14(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x1c(%rbp)
L29:
  mov    -0x1c(%rbp),%eax
  cmp    %eax,-0x18(%rbp)
  jle    L4
  mov    $0x0,%eax
L52:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L12
  call   <__stack_chk_fail@plt>
L12:
  leave
  ret
```

tool_calls: name: parse_data
arguments: data_label: D2
data_type: string
name: parse_data
arguments: data_label: D1
data_type: string
name: parse_data
arguments: data_label: D39
data_type: string
name: parse_data
arguments: data_label: D10
data_type: string

tool: D2: r

tool: D1: dictionary.txt

tool: D39: %d

tool: D10: A permutation of %s is %s.


assistant: ```c
int checkdict(FILE *ofp, char **dictionary, char check[], const char *submission) {
  FILE *ifp;
  int min = 0, max, mid;
  ifp = fopen("dictionary.txt", "r");
  fscanf(ifp, "%d", &max);
  fclose(ifp);
  while (min <= max) {
    mid = (min + max) / 2;
    if (strcmp(check, dictionary[mid]) == 0) {
      printf("A permutation of %s is %s.\n", submission, dictionary[mid]);
      fprintf(ofp, "A permutation of %s is %s.\n", submission, dictionary[mid]);
      return 1;
    } else if (strcmp(check, dictionary[mid]) > 0)
      min = mid + 1;
    else if (strcmp(check, dictionary[mid]) < 0)
      max = mid - 1;
  }
  return 0;
}
```