// File: /workspace/github_cpp_makefile_star2_O1/trapexit[P]bbf/src/bbf_filethrash.cpp
// Function: bbf::filethrash(Options const&)
AppError
  filethrash(const Options &opts_)
  {
    int rv;
    int cores;
    FileThrashState state;
    struct statfs vfs;
    std::vector<pthread_t> threads;

    printf("Creating file: %s\n",opts_.device.c_str());
    rv = open(opts_.device.c_str(),O_RDWR|O_CREAT|O_SYNC|O_EXCL,0666);
    if(rv == -1)
      return AppError::opening_file(errno,opts_.device);

    state.fd = rv;

    rv = fstatfs(rv,&vfs);
    if(rv == -1)
      goto error;

    state.size = (vfs.f_bavail * vfs.f_frsize);

    printf("Expanding file to fill drive: %lu bytes\n",state.size);
    rv = fallocate(state.fd,FALLOC_FL_ZERO_RANGE,0,state.size);
    if(rv == -1)
      goto error;

    cores = l::nprocs();
    printf("Spawning thrashing threads: %d (one per core)\n",cores);
    for(int i = 0; i < cores; i++)
      l::spawn_thread(l::write_thread,&state,&threads);

    printf("CTRL-C to exit...\n");
    pause();

    l::disable_signals();
    state.is_finished = true;
    for(size_t i = 0; i < threads.size(); i++)
      pthread_join(threads[i],NULL);

    close(state.fd);
    unlink(opts_.device.c_str());

    return AppError::success();

  error:
    close(state.fd);
    unlink(opts_.device.c_str());
    return AppError::opening_file(errno,opts_.device);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %rbx
movq %rdi, %r14
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq 0x8(%rsi), %rsi
leaq 0xf337(%rip), %rdi      # 0x16185
xorl %eax, %eax
callq 0x4070
movq 0x8(%rbx), %rdi
movl $0x1010c2, %esi         # imm = 0x1010C2
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x4360
addq $0x8, %rbx
cmpl $-0x1, %eax
je 0x7026
movl %eax, 0x20(%rsp)
leaq 0x50(%rsp), %rsi
movl %eax, %edi
callq 0x41b0
cmpl $-0x1, %eax
je 0x7015
movq 0x98(%rsp), %rsi
imulq 0x70(%rsp), %rsi
movq %rsi, 0x28(%rsp)
leaq 0xf2ee(%rip), %rdi      # 0x16198
xorl %eax, %eax
callq 0x4070
movl 0x20(%rsp), %edi
movq 0x28(%rsp), %rcx
movl $0x10, %esi
xorl %edx, %edx
callq 0x43b0
cmpl $-0x1, %eax
je 0x7015
movq %rbx, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movl $0x54, %edi
callq 0x42e0
movq %rax, %r15
leaq 0xf2d4(%rip), %rdi      # 0x161c1
movl %r15d, %esi
xorl %eax, %eax
callq 0x4070
testl %r15d, %r15d
jle 0x6f8b
leaq 0x148(%rsp), %r12
leaq 0xc8(%rsp), %r13
leaq 0x171(%rip), %rbp       # 0x7088
leaq 0x48(%rsp), %rbx
leaq 0x20(%rsp), %r14
movq %r12, %rdi
callq 0x4180
movl $0x2, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x40f0
movq %rbx, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x4710
testl %eax, %eax
jne 0x6f77
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x6f6c
movq 0x48(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x6f77
movq %rsp, %rdi
movq %rbx, %rdx
callq 0x4f8c
movl $0x2, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x40f0
decl %r15d
jne 0x6f21
leaq 0xf275(%rip), %rdi      # 0x16207
callq 0x4630
callq 0x40a0
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4180
movl $0x2, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x40f0
movb $0x1, 0x30(%rsp)
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x6ffa
xorl %ebx, %ebx
movq (%rax,%rbx,8), %rdi
xorl %esi, %esi
callq 0x4420
incq %rbx
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jb 0x6fd7
movl 0x20(%rsp), %edi
callq 0x4780
movq (%r15), %rdi
callq 0x4220
movq %r14, %rdi
callq 0xdd7c
jmp 0x7038
movl 0x20(%rsp), %edi
callq 0x4780
movq (%rbx), %rdi
callq 0x4220
callq 0x4060
movl (%rax), %esi
movq %r14, %rdi
movq %rbx, %rdx
callq 0xe2c8
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x704e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq %r14, %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7067
jmp 0x7067
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x7080
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x44b0
movq %rbx, %rdi
callq 0x46f0