// File: /workspace/github_cpp_makefile_star2_O3/trapexit[P]bbf/src/bbf_write_uncorrectable.cpp
// Function: bbf::write_uncorrectable(Options const&)
AppError
  write_uncorrectable(const Options &opts_)
  {
    int rv;
    BlkDev blkdev;
    std::string captcha;
    std::string input_file;
    std::vector<uint64_t> badblocks;

    input_file = opts_.input_file;

    rv = blkdev.open_rdwr(opts_.device,!opts_.force);
    if(rv < 0)
      return AppError::opening_device(-rv,opts_.device);

    captcha = captcha::calculate(blkdev);
    if(opts_.captcha != captcha)
      return AppError::captcha(opts_.captcha,captcha);

    if(input_file.empty())
      input_file = BadBlockFile::filepath(blkdev);

    rv = BadBlockFile::read(input_file,badblocks);
    if(rv < 0)
      return AppError::reading_badblocks_file(-rv,input_file);

    switch(opts_.instruction)
      {
      case Options::WRITE_PSEUDO_UNCORRECTABLE_WL:
        l::write_pseudo_uncorrectable_loop(blkdev,true,badblocks);
        break;
      case Options::WRITE_PSEUDO_UNCORRECTABLE_WOL:
        l::write_pseudo_uncorrectable_loop(blkdev,false,badblocks);
        break;
      case Options::WRITE_FLAGGED_UNCORRECTABLE_WL:
        l::write_flagged_uncorrectable_loop(blkdev,true,badblocks);
        break;
      case Options::WRITE_FLAGGED_UNCORRECTABLE_WOL:
        l::write_flagged_uncorrectable_loop(blkdev,false,badblocks);
        break;
      }

    rv = blkdev.close();
    if(rv < 0)
      return AppError::closing_device(-rv,opts_.device);

    return AppError::success();
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x80(%rsp), %rdi
callq 0xcc38
leaq 0x30(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x78(%r15), %rsi
leaq 0x40(%rsp), %rdi
callq 0x4250
leaq 0x8(%r15), %r14
movzbl 0xb8(%r15), %edx
xorl $0x1, %edx
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xcdde
testl %eax, %eax
js 0xc9b7
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xd854
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %r12
movq %r12, %rsi
callq 0x4540
movq (%r12), %rdi
leaq 0x70(%rsp), %r13
cmpq %r13, %rdi
je 0xc971
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x98(%r15), %r12
movq 0xa0(%r15), %rdx
cmpq 0x28(%rsp), %rdx
jne 0xc9a5
testq %rdx, %rdx
je 0xca31
movq 0x20(%rsp), %rsi
movq (%r12), %rdi
callq 0x44c0
testl %eax, %eax
je 0xca31
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe2ca
jmp 0xc9c6
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xdf2e
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xc9dc
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xc9f3
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x44b0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xca0f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x80(%rsp), %rdi
callq 0xcc6a
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x48(%rsp)
jne 0xca73
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4bcc
leaq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %r12
movq %r12, %rsi
callq 0x4540
movq (%r12), %rdi
cmpq %r13, %rdi
je 0xca73
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x4cf8
testl %eax, %eax
js 0xcab8
movl (%r15), %ecx
addl $-0xd, %ecx
cmpl $0x3, %ecx
ja 0xcae3
movb $0x1, %al
leaq 0x9e70(%rip), %rdx      # 0x16908
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %eax, %eax
movzbl %al, %esi
leaq 0x80(%rsp), %rdi
movq %rsp, %rdx
callq 0xcbc4
jmp 0xcae3
negl %eax
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
movl %eax, %esi
callq 0xe0fc
jmp 0xc9c6
xorl %eax, %eax
movzbl %al, %esi
leaq 0x80(%rsp), %rdi
movq %rsp, %rdx
callq 0xcb7d
leaq 0x80(%rsp), %rdi
callq 0xcdec
testl %eax, %eax
js 0xcb01
movq %rbx, %rdi
callq 0xdce4
jmp 0xc9c6
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xdfc8
jmp 0xc9c6
jmp 0xcb17
movq %rax, %rbx
jmp 0xcb35
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xcb35
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xcb4c
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x44b0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xcb68
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x80(%rsp), %rdi
callq 0xcc6a
movq %rbx, %rdi
callq 0x46f0