user: What is the c source code of the assembly code below:

```asm
<crypt_loop_attach>:
  endbr64
  push   %r15
  pxor   %xmm0,%xmm0
  mov    %r8,%r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  mov    %rsi,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  mov    %ecx,%ebx
  sub    $0x28,%rsp
  mov    (%r8),%ecx
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  movaps %xmm0,(%rsp)
  movq   $0x0,0x10(%rsp)
  test   %ecx,%ecx
  je     L159
  mov    D2(%rip),%rax
  mov    (%rax),%esi
L10:
  mov    D101(%rip),%rax
  mov    %r13,%rdi
  or     (%rax),%esi
  call   <open@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  js     L181
L113:
  mov    (%r15),%eax
  test   %eax,%eax
  jne    L21
  mov    D126(%rip),%rax
  mov    %r12,%rdi
  mov    (%rax),%esi
  call   <open@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L0
L55:
  mov    D82(%rip),%rax
  mov    0x8(%rsp),%rdi
  mov    %r13,%rsi
  mov    (%rax),%edx
  call   <strncpy@plt>
  mov    %r14d,(%rsp)
  test   %ebx,%ebx
  je     L188
  orl    $0x4,0x4(%rsp)
L188:
  mov    D36(%rip),%rax
  mov    %ebp,%edx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L40
  mov    D107(%rip),%rax
  mov    %rsp,%r13
  mov    %r12d,%edi
  mov    %r13,%rdx
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L102
  test   %ebx,%ebx
  jne    L85
L186:
  mov    %ebp,%edi
  call   <close@plt>
  nopl   0x0(%rax)
L122:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L95
  add    $0x28,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L21:
  mov    D2(%rip),%rax
  mov    %r12,%rdi
  mov    (%rax),%esi
  call   <open@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jns    L55
L0:
  mov    %ebp,%edi
  call   <close@plt>
L42:
  mov    $0xffffffff,%r12d
  jmp    L122
  nopl   0x0(%rax,%rax,1)
L159:
  mov    D126(%rip),%rax
  mov    (%rax),%esi
  jmp    L10
  xchg   %ax,%ax
L181:
  mov    D18(%rip),%rax
  mov    D98(%rip),%rdx
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L42
  mov    (%r15),%edx
  test   %edx,%edx
  jne    L42
  mov    D2(%rip),%rax
  movl   $0x1,(%r15)
  mov    %r13,%rdi
  mov    (%rax),%esi
  mov    D101(%rip),%rax
  or     (%rax),%esi
  call   <open@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  jns    L113
  jmp    L42
  nopw   0x0(%rax,%rax,1)
L85:
  xor    %esi,%esi
  mov    $0x18,%edx
  mov    %r13,%rdi
  call   <memset@plt>
  mov    D120(%rip),%rax
  mov    %r13,%rdx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L102
  testb  $0x4,0x4(%rsp)
  jne    L186
L102:
  mov    D29(%rip),%rax
  xor    %edx,%edx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
L40:
  mov    %r12d,%edi
  call   <close@plt>
  jmp    L0
L95:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int crypt_loop_attach(const char *loop, const char *file, int offset, int autoclear, int *readonly) {
  struct loop_info64 lo64 = {0};
  int loop_fd = -1, file_fd = -1, r = 1;
  file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL);
  if (file_fd < 0 && errno == EROFS && !*readonly) {
    *readonly = 1;
    file_fd = open(file, O_RDONLY | O_EXCL);
  }
  if (file_fd < 0)
    goto out;
  loop_fd = open(loop, *readonly ? O_RDONLY : O_RDWR);
  if (loop_fd < 0)
    goto out;
  strncpy((char *)lo64.lo_file_name, file, LO_NAME_SIZE);
  lo64.lo_offset = offset;
  if (autoclear)
    lo64.lo_flags |= 4;
  if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0)
    goto out;
  if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) {
    (void)ioctl(loop_fd, LOOP_CLR_FD, 0);
    goto out;
  }
  if (autoclear) {
    memset(&lo64, 0, sizeof(lo64));
    if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0 || !(lo64.lo_flags & 4)) {
      (void)ioctl(loop_fd, LOOP_CLR_FD, 0);
      goto out;
    }
  }
  r = 0;
out:
  if (r && loop_fd >= 0)
    close(loop_fd);
  if (file_fd >= 0)
    close(file_fd);
  return r ? -1 : loop_fd;
}
```