// File: /workspace/github_cpp_makefile_star2_O1/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 0xccb4
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 0xce56
testl %eax, %eax
js 0xca37
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xd8ec
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %r12
movq %r12, %rsi
callq 0x4540
movq (%r12), %rdi
leaq 0x70(%rsp), %r13
cmpq %r13, %rdi
je 0xc9f1
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x98(%r15), %r12
movq 0xa0(%r15), %rdx
cmpq 0x28(%rsp), %rdx
jne 0xca25
testq %rdx, %rdx
je 0xcab1
movq 0x20(%rsp), %rsi
movq (%r12), %rdi
callq 0x44c0
testl %eax, %eax
je 0xcab1
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe362
jmp 0xca46
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xdfc6
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xca5c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xca73
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x44b0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xca8f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x80(%rsp), %rdi
callq 0xcce6
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 0xcaf3
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 0xcaf3
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x4cf8
testl %eax, %eax
js 0xcb38
movl (%r15), %ecx
addl $-0xd, %ecx
cmpl $0x3, %ecx
ja 0xcb63
movb $0x1, %al
leaq 0x9df0(%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 0xcc41
jmp 0xcb63
negl %eax
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
movl %eax, %esi
callq 0xe194
jmp 0xca46
xorl %eax, %eax
movzbl %al, %esi
leaq 0x80(%rsp), %rdi
movq %rsp, %rdx
callq 0xcbfa
leaq 0x80(%rsp), %rdi
callq 0xce64
testl %eax, %eax
js 0xcb81
movq %rbx, %rdi
callq 0xdd7c
jmp 0xca46
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xe060
jmp 0xca46
jmp 0xcb99
jmp 0xcb99
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xcbb2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xcbc9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x44b0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xcbe5
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x44b0
leaq 0x80(%rsp), %rdi
callq 0xcce6
movq %rbx, %rdi
callq 0x46f0