// File: fhirschman[P]CANF-gp/source/./../headers/gnuplot-iostream.h
// Function: gnuplotio::GnuplotFeedbackPty::GnuplotFeedbackPty(bool)
explicit GnuplotFeedbackPty(bool debug_messages) :
		pty_fn(),
		pty_fh(NULL),
		master_fd(-1),
		slave_fd(-1)
	{
	// adapted from http://www.gnuplot.info/files/gpReadMouseTest.c
		if(0 > openpty(&master_fd, &slave_fd, NULL, NULL, NULL)) {
			perror("openpty");
			throw std::runtime_error("openpty failed");
		}
		char pty_fn_buf[1024];
		if(ttyname_r(slave_fd, pty_fn_buf, 1024)) {
			perror("ttyname_r");
			throw std::runtime_error("ttyname failed");
		}
		pty_fn = std::string(pty_fn_buf);
		if(debug_messages) {
			std::cerr << "feedback_fn=" << pty_fn << std::endl;
		}

		// disable echo
		struct termios tios;
		if(tcgetattr(slave_fd, &tios) < 0) {
			perror("tcgetattr");
			throw std::runtime_error("tcgetattr failed");
		}
		tios.c_lflag &= ~(ECHO | ECHONL);
		if(tcsetattr(slave_fd, TCSAFLUSH, &tios) < 0) {
			perror("tcsetattr");
			throw std::runtime_error("tcsetattr failed");
		}

		pty_fh = fdopen(master_fd, "r");
		if(!pty_fh) {
			throw std::runtime_error("fdopen failed");
		}
	}

// Assembly:
subq $0x4d8, %rsp            # imm = 0x4D8
movb %sil, %al
movq %rdi, 0x4d0(%rsp)
andb $0x1, %al
movb %al, 0x4cf(%rsp)
movq 0x4d0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xeca0
movq 0x48(%rsp), %rdi
leaq 0x19907(%rip), %rax     # 0x28190
addq $0x10, %rax
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, 0x40(%rsp)
callq 0x8770
movq 0x48(%rsp), %rsi
movq $0x0, 0x28(%rsi)
movl $0xffffffff, 0x30(%rsi) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x34(%rsi) # imm = 0xFFFFFFFF
movq %rsi, %rdi
addq $0x30, %rdi
addq $0x34, %rsi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rdx
movq %r8, %rcx
callq 0x8620
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jle 0xe96a
leaq 0xfb16(%rip), %rdi      # 0x1e3fd
callq 0x8410
jmp 0xe8ee
movl $0x10, %edi
callq 0x8280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x38(%rsp)
leaq 0xfafb(%rip), %rsi      # 0x1e405
callq 0x8200
jmp 0xe911
movq 0x38(%rsp), %rdi
movq 0x1a6d3(%rip), %rsi     # 0x28ff0
movq 0x1a66c(%rip), %rdx     # 0x28f90
callq 0x8910
jmp 0xec9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
jmp 0xec7a
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
callq 0x83c0
jmp 0xec7a
movq 0x48(%rsp), %rax
movl 0x34(%rax), %edi
leaq 0xb0(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x8430
cmpl $0x0, %eax
je 0xe9fa
leaq 0xfa84(%rip), %rdi      # 0x1e414
callq 0x8410
jmp 0xe997
movl $0x10, %edi
callq 0x8280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
leaq 0xfa6b(%rip), %rsi      # 0x1e41e
callq 0x8200
jmp 0xe9ba
movq 0x30(%rsp), %rdi
movq 0x1a62a(%rip), %rsi     # 0x28ff0
movq 0x1a5c3(%rip), %rdx     # 0x28f90
callq 0x8910
jmp 0xec9b
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
callq 0x83c0
jmp 0xec7a
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x8970
movq 0x28(%rsp), %rdx
leaq 0x90(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0xbd90
jmp 0xea28
movq 0x48(%rsp), %rdi
addq $0x8, %rdi
leaq 0x90(%rsp), %rsi
callq 0x8690
leaq 0x90(%rsp), %rdi
callq 0x8330
leaq 0x8f(%rsp), %rdi
callq 0x85a0
testb $0x1, 0x4cf(%rsp)
je 0xead1
movq 0x1a57f(%rip), %rdi     # 0x28fe8
leaq 0xf9bd(%rip), %rsi      # 0x1e42d
callq 0x84e0
movq %rax, 0x20(%rsp)
jmp 0xea7c
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x8, %rsi
callq 0x8450
movq %rax, 0x18(%rsp)
jmp 0xea96
movq 0x18(%rsp), %rdi
movq 0x1a4ce(%rip), %rsi     # 0x28f70
callq 0x8560
jmp 0xeaa9
jmp 0xead1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
leaq 0x8f(%rsp), %rdi
callq 0x85a0
jmp 0xec7a
movq 0x48(%rsp), %rax
movl 0x34(%rax), %edi
leaq 0x50(%rsp), %rsi
callq 0x85f0
cmpl $0x0, %eax
jge 0xeb59
leaq 0xf94b(%rip), %rdi      # 0x1e43a
callq 0x8410
jmp 0xeaf6
movl $0x10, %edi
callq 0x8280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
leaq 0xf932(%rip), %rsi      # 0x1e444
callq 0x8200
jmp 0xeb19
movq 0x10(%rsp), %rdi
movq 0x1a4cb(%rip), %rsi     # 0x28ff0
movq 0x1a464(%rip), %rdx     # 0x28f90
callq 0x8910
jmp 0xec9b
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
callq 0x83c0
jmp 0xec7a
movq 0x48(%rsp), %rax
movl 0x5c(%rsp), %ecx
andl $-0x49, %ecx
movl %ecx, 0x5c(%rsp)
movl 0x34(%rax), %edi
movl $0x2, %esi
leaq 0x50(%rsp), %rdx
callq 0x86c0
cmpl $0x0, %eax
jge 0xebf1
leaq 0xf8ce(%rip), %rdi      # 0x1e455
callq 0x8410
jmp 0xeb8e
movl $0x10, %edi
callq 0x8280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
leaq 0xf8b5(%rip), %rsi      # 0x1e45f
callq 0x8200
jmp 0xebb1
movq 0x8(%rsp), %rdi
movq 0x1a433(%rip), %rsi     # 0x28ff0
movq 0x1a3cc(%rip), %rdx     # 0x28f90
callq 0x8910
jmp 0xec9b
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
callq 0x83c0
jmp 0xec7a
movq 0x48(%rsp), %rax
movl 0x30(%rax), %edi
leaq 0xf81c(%rip), %rsi      # 0x1e41c
callq 0x8590
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x28(%rax)
cmpq $0x0, 0x28(%rax)
jne 0xec72
movl $0x10, %edi
callq 0x8280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, (%rsp)
leaq 0xf83d(%rip), %rsi      # 0x1e470
callq 0x8200
jmp 0xec3a
movq (%rsp), %rdi
movq 0x1a3ab(%rip), %rsi     # 0x28ff0
movq 0x1a344(%rip), %rdx     # 0x28f90
callq 0x8910
jmp 0xec9b
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4c0(%rsp)
movl %eax, 0x4bc(%rsp)
callq 0x83c0
jmp 0xec7a
addq $0x4d8, %rsp            # imm = 0x4D8
retq
movq 0x40(%rsp), %rdi
callq 0x8330
movq 0x48(%rsp), %rdi
callq 0xedd0
movq 0x4c0(%rsp), %rdi
callq 0x8960
nopl (%rax,%rax)