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

```asm
<tofile>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x130,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x128(%rsp)
  xor    %eax,%eax
  lea    D19(%rip),%rdi
  call   <puts0@plt>
  lea    0x20(%rsp),%rbx
  lea    0x30(%rsp),%rdx
  mov    %rbx,%rax
L51:
  movb   $0x0,(%rax)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L51
  lea    0x20(%rsp),%rdi
  mov    $0x100,%esi
  mov    $0x0,%eax
  call   <getsn@plt>
  mov    $0x0,%eax
L31:
  movzbl 0x20(%rsp,%rax,1),%edx
  mov    %dl,(%rsp,%rax,1)
  add    $0x1,%rax
  cmp    $0x10,%rax
  jne    L31
  movb   $0x0,0x10(%rsp)
  lea    D65(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %rsp,%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  lea    D56(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  lea    D35(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  lea    0x100(%rbx),%rbp
  mov    %rbx,%rax
L5:
  movb   $0x0,(%rax)
  add    $0x1,%rax
  cmp    %rbp,%rax
  jne    L5
  lea    0x20(%rsp),%r12
  mov    $0x100,%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <getsn@plt>
  lea    D65(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  lea    D56(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %rsp,%rdi
  mov    $0x2,%esi
  mov    $0x0,%eax
  call   <open_@plt>
  cmp    $0x1,%ax
  je     L54
  lea    D39(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  jmp    L54
L63:
  add    $0x1,%rbx
  cmp    %rbp,%rbx
  je     L76
L54:
  movzbl (%rbx),%esi
  test   %sil,%sil
  je     L63
  movzbl %sil,%esi
  mov    $0x0,%edi
  mov    $0x0,%eax
  call   <writec@plt>
  movzbl (%rbx),%edi
  mov    $0x0,%eax
  call   <putch@plt>
  jmp    L63
L76:
  mov    $0x0,%edi
  mov    $0x0,%eax
  call   <close_@plt>
  mov    0x128(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L11
  add    $0x130,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L11:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: label: D19
type_infered: string
name: disassemble_data
arguments: label: D65
type_infered: string
name: disassemble_data
arguments: label: D56
type_infered: string
name: disassemble_data
arguments: label: D35
type_infered: string
name: disassemble_data
arguments: label: D39
type_infered: string

tool: D19: file ? 

tool: D65: 
'

tool: D56: '


tool: D35: data to file ? 

tool: D39: open not ok


assistant: ```c
void tofile(void) {
  unsigned short int i;
  unsigned short int j;
  unsigned short int equal;
  unsigned char device;
  unsigned char filename[16 + 2];
  unsigned char str[256];
  puts0("file ? ");
  for (i = 0; i < 16; i++)
    str[i] = 0;
  getsn(str, 256);
  for (i = 0; i < 16; i++)
    filename[i] = str[i];
  filename[16] = 0;
  puts0("\r\n'");
  puts0(filename);
  puts0("'\r\n");
  puts0("data to file ? ");
  for (i = 0; i < 256; i++)
    str[i] = 0;
  getsn(str, 256);
  puts0("\r\n'");
  puts0(str);
  puts0("'\r\n");
  i = open_(filename, 2);
  if (i == 1) {
  } else
    puts0("open not ok\r\n");
  for (i = 0; i < 256; i++)
    if (str[i]) {
      writec(0, str[i]);
      putch(str[i]);
    }
  close_(0);
}
```