// File: 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
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x300(%rbp)
movq %rdi, %rax
movq %rax, -0x2f8(%rbp)
movq %rdi, -0x8(%rbp)
leaq 0x9fc2(%rip), %rsi      # 0x18239
leaq -0x210(%rbp), %rdi
movl $0x8, %edx
callq 0x3480
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x3440
movb %al, -0x2ea(%rbp)
jmp 0xe2a8
movb -0x2ea(%rbp), %al
testb $0x1, %al
jne 0xe36d
jmp 0xe2b8
movq 0x12d01(%rip), %rdi     # 0x20fc0
leaq 0x9f82(%rip), %rsi      # 0x18248
callq 0x32a0
movq %rax, -0x308(%rbp)
jmp 0xe2d4
movq -0x308(%rbp), %rdi
movq 0x12cce(%rip), %rsi     # 0x20fb0
callq 0x32e0
jmp 0xe2e9
leaq -0x21d(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x3470
movq -0x300(%rbp), %rdi
movq -0x310(%rbp), %rdx
leaq 0xa8e8(%rip), %rsi      # 0x18bf9
callq 0x33a0
jmp 0xe318
leaq -0x21d(%rbp), %rdi
callq 0x3300
movl $0x1, -0x224(%rbp)
jmp 0xe7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0xe7f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x21d(%rbp), %rdi
callq 0x3300
jmp 0xe7f6
leaq -0x22c(%rbp), %rdi
callq 0x3390
cmpl $0x0, %eax
jge 0xe3eb
leaq -0x231(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x3470
movq -0x300(%rbp), %rdi
movq -0x318(%rbp), %rdx
leaq 0x9ec7(%rip), %rsi      # 0x1826d
callq 0x33a0
jmp 0xe3ad
leaq -0x231(%rbp), %rdi
callq 0x3300
movl $0x1, -0x224(%rbp)
jmp 0xe7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x231(%rbp), %rdi
callq 0x3300
jmp 0xe7f6
callq 0x30b0
movl %eax, -0x230(%rbp)
cmpl $0x0, %eax
jge 0xe468
leaq -0x232(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x3470
movq -0x300(%rbp), %rdi
movq -0x320(%rbp), %rdx
leaq 0x9e5e(%rip), %rsi      # 0x18281
callq 0x33a0
jmp 0xe42a
leaq -0x232(%rbp), %rdi
callq 0x3300
movl $0x1, -0x224(%rbp)
jmp 0xe7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x232(%rbp), %rdi
callq 0x3300
jmp 0xe7f6
cmpl $0x0, -0x230(%rbp)
jne 0xe633
movl -0x22c(%rbp), %edi
callq 0x34b0
jmp 0xe482
cmpl $0x1, -0x228(%rbp)
je 0xe4e2
movl -0x228(%rbp), %edi
movl $0x1, %esi
callq 0x3260
cmpl $0x1, %eax
je 0xe4d3
movq 0x12b41(%rip), %rdi     # 0x20fe8
leaq 0x9de7(%rip), %rsi      # 0x18295
callq 0x32a0
movq %rax, -0x328(%rbp)
jmp 0xe4bc
movq -0x328(%rbp), %rdi
movq 0x12ae6(%rip), %rsi     # 0x20fb0
callq 0x32e0
jmp 0xe4d1
jmp 0xe4d3
movl -0x228(%rbp), %edi
callq 0x34b0
jmp 0xe4e0
jmp 0xe4e2
movq 0x12897(%rip), %rax     # 0x20d80
movq %rax, -0x250(%rbp)
movq 0x12891(%rip), %rax     # 0x20d88
movq %rax, -0x248(%rbp)
movq 0x1288b(%rip), %rax     # 0x20d90
movq %rax, -0x240(%rbp)
leaq -0x250(%rbp), %rsi
leaq 0x9d1f(%rip), %rdi      # 0x18239
callq 0x3240
cmpl $0x0, %eax
jge 0xe5c6
movq 0x12ab9(%rip), %rdi     # 0x20fe8
leaq 0x9d80(%rip), %rsi      # 0x182b6
callq 0x32a0
movq %rax, -0x330(%rbp)
jmp 0xe544
movq -0x330(%rbp), %rdi
movq 0x12a5e(%rip), %rsi     # 0x20fb0
callq 0x32e0
jmp 0xe559
leaq -0x251(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x3470
movq -0x300(%rbp), %rdi
movq -0x338(%rbp), %rdx
leaq 0x9d49(%rip), %rsi      # 0x182ca
callq 0x33a0
jmp 0xe588
leaq -0x251(%rbp), %rdi
callq 0x3300
movl $0x1, -0x224(%rbp)
jmp 0xe7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x251(%rbp), %rdi
callq 0x3300
jmp 0xe7f6
leaq -0x252(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x3470
movq -0x300(%rbp), %rdi
movq -0x340(%rbp), %rdx
leaq 0xa60b(%rip), %rsi      # 0x18bf9
callq 0x33a0
jmp 0xe5f5
leaq -0x252(%rbp), %rdi
callq 0x3300
movl $0x1, -0x224(%rbp)
jmp 0xe7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x252(%rbp), %rdi
callq 0x3300
jmp 0xe7f6
movl -0x228(%rbp), %edi
callq 0x34b0
jmp 0xe640
movq -0x300(%rbp), %rdi
movb $0x0, -0x2c1(%rbp)
callq 0x33b0
jmp 0xe655
movl -0x22c(%rbp), %edi
leaq -0x2c0(%rbp), %rsi
movl $0x64, %edx
callq 0x33c0
movq %rax, -0x348(%rbp)
jmp 0xe675
movq -0x348(%rbp), %rax
movl %eax, -0x2c8(%rbp)
cmpl $0x0, %eax
jge 0xe6d1
movq 0x1295a(%rip), %rdi     # 0x20fe8
leaq 0x9c4a(%rip), %rsi      # 0x182df
callq 0x32a0
movq %rax, -0x350(%rbp)
jmp 0xe6a3
movq -0x350(%rbp), %rdi
movq 0x128ff(%rip), %rsi     # 0x20fb0
callq 0x32e0
jmp 0xe6b8
jmp 0xe6e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0xe7cc
cmpl $0x0, -0x2c8(%rbp)
jne 0xe6df
jmp 0xe797
jmp 0xe6e1
movslq -0x2c8(%rbp), %rax
movq %rax, -0x360(%rbp)
leaq -0x2e9(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x3470
movq -0x360(%rbp), %rdx
movq -0x358(%rbp), %rcx
leaq -0x2e8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x3310
jmp 0xe725
leaq -0x2e9(%rbp), %rdi
callq 0x3300
movq -0x300(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x3370
jmp 0xe746
leaq -0x2e8(%rbp), %rdi
callq 0x31a0
jmp 0xe653
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x2e9(%rbp), %rdi
callq 0x3300
jmp 0xe7cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x31a0
jmp 0xe7cc
movl -0x22c(%rbp), %edi
callq 0x34b0
jmp 0xe7a4
movb $0x1, -0x2c1(%rbp)
movl $0x1, -0x224(%rbp)
testb $0x1, -0x2c1(%rbp)
jne 0xe7ca
movq -0x300(%rbp), %rdi
callq 0x31a0
jmp 0xe7da
movq -0x300(%rbp), %rdi
callq 0x31a0
jmp 0xe7f6
leaq -0x210(%rbp), %rdi
callq 0x30a0
movq -0x2f8(%rbp), %rax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
leaq -0x210(%rbp), %rdi
callq 0x30a0
movq -0x218(%rbp), %rdi
callq 0x3460
nop