// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x78(%rsp), %rdi
callq 0xa986
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x28(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x78(%r15), %rsi
leaq 0x18(%rsp), %rdi
callq 0x4260
leaq 0x8(%r15), %r14
movzbl 0xb8(%r15), %edx
xorl $0x1, %edx
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xab22
testl %eax, %eax
js 0xa790
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xb418
leaq 0x38(%rsp), %r13
leaq 0x58(%rsp), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x4550
movq %r12, %rdi
callq 0x4200
leaq 0x98(%r15), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x5c59
testb %al, %al
je 0xa7a4
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xba3c
jmp 0xa863
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xb82c
jmp 0xa863
cmpq $0x0, 0x20(%rsp)
jne 0xa7d5
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4b6c
leaq 0x18(%rsp), %rdi
leaq 0x58(%rsp), %r12
movq %r12, %rsi
callq 0x4550
movq %r12, %rdi
callq 0x4200
leaq 0x18(%rsp), %rdi
movq %rsp, %rsi
callq 0x4c35
testl %eax, %eax
js 0xa817
movl (%r15), %ecx
addl $-0xd, %ecx
cmpl $0x3, %ecx
ja 0xa83c
movb $0x1, %al
leaq 0x8126(%rip), %rdx      # 0x12920
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %eax, %eax
movzbl %al, %esi
leaq 0x78(%rsp), %rdi
movq %rsp, %rdx
callq 0xa916
jmp 0xa83c
negl %eax
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
movl %eax, %esi
callq 0xb934
jmp 0xa863
xorl %eax, %eax
movzbl %al, %esi
leaq 0x78(%rsp), %rdi
movq %rsp, %rdx
callq 0xa8d2
leaq 0x78(%rsp), %rdi
callq 0xab30
testl %eax, %eax
js 0xa854
movq %rbx, %rdi
callq 0xb6d0
jmp 0xa863
negl %eax
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0xb884
movq %rsp, %rdi
callq 0x63d8
leaq 0x18(%rsp), %rdi
callq 0x4200
leaq 0x38(%rsp), %rdi
callq 0x4200
leaq 0x78(%rsp), %rdi
callq 0xa9b6
movq %rbx, %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0xa8a1
jmp 0xa8a1
movq %rax, %rbx
movq %rsp, %rdi
callq 0x63d8
leaq 0x18(%rsp), %rdi
callq 0x4200
leaq 0x38(%rsp), %rdi
callq 0x4200
leaq 0x78(%rsp), %rdi
callq 0xa9b6
movq %rbx, %rdi
callq 0x4730