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

  auto &file = argv[1], &attr = argv[2];
  std::vector<char> payload;

  // load the data

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

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

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

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

  // return the data

  std::cout.write(payload.data(), payload.size());
  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
cmpl $0x3, %edi
jne 0x13b4
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movl $0x1000, %r15d          # imm = 0x1000
movq %r14, %rdi
movq %r15, %rsi
callq 0x1564
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
subq %rdx, %rcx
callq 0x1050
testq %rax, %rax
jns 0x13fd
callq 0x1040
cmpl $0x22, (%rax)
jne 0x144a
leaq (%r15,%r15), %rax
cmpq $0x3200001, %r15        # imm = 0x3200001
movq %rax, %r15
jb 0x130d
movq 0x2c90(%rip), %rdi      # 0x3ff0
leaq 0xccc(%rip), %rsi       # 0x2033
movl $0x22, %edx
callq 0x1140
movq 0x2c78(%rip), %rdi      # 0x3ff0
movl $0x6400000, %esi        # imm = 0x6400000
callq 0x10b0
movq %rax, %r14
leaq 0xcca(%rip), %rsi       # 0x2056
movl $0x8, %edx
movq %rax, %rdi
callq 0x1140
movl $0x1, %ebx
leaq 0xcba(%rip), %rsi       # 0x205f
movl $0x1a, %edx
movq %r14, %rdi
callq 0x1140
jmp 0x1425
movq 0x2c35(%rip), %rbx      # 0x3ff0
leaq 0xc42(%rip), %rsi       # 0x2004
movl $0x25, %edx
movq %rbx, %rdi
callq 0x1140
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10c0
movl $0x1, %ebx
jmp 0x143c
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1564
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
xorl %ebx, %ebx
movq 0x2bb0(%rip), %rdi      # 0x3fd0
callq 0x1160
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x143c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %r12
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1590
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xbba(%rip), %rsi       # 0x202a
leaq 0xbbb(%rip), %rdx       # 0x2032
leaq 0x28(%rsp), %rdi
callq 0x16d2
movl (%r12), %ebx
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x2b5a(%rip), %rdi      # 0x3ff0
callq 0x1140
movq %rax, %r14
leaq 0xbb8(%rip), %rsi       # 0x205d
movl $0x1, %edx
movq %rax, %rdi
callq 0x1140
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x1140
movq %rax, %r14
leaq 0xbac(%rip), %rsi       # 0x207a
movl $0x2, %edx
movq %rax, %rdi
callq 0x1140
movl %ebx, %edi
callq 0x1060
movq %r14, %rdi
movq %rax, %rsi
callq 0x1110
movq %rax, %rdi
callq 0x1080
movl $0x1, %edi
callq 0x1150
jmp 0x1541
jmp 0x1541
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1522
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x1130
jmp 0x1522
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1544
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x1130
jmp 0x1544
jmp 0x1541
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x155b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
movq %rbx, %rdi
callq 0x1190
nop