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

```asm
<takedarkimage>:
  endbr64
  push   %r13
  mov    $0xc8,%esi
  push   %r12
  push   %rbx
  mov    %edi,%ebx
  sub    $0x840,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x838(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%r13
  lea    0x30(%rsp),%r12
  mov    %r13,%rdi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x12(%rsp),%rdi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x14(%rsp),%rdi
  call   <convint@plt>
  lea    0x16(%rsp),%rdi
  mov    $0x79,%esi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x18(%rsp),%rdi
  call   <convint@plt>
  lea    0x1a(%rsp),%rdi
  mov    $0xfa,%esi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x1c(%rsp),%rdi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x1e(%rsp),%rdi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x20(%rsp),%rdi
  call   <convint@plt>
  lea    0x22(%rsp),%rdi
  mov    $0x1770,%esi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x24(%rsp),%rdi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x26(%rsp),%rdi
  call   <convint@plt>
  lea    0x28(%rsp),%rdi
  mov    $0x3,%esi
  call   <convint@plt>
  xor    %esi,%esi
  lea    0x2a(%rsp),%rdi
  call   <convint@plt>
  lea    0xc(%rsp),%rsi
  mov    %r13,%rcx
  mov    %r12,%rdi
  mov    $0x1c,%r8d
  mov    $0x1,%edx
  call   <buildpacket@plt>
  mov    0xc(%rsp),%edx
  mov    %r12,%rsi
  mov    %ebx,%edi
  call   <write@plt>
  lea    0x430(%rsp),%rsi
  mov    %ebx,%edi
  call   <listen@plt>
  cmp    $0x1,%eax
  jne    L16
  cmpb   $0x6,0x430(%rsp)
  je     L6
L16:
  lea    D29(%rip),%rdi
  xor    %r12d,%r12d
  call   <printf@plt>
L57:
  mov    0x838(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x840,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  ret
  nopl   (%rax)
L6:
  lea    D6(%rip),%rdi
  mov    $0x160dc080,%r13d
  call   <printf@plt>
  jmp    L38
  nopl   0x0(%rax)
L26:
  xor    %edx,%edx
  mov    %r13d,%edi
  xor    %esi,%esi
  call   <nanosleep@plt>
L38:
  mov    %ebx,%edi
  call   <checkidle@plt>
  mov    %eax,%r12d
  cmp    $0x1,%eax
  jne    L26
  lea    D3(%rip),%rdi
  call   <printf@plt>
  jmp    L57
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_label: D29
data_type: string
name: read_data
arguments: data_label: D6
data_type: string
name: read_data
arguments: data_label: D3
data_type: string

tool: D29: Problem taking image.


tool: D6: Taking image ...


tool: D3: Exposure completed!  Image stored in dark buffer.


assistant: ```c
int takedarkimage(int fd) {
  unsigned char pak[1024];
  unsigned char buf[1024];
  int len, res;
  int DONE = 0;
  unsigned char p[28];
  convint(&p[0], 200);
  convint(&p[2], 0);
  convint(&p[4], 0);
  convint(&p[6], 121);
  convint(&p[8], 0);
  convint(&p[10], 250);
  convint(&p[12], 0);
  convint(&p[14], 0);
  convint(&p[16], 0);
  convint(&p[18], 6000);
  convint(&p[20], 0);
  convint(&p[22], 0);
  convint(&p[24], 3);
  convint(&p[26], 0);
  buildpacket(pak, &len, 0x01, p, 28);
  write(fd, pak, len);
  res = listen(fd, buf);
  if (!(res == 1 && buf[0] == 0x06)) {
    printf("Problem taking image.\n");
    return 0;
  } else
    printf("Taking image ...\n");
  struct timespec wait;
  wait.tv_sec = 0;
  wait.tv_nsec = 370000000;
  while (!(checkidle(fd) == 1)) {
    nanosleep(wait, NULL);
  }
  printf("Exposure completed!  Image stored in dark buffer.\n");
  return 1;
}
```