// File: /workspace/github_cpp_makefile_star2_O2/SoftwearDevelopment[P]xattr_syscall_wrapper/listxattr.cc
// Function: main
int main(int argc, char** argv) {
  if (argc != 2 && argc != 3) {
    std::cerr << "USAGE: "
      << std::endl << "  getxattr [FILE] > data"
      << std::endl << "  getxattr -z [FILE] > data"
      << std::endl;
    return 1;
  }

  auto &file = argv[1];
  bool print_zeros = std::string(file) == "-z";
  if (print_zeros) file = argv[2];

  std::vector<char> payload;

  // load the data

  size_t alloc = 1024*4; // One page
  while (true) {
    payload.resize(alloc);
    ssize_t len = listxattr(file, payload.data(), payload.size());
    alloc *=2;

    if (len >= 0) { // success
      payload.resize(len);
      break;

    } else if (errno != ERANGE) { // unknown error
      fatal_errno(file, "listxattr");

    } else if (alloc > max_buf_size) { // to large
      std::cerr << "listxattr error: xattr list larger than "
                << max_buf_size << " bytes. "
                << "Refusing to allocate more.";
      return 1;
    }
  }

  if (print_zeros)
    std::cout.write(payload.data(), payload.size());
  else
    print_with_newline(payload.data(), payload.data() + payload.size(),
                       std::cout);;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
addl $-0x4, %edi
cmpl $-0x3, %edi
ja 0x2363
movq 0x2cd7(%rip), %rdi      # 0x4ff0
leaq 0xce4(%rip), %rsi       # 0x3004
callq 0x2140
movq %rax, %rdi
callq 0x20b0
leaq 0xcd8(%rip), %rsi       # 0x300c
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
leaq 0xcda(%rip), %rsi       # 0x3025
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20b0
pushq $0x1
popq %rbx
jmp 0x24ee
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq 0x48(%rsp), %r14
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
callq 0x2546
leaq 0xcbe(%rip), %rsi       # 0x3041
movq %r14, %rdi
callq 0x2538
movl %eax, %ebp
movq %r14, %rdi
callq 0x20a0
movb %bpl, 0xd(%rsp)
testb %bpl, %bpl
je 0x23a7
movq 0x10(%rbx), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
andq $0x0, 0x10(%r14)
movaps %xmm0, (%r14)
movl $0x1000, %r15d          # imm = 0x1000
leaq 0x48(%rsp), %r12
leaq 0x28(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x2582
movq 0x8(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
callq 0x20f0
testq %rax, %rax
jns 0x2458
addq %r15, %r15
callq 0x2030
cmpl $0x22, (%rax)
jne 0x2409
cmpq $0x6400001, %r15        # imm = 0x6400001
jb 0x23c8
jmp 0x24a3
movq %rax, %rbp
movq 0x8(%rbx), %rsi
movq %r12, %rdi
leaq 0xf(%rsp), %rdx
callq 0x2546
movq %r13, %rdi
leaq 0xc1d(%rip), %rsi       # 0x3044
leaq 0xe(%rsp), %rdx
callq 0x2546
movslq (%rbp), %rdx
movq %r12, %rdi
movq %r13, %rsi
pushq $0x1
popq %rcx
callq 0x25ae
movq %r13, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x20a0
jmp 0x23c8
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x2582
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
cmpb $0x0, 0xd(%rsp)
je 0x2487
movq 0x2b50(%rip), %rdi      # 0x4fd0
callq 0x2180
jmp 0x249f
addq %rsi, %rdx
movq 0x2b3f(%rip), %rax      # 0x4fd0
movq %rsi, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0x2619
xorl %ebx, %ebx
jmp 0x24e4
movq 0x2b46(%rip), %rdi      # 0x4ff0
leaq 0xb9d(%rip), %rsi       # 0x304e
callq 0x2140
movl $0x6400000, %esi        # imm = 0x6400000
movq %rax, %rdi
callq 0x20e0
leaq 0xbad(%rip), %rsi       # 0x3077
movq %rax, %rdi
callq 0x2140
leaq 0xba7(%rip), %rsi       # 0x3080
movq %rax, %rdi
callq 0x2140
pushq $0x1
popq %rbx
leaq 0x10(%rsp), %rdi
callq 0x274e
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2523
jmp 0x2523
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20a0
jmp 0x2515
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20a0
jmp 0x2526
jmp 0x2523
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x274e
movq %rbx, %rdi
callq 0x21b0