user: Demonstrate the C code that generates the assembly output 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     L158
  mov    D90(%rip),%rax
  mov    (%rax),%esi
L31:
  mov    D25(%rip),%rax
  mov    %r13,%rdi
  or     (%rax),%esi
  call   <open@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  js     L102
L33:
  mov    (%r15),%eax
  test   %eax,%eax
  jne    L114
  mov    D20(%rip),%rax
  mov    %r12,%rdi
  mov    (%rax),%esi
  call   <open@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  js     L32
L179:
  mov    D130(%rip),%rax
  mov    0x8(%rsp),%rdi
  mov    %r13,%rsi
  mov    (%rax),%edx
  call   <strncpy@plt>
  mov    %r14d,(%rsp)
  test   %ebx,%ebx
  je     L149
  orl    $0x4,0x4(%rsp)
L149:
  mov    D63(%rip),%rax
  mov    %ebp,%edx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L10
  mov    D19(%rip),%rax
  mov    %rsp,%r13
  mov    %r12d,%edi
  mov    %r13,%rdx
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L64
  test   %ebx,%ebx
  jne    L155
L143:
  mov    %ebp,%edi
  call   <close@plt>
  nopl   0x0(%rax)
L40:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L166
  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)
L114:
  mov    D90(%rip),%rax
  mov    %r12,%rdi
  mov    (%rax),%esi
  call   <open@plt>
  mov    %eax,%r12d
  test   %eax,%eax
  jns    L179
L32:
  mov    %ebp,%edi
  call   <close@plt>
L80:
  mov    $0xffffffff,%r12d
  jmp    L40
  nopl   0x0(%rax,%rax,1)
L158:
  mov    D20(%rip),%rax
  mov    (%rax),%esi
  jmp    L31
  xchg   %ax,%ax
L102:
  mov    D21(%rip),%rax
  mov    D85(%rip),%rdx
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L80
  mov    (%r15),%edx
  test   %edx,%edx
  jne    L80
  mov    D90(%rip),%rax
  movl   $0x1,(%r15)
  mov    %r13,%rdi
  mov    (%rax),%esi
  mov    D25(%rip),%rax
  or     (%rax),%esi
  call   <open@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  jns    L33
  jmp    L80
  nopw   0x0(%rax,%rax,1)
L155:
  xor    %esi,%esi
  mov    $0x18,%edx
  mov    %r13,%rdi
  call   <memset@plt>
  mov    D7(%rip),%rax
  mov    %r13,%rdx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
  test   %rax,%rax
  js     L64
  testb  $0x4,0x4(%rsp)
  jne    L143
L64:
  mov    D121(%rip),%rax
  xor    %edx,%edx
  mov    %r12d,%edi
  mov    (%rax),%esi
  xor    %eax,%eax
  call   <ioctl@plt>
L10:
  mov    %r12d,%edi
  call   <close@plt>
  jmp    L32
L166:
  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;
}
```