// File: /workspace/github_cpp_makefile_star2_O2/AsherGlick[P]CommentHeader/source/./pipein.h
// Function: copyFromClipboard[abi:cxx11]()
std::string copyFromClipboard() {

    std::ifstream xclipBinary("/usr/bin/xclip");
    if (!xclipBinary.good()){
        std::cout << "Error: Cannot Find XClip binary" << std::endl;
        return "";
    }

    int fd2[2];
    pid_t pid;
    // Create a pipe
    if ( (pipe(fd2) < 0) ) return "PIPE ERROR (PARENT)"; // Pipe Error (parent)
    // fork into a new process
    if ( (pid = fork()) < 0 ) return "FORK ERROR (PARENT)"; // Fork Error (parent)

    // Child process
    else  if (pid == 0) {

        close(fd2[0]);
        
        if (fd2[1] != STDOUT_FILENO) {
            if (dup2(fd2[1], STDOUT_FILENO) != STDOUT_FILENO) {
                std::cerr << "CHILD: dup2 error to stdout" << std::endl;
            }
            close(fd2[1]);
        }
        
        char *args[] = { (char*)"xclip" , (char*)"-out", (char*)0};
        if ( execv("/usr/bin/xclip", args) < 0) {
            std::cerr << "CHILD: system error" << std::endl;
            return "SYSTEM ERROR (CHILD)";
        }
        return "";
    }

    // PARENT process
    else {
        close(fd2[1]);

        #define LINEBUFFERSIZE 100
        char lineBuffer[LINEBUFFERSIZE];
        std::string output;
        int rv;

        while(true) {
            if ((rv = read(fd2[0], lineBuffer, LINEBUFFERSIZE)) < 0 ) {
                std::cerr << "READ ERROR FROM PIPE" << std::endl;
            }
            // Pipe Closed
            else if (rv == 0) {
                break;
            }

            std::string trimmedString(lineBuffer, rv);
            output += trimmedString;
        }

        close(fd2[0]);
        return output;
    }

    return ""; // Error.
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, -0x30(%rbp)
leaq 0x4dbc(%rip), %rsi      # 0xc1ed
leaq -0x2c8(%rbp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x33b0
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x2a8(%rbp,%rax)
je 0x74a8
movq 0xab6d(%rip), %rdi      # 0x11fc8
leaq 0x4d9a(%rip), %rsi      # 0xc1fc
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x5737(%rip), %rsi      # 0xcbad
leaq -0xc0(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x30f0
leaq -0x2c8(%rbp), %rdi
callq 0x3090
movq -0x30(%rbp), %rax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x3300
testl %eax, %eax
js 0x7563
callq 0x30a0
testl %eax, %eax
js 0x758c
je 0x75a8
movl -0x34(%rbp), %edi
callq 0x33f0
movq -0x30(%rbp), %rcx
leaq 0x10(%rcx), %rax
movq %rax, (%rcx)
andq $0x0, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
leaq -0x48(%rbp), %rbx
leaq -0xc0(%rbp), %r14
pushq $0x64
popq %r15
leaq -0x58(%rbp), %r12
movl -0x38(%rbp), %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3320
movq %rax, %r13
testl %r13d, %r13d
js 0x7515
jne 0x7530
jmp 0x757f
movq 0xaad4(%rip), %rdi      # 0x11ff0
leaq 0x4d70(%rip), %rsi      # 0xc293
callq 0x3260
movq %rax, %rdi
callq 0x3130
movslq %r13d, %rax
movq %rbx, -0x58(%rbp)
leaq (%rax,%rbp), %rdx
addq $-0xc0, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0xa662
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x33e0
movq %r12, %rdi
callq 0x3120
jmp 0x74fb
leaq 0x4cb7(%rip), %rsi      # 0xc221
leaq -0xc0(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x30f0
jmp 0x7486
movl -0x38(%rbp), %edi
callq 0x33f0
jmp 0x7486
leaq 0x4ca2(%rip), %rsi      # 0xc235
leaq -0xc0(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x30f0
jmp 0x7486
movl -0x38(%rbp), %edi
callq 0x33f0
movl -0x34(%rbp), %edi
cmpl $0x1, %edi
je 0x75e8
pushq $0x1
popq %rsi
callq 0x3240
cmpl $0x1, %eax
je 0x75e0
movq 0xaa24(%rip), %rdi      # 0x11ff0
leaq 0x4c76(%rip), %rsi      # 0xc249
callq 0x3260
movq %rax, %rdi
callq 0x3130
movl -0x34(%rbp), %edi
callq 0x33f0
movq 0xa7b1(%rip), %rax      # 0x11da0
leaq -0xc0(%rbp), %rsi
movq %rax, 0x10(%rsi)
movaps 0xa78f(%rip), %xmm0     # 0x11d90
movaps %xmm0, (%rsi)
leaq 0x4be2(%rip), %rdi      # 0xc1ed
callq 0x3220
testl %eax, %eax
js 0x762d
leaq 0x5592(%rip), %rsi      # 0xcbad
leaq -0x58(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x30f0
jmp 0x7486
movq 0xa9bc(%rip), %rdi      # 0x11ff0
leaq 0x4c2f(%rip), %rsi      # 0xc26a
callq 0x3260
movq %rax, %rdi
callq 0x3130
leaq 0x4c2f(%rip), %rsi      # 0xc27e
leaq -0x58(%rbp), %rdx
movq -0x30(%rbp), %rdi
callq 0x30f0
jmp 0x7486
jmp 0x7671
jmp 0x7671
jmp 0x7671
jmp 0x7671
jmp 0x7686
jmp 0x7671
jmp 0x7671
jmp 0x7671
movq %rax, %r14
jmp 0x7692
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x3120
jmp 0x7689
jmp 0x7686
movq %rax, %r14
movq -0x30(%rbp), %rdi
callq 0x3120
leaq -0x2c8(%rbp), %rdi
callq 0x3090
movq %r14, %rdi
callq 0x3390