// File: /workspace/github_cpp_makefile_star2_O1/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 0x13cf
movq 0x2ce3(%rip), %rbx      # 0x3ff0
leaq 0xcf0(%rip), %rsi       # 0x2004
movl $0x7, %edx
movq %rbx, %rdi
callq 0x1150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10c0
movq %rax, %rbx
leaq 0xcba(%rip), %rsi       # 0x200c
movl $0x18, %edx
movq %rax, %rdi
callq 0x1150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10c0
movq %rax, %rbx
leaq 0xc95(%rip), %rsi       # 0x2025
movl $0x1b, %edx
movq %rax, %rdi
callq 0x1150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10c0
movl $0x1, %r13d
jmp 0x1553
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
leaq 0x28(%rsp), %r14
leaq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x167e
leaq 0xc52(%rip), %rsi       # 0x2041
movq %r14, %rdi
callq 0x1050
movl %eax, %ebp
movq (%r14), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x1413
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x1140
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
jne 0x1423
movq 0x10(%rbx), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
xorl %r13d, %r13d
movl $0x1000, %r15d          # imm = 0x1000
movq 0x2ba9(%rip), %r12      # 0x3ff0
movq %r14, %rdi
movq %r15, %rsi
callq 0x16bc
movq 0x8(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
callq 0x10d0
addq %r15, %r15
testq %rax, %rax
js 0x1482
movl $0x3, %ebp
movq %r14, %rdi
movq %rax, %rsi
callq 0x16bc
jmp 0x14f2
callq 0x1040
cmpl $0x22, (%rax)
jne 0x1565
xorl %ebp, %ebp
cmpq $0x6400001, %r15        # imm = 0x6400001
jb 0x14f2
movl $0x28, %edx
movq %r12, %rdi
leaq 0xba4(%rip), %rsi       # 0x204e
callq 0x1150
movl $0x6400000, %esi        # imm = 0x6400000
movq %r12, %rdi
callq 0x10b0
movq %rax, %rbp
movl $0x8, %edx
movq %rax, %rdi
leaq 0xba9(%rip), %rsi       # 0x2077
callq 0x1150
movl $0x1, %r13d
movl $0x1a, %edx
movq %rbp, %rdi
leaq 0xb98(%rip), %rsi       # 0x2080
callq 0x1150
movl $0x1, %ebp
testl %ebp, %ebp
je 0x1447
cmpl $0x3, %ebp
jne 0x153c
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
cmpl $0x0, 0xc(%rsp)
je 0x152a
addq %rsi, %rax
movq 0x2ab3(%rip), %rdx      # 0x3fd0
movq %rsi, %rdi
movq %rax, %rsi
callq 0x16e8
jmp 0x1539
movq 0x2a9f(%rip), %rdi      # 0x3fd0
movq %rax, %rdx
callq 0x1170
xorl %r13d, %r13d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1553
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1140
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbp
movq 0x8(%rbx), %rsi
leaq 0x28(%rsp), %rdi
leaq 0xb(%rsp), %rdx
callq 0x167e
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xab9(%rip), %rsi       # 0x2044
leaq 0xabb(%rip), %rdx       # 0x204d
leaq 0x48(%rsp), %rdi
callq 0x17a0
movl (%rbp), %ebx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x2a40(%rip), %rdi      # 0x3ff0
callq 0x1150
movq %rax, %r14
leaq 0xabf(%rip), %rsi       # 0x207e
movl $0x1, %edx
movq %rax, %rdi
callq 0x1150
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r14, %rdi
callq 0x1150
movq %rax, %r14
leaq 0xa21(%rip), %rsi       # 0x2009
movl $0x2, %edx
movq %rax, %rdi
callq 0x1150
movl %ebx, %edi
callq 0x1060
movq %r14, %rdi
movq %rax, %rsi
callq 0x1120
movq %rax, %rdi
callq 0x1080
movl $0x1, %edi
callq 0x1160
jmp 0x165c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x163a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x1140
jmp 0x163a
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x165f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x1140
jmp 0x165f
jmp 0x165c
jmp 0x165c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1676
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1140
movq %rbx, %rdi
callq 0x11a0