// File: magmastonealex[P]fbkeyboard/src/fbkeyboard.cpp
// Function: run(int, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
int run(int width, int height, int dpi, std::string fbdev, std::string tsdev, std::string prompt, bool password) {

	std::string kbfile = "tst.ppm";

  	Display screen(width, height, dpi);
  	screen.setString(prompt);
  	screen.refresh();
  	screen.write("out.ppm");
  	system((std::string("fbsplash -s out.ppm -d ") + fbdev).c_str());
  	std::string todisplay = "";
  	std::string toreturn = "";
  	Input inputSource(tsdev);
	while(1) {
		Touch t = inputSource.getNextEvent();
		char touched = screen.keyAt(t.x, t.y);
		switch(touched) {
			case 0:
				break;
			case 0x08:
				if(toreturn.length() > 0)
					toreturn.pop_back();
				break;
			case 0x0a:
				std::cout << toreturn << std::endl;
				return 0;
				break;
			default:
				toreturn += touched;
				if(password)
					todisplay += (char)0x05;
				else
					todisplay += touched;
				break;
		}
	  	screen.setString(toreturn);
	  	screen.refresh();
	  	screen.write("out.ppm");
	  	system("fbsplash -s out.ppm -d /dev/fb0");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x520, %rsp            # imm = 0x520
movq %r9, -0x4d8(%rbp)
movq %r8, -0x4d0(%rbp)
movq %rcx, -0x4c8(%rbp)
movb 0x10(%rbp), %al
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
callq 0x2340
movq -0x4c0(%rbp), %rdx
leaq 0x1087(%rip), %rsi      # 0x5282
leaq -0x50(%rbp), %rdi
callq 0x4850
jmp 0x4206
leaq -0x51(%rbp), %rdi
callq 0x2200
movl -0x4(%rbp), %esi
movl -0x8(%rbp), %edx
movl -0xc(%rbp), %ecx
leaq -0x158(%rbp), %rdi
callq 0x2570
jmp 0x4226
movq -0x4d8(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x20d0
jmp 0x423b
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x3530
jmp 0x4250
leaq -0x178(%rbp), %rdi
callq 0x2120
leaq -0x158(%rbp), %rdi
callq 0x30f0
jmp 0x426a
leaq -0x199(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x2340
movq -0x4e0(%rbp), %rdx
leaq 0xfff(%rip), %rsi       # 0x528a
leaq -0x198(%rbp), %rdi
callq 0x4850
jmp 0x4299
leaq -0x158(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x2810
jmp 0x42ae
leaq -0x198(%rbp), %rdi
callq 0x2120
leaq -0x199(%rbp), %rdi
callq 0x2200
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x2340
movq -0x4e8(%rbp), %rdx
leaq 0xfab(%rip), %rsi       # 0x5292
leaq -0x1e0(%rbp), %rdi
callq 0x4850
jmp 0x42f5
movq -0x4c8(%rbp), %rdx
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x4900
jmp 0x4311
leaq -0x1c0(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2180
jmp 0x4327
leaq -0x1c0(%rbp), %rdi
callq 0x2120
leaq -0x1e0(%rbp), %rdi
callq 0x2120
leaq -0x1e1(%rbp), %rdi
callq 0x2200
leaq -0x209(%rbp), %rdi
movq %rdi, -0x4f0(%rbp)
callq 0x2340
movq -0x4f0(%rbp), %rdx
leaq 0xd31(%rip), %rsi       # 0x509d
leaq -0x208(%rbp), %rdi
callq 0x4850
jmp 0x437a
leaq -0x209(%rbp), %rdi
callq 0x2200
leaq -0x231(%rbp), %rdi
movq %rdi, -0x4f8(%rbp)
callq 0x2340
movq -0x4f8(%rbp), %rdx
leaq 0xcf6(%rip), %rsi       # 0x509d
leaq -0x230(%rbp), %rdi
callq 0x4850
jmp 0x43b5
leaq -0x231(%rbp), %rdi
callq 0x2200
movq -0x4d0(%rbp), %rsi
leaq -0x460(%rbp), %rdi
callq 0x20d0
jmp 0x43d6
leaq -0x440(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x39a0
jmp 0x43eb
leaq -0x460(%rbp), %rdi
callq 0x2120
jmp 0x43f9
leaq -0x440(%rbp), %rdi
callq 0x3ad0
movq %rax, -0x500(%rbp)
jmp 0x440e
movq -0x500(%rbp), %rax
movq %rax, -0x468(%rbp)
movl -0x468(%rbp), %esi
movl -0x464(%rbp), %edx
leaq -0x158(%rbp), %rdi
callq 0x2ee0
movb %al, -0x501(%rbp)
jmp 0x443c
movb -0x501(%rbp), %al
movb %al, -0x469(%rbp)
movsbl -0x469(%rbp), %eax
movl %eax, -0x508(%rbp)
testl %eax, %eax
je 0x45de
jmp 0x445f
movl -0x508(%rbp), %eax
subl $0x8, %eax
je 0x45e3
jmp 0x4470
movl -0x508(%rbp), %eax
subl $0xa, %eax
je 0x4606
jmp 0x467b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x2200
jmp 0x47fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x47f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x47e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2120
jmp 0x47e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4503
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x2120
leaq -0x199(%rbp), %rdi
callq 0x2200
jmp 0x47e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x4548
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x2120
leaq -0x1e0(%rbp), %rdi
callq 0x2120
leaq -0x1e1(%rbp), %rdi
callq 0x2200
jmp 0x47e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x209(%rbp), %rdi
callq 0x2200
jmp 0x47e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x231(%rbp), %rdi
callq 0x2200
jmp 0x47db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x47cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x2120
jmp 0x47cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x47c3
jmp 0x46c4
leaq -0x230(%rbp), %rdi
callq 0x22d0
cmpq $0x0, %rax
jbe 0x4601
leaq -0x230(%rbp), %rdi
callq 0x2250
jmp 0x46c4
movq 0x29b3(%rip), %rdi      # 0x6fc0
leaq -0x230(%rbp), %rsi
callq 0x21a0
movq %rax, -0x510(%rbp)
jmp 0x4622
movq -0x510(%rbp), %rdi
movq 0x2978(%rip), %rsi      # 0x6fa8
callq 0x21e0
jmp 0x4637
leaq -0x440(%rbp), %rdi
callq 0x3a70
leaq -0x230(%rbp), %rdi
callq 0x2120
leaq -0x208(%rbp), %rdi
callq 0x2120
leaq -0x158(%rbp), %rdi
callq 0x27a0
leaq -0x50(%rbp), %rdi
callq 0x2120
xorl %eax, %eax
addq $0x520, %rsp            # imm = 0x520
popq %rbp
retq
movsbl -0x469(%rbp), %esi
leaq -0x230(%rbp), %rdi
callq 0x2130
jmp 0x4690
testb $0x1, -0x29(%rbp)
je 0x46ab
leaq -0x208(%rbp), %rdi
movl $0x5, %esi
callq 0x2130
jmp 0x46a9
jmp 0x46c2
movsbl -0x469(%rbp), %esi
leaq -0x208(%rbp), %rdi
callq 0x2130
jmp 0x46c0
jmp 0x46c2
jmp 0x46c4
leaq -0x490(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x20d0
jmp 0x46d9
leaq -0x158(%rbp), %rdi
leaq -0x490(%rbp), %rsi
callq 0x3530
jmp 0x46ee
leaq -0x490(%rbp), %rdi
callq 0x2120
leaq -0x158(%rbp), %rdi
callq 0x30f0
jmp 0x4708
leaq -0x4b1(%rbp), %rdi
movq %rdi, -0x518(%rbp)
callq 0x2340
movq -0x518(%rbp), %rdx
leaq 0xb61(%rip), %rsi       # 0x528a
leaq -0x4b0(%rbp), %rdi
callq 0x4850
jmp 0x4737
leaq -0x158(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x2810
jmp 0x474c
leaq -0x4b0(%rbp), %rdi
callq 0x2120
leaq -0x4b1(%rbp), %rdi
callq 0x2200
leaq 0xb3f(%rip), %rdi       # 0x52aa
callq 0x2180
jmp 0x4772
jmp 0x43f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x2120
jmp 0x47c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x47b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x4b0(%rbp), %rdi
callq 0x2120
leaq -0x4b1(%rbp), %rdi
callq 0x2200
leaq -0x440(%rbp), %rdi
callq 0x3a70
leaq -0x230(%rbp), %rdi
callq 0x2120
leaq -0x208(%rbp), %rdi
callq 0x2120
leaq -0x158(%rbp), %rdi
callq 0x27a0
leaq -0x50(%rbp), %rdi
callq 0x2120
movq -0x60(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)
nop