// File: AsherGlick[P]CommentHeader/source/./pipein.h
// Function: copyToClipboard(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int copyToClipboard(std::string contents)
{
    std::ifstream xclipBinary("/usr/bin/xclip");
    if (!xclipBinary.good()){
        std::cout << "Error: Cannot Find XClip binary" << std::endl;
        return -1;
    }
    int fd1[2];
    pid_t pid;
    // Create a pipe
    if ( (pipe(fd1) < 0) ) return -2; // Pipe Error (parent)
    // fork into a new process
    if ( (pid = fork()) < 0 ) return -3; // Fork Error (parent)
    
    // Child process
    else  if (pid == 0) {
        close(fd1[1]);
        if (fd1[0] != STDIN_FILENO) {
            if (dup2(fd1[0], STDIN_FILENO) != STDIN_FILENO) return -5; // Dup2 error (Child)
            close(fd1[0]);
        }
        char *args[] = { (char*)"xclip" , (char*)"-sel", (char*)"clip", (char*)0};
        if ( execv("/usr/bin/xclip", args) < 0) return -4; //execv error (CHILD)
        return 0;
    }

    // PARENT process
    else {
        close(fd1[0]);
        if ( write(fd1[1], contents.c_str(), contents.size() ) != (int)contents.size() ) return -6; // WRITE ERROR FROM PIPE (PARENT)
        close(fd1[1]);
        return 0;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x270(%rbp)
movq %rdi, -0x10(%rbp)
leaq 0xa27c(%rip), %rsi      # 0x18239
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x3480
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x3440
movb %al, -0x261(%rbp)
jmp 0xdfee
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0xe064
jmp 0xdffa
movq 0x12fbf(%rip), %rdi     # 0x20fc0
leaq 0xa240(%rip), %rsi      # 0x18248
callq 0x32a0
movq %rax, -0x278(%rbp)
jmp 0xe016
movq -0x278(%rbp), %rdi
movq 0x12f8c(%rip), %rsi     # 0x20fb0
callq 0x32e0
jmp 0xe02b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x228(%rbp)
jmp 0xe22c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x30a0
jmp 0xe244
leaq -0x230(%rbp), %rdi
callq 0x3390
cmpl $0x0, %eax
jge 0xe08b
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x228(%rbp)
jmp 0xe22c
callq 0x30b0
movl %eax, -0x234(%rbp)
cmpl $0x0, %eax
jge 0xe0b1
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
movl $0x1, -0x228(%rbp)
jmp 0xe22c
cmpl $0x0, -0x234(%rbp)
jne 0xe187
movl -0x22c(%rbp), %edi
callq 0x34b0
jmp 0xe0cb
cmpl $0x0, -0x230(%rbp)
je 0xe10b
movl -0x230(%rbp), %edi
xorl %esi, %esi
callq 0x3260
cmpl $0x0, %eax
je 0xe0fc
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
movl $0x1, -0x228(%rbp)
jmp 0xe22c
movl -0x230(%rbp), %edi
callq 0x34b0
jmp 0xe109
jmp 0xe10b
movq 0x12c4e(%rip), %rax     # 0x20d60
movq %rax, -0x260(%rbp)
movq 0x12c48(%rip), %rax     # 0x20d68
movq %rax, -0x258(%rbp)
movq 0x12c42(%rip), %rax     # 0x20d70
movq %rax, -0x250(%rbp)
movq 0x12c3c(%rip), %rax     # 0x20d78
movq %rax, -0x248(%rbp)
leaq -0x260(%rbp), %rsi
leaq 0xa0e8(%rip), %rdi      # 0x18239
callq 0x3240
cmpl $0x0, %eax
jge 0xe171
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
movl $0x1, -0x228(%rbp)
jmp 0xe22c
movl $0x0, -0x4(%rbp)
movl $0x1, -0x228(%rbp)
jmp 0xe22c
movl -0x230(%rbp), %edi
callq 0x34b0
jmp 0xe194
movq -0x270(%rbp), %rdi
movl -0x22c(%rbp), %eax
movl %eax, -0x28c(%rbp)
callq 0x3120
movq -0x270(%rbp), %rdi
movq %rax, -0x288(%rbp)
callq 0x31e0
movl -0x28c(%rbp), %edi
movq -0x288(%rbp), %rsi
movq %rax, %rdx
callq 0x30e0
movq %rax, -0x280(%rbp)
jmp 0xe1dd
movq -0x270(%rbp), %rdi
callq 0x31e0
movq %rax, %rcx
movq -0x280(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0xe20e
movl $0xfffffffa, -0x4(%rbp) # imm = 0xFFFFFFFA
movl $0x1, -0x228(%rbp)
jmp 0xe22c
movl -0x22c(%rbp), %edi
callq 0x34b0
jmp 0xe21b
movl $0x0, -0x4(%rbp)
movl $0x1, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x30a0
movl -0x4(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x220(%rbp), %rdi
callq 0x3460