// File: /workspace/github_cpp_makefile_star2_O1/danish241194[P]Linux-Terminal-Based-File-Explorer/start_page.cpp
// Function: searchConsole(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void searchConsole(int j,int limit_y,string name){

	tcgetattr(0,&initial_settings);
	new_settings = initial_settings;

	new_settings.c_lflag &= ~ECHO;

	new_settings.c_lflag &= ~ICANON;

	tcsetattr(0, TCSANOW, &new_settings); 
	init_Search_Screen();
	print_search(j,limit_y,name);
	char ch;
	gotoxy(start_x,start_y);
	int flag=0;
	y=1;
	scroll_k = 0;
	init_Search_Screen();

	while(1){
		ch = getchar();
		int s = (int)ch;
	
	
		switch(s){
		case 58:{
			flag=1;
				break;		
			}
			case 65:
			{
					
				if(y>=2){
					y--;
					gotoxy(y+start_x-1,1);//y+2,1....new change

						break;
				}
				
				if(scroll_k!=0)
				{
	
				gotoxy(start_x,start_y);
				scroll_k=scroll_k-1;

				print_search(scroll_k,height+scroll_k,name);
				gotoxy(start_x,start_y);
				
				}
				else
				{
								
				}
				break;			
			}
			//down
			case 66:{	

				if(nn>height){
				if(height-(height-y)+scroll_k<nn){
				if(y<height){
					y++;
					gotoxy(y+start_x-1,1); //y,1....y+2
					break;
				}		
				gotoxy(start_x,start_y);
				scroll_k++;
				print_search(scroll_k,height+scroll_k,name);
				gotoxy(height+start_x-1,1);//height,1
				}
				}else{
				if(y<nn)
				{
					y++;
					gotoxy(y+start_x-1,1);//shayad y,1 ///............y+2
				}	

				}
				break;			
			}
			case 68:case 127:
				{
				fflush(stdout);		
				

				y=1;
				scroll_k=0;
								
				flag=1;
				print_dirs(0,height);break;
				
			}
			case 10:{	
				
				fflush(stdout);		
				cout<<path;
				string pathre = search_path[y+scroll_k-1]+"/"+name;
				for(int k=0;k<pathre.size();k++){
					if(pathre[k]==' '){

						pathre.insert(k,1,'\\');
						k+=1;
					}
				}
				
				pid_t pid = fork();
				string path1 = pathre;

				if (pid == 0) {		
  					
					int out = open("err.log", O_RDWR|O_CREAT|O_APPEND, 0600);
    					
  					 if (-1 == out) { perror("opening cout.log"); return ; }
    					int save_out = dup(fileno(stderr));
   					if (-1 == dup2(out, fileno(stderr))) { perror("cannot redirect stdout"); return ; }
      					
  	  			  	execl("/usr/bin/xdg-open", "xdg-open", path1.c_str(), (char *)0);
						
  	  				fflush(stderr); close(out);
  			
  	  				dup2(save_out, fileno(stderr));
   

  	  				close(save_out);
  				
  					exit(1);
				}
				y=1;
				scroll_k=0;

								
				flag=1;
				print_dirs(0,height);

			break;
			}
		}
		if(flag){
			break;
		}

	}




}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movl %edi, %r14d
leaq 0x11182(%rip), %rsi     # 0x1549c
xorl %edi, %edi
callq 0x32a0
movups 0x11174(%rip), %xmm0    # 0x1549c
movups %xmm0, 0x111a9(%rip)    # 0x154d8
movups 0x11176(%rip), %xmm0    # 0x154ac
movups %xmm0, 0x111ab(%rip)    # 0x154e8
movups 0x11178(%rip), %xmm0    # 0x154bc
movups %xmm0, 0x111ad(%rip)    # 0x154f8
movups 0x11176(%rip), %xmm0    # 0x154c8
movups %xmm0, 0x111ab(%rip)    # 0x15504
leaq 0x11178(%rip), %rdx     # 0x154d8
andb $-0xb, 0x1117d(%rip)    # 0x154e4
xorl %edi, %edi
xorl %esi, %esi
callq 0x3350
callq 0x3e11
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0xfda0
movl %r14d, %edi
movl %ebp, %esi
movq %r15, %rdx
callq 0x3fc6
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x43c6
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3260
movl 0x10ea8(%rip), %esi     # 0x15274
movl 0x10ea6(%rip), %edx     # 0x15278
leaq 0xccaf(%rip), %rdi      # 0x11088
xorl %eax, %eax
callq 0x3060
movl $0x1, 0x10e92(%rip)     # 0x1527c
movl $0x0, 0x110a4(%rip)     # 0x15498
callq 0x3e11
leaq 0x38(%rsp), %r14
leaq 0x58(%rsp), %r15
xorl %r12d, %r12d
callq 0x3370
movsbl %al, %eax
cmpl $0x41, %eax
jg 0x445e
cmpl $0xa, %eax
je 0x44b0
cmpl $0x3a, %eax
je 0x44a5
cmpl $0x41, %eax
jne 0x487d
movl 0x10e48(%rip), %eax     # 0x1527c
cmpl $0x2, %eax
jl 0x4657
leal -0x1(%rax), %ecx
movl %ecx, 0x10e36(%rip)     # 0x1527c
movl 0x10e28(%rip), %ecx     # 0x15274
leal (%rax,%rcx), %esi
addl $-0x2, %esi
leaq 0xcc2f(%rip), %rdi      # 0x11088
jmp 0x464d
cmpl $0x42, %eax
je 0x4566
cmpl $0x44, %eax
je 0x4475
cmpl $0x7f, %eax
jne 0x487d
movq 0x10b24(%rip), %rax     # 0x14fa0
movq (%rax), %rdi
callq 0x32e0
movl $0x1, 0x10dee(%rip)     # 0x1527c
movl $0x0, 0x11000(%rip)     # 0x15498
movl 0x10dd2(%rip), %esi     # 0x15270
xorl %edi, %edi
callq 0x49be
movl $0x1, %r12d
jmp 0x487d
movq 0x10ae9(%rip), %rax     # 0x14fa0
movq (%rax), %rdi
callq 0x32e0
movq 0x10f62(%rip), %rsi     # 0x15428
movq 0x10f63(%rip), %rdx     # 0x15430
movq 0x10af4(%rip), %rdi     # 0x14fc8
callq 0x32c0
movslq 0x10d9c(%rip), %rax     # 0x1527c
movslq 0x10fb1(%rip), %rcx     # 0x15498
addq %rax, %rcx
movq 0x1133f(%rip), %rax     # 0x15830
shlq $0x5, %rcx
leaq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rsp)
movq -0x20(%rax,%rcx), %rsi
movq -0x18(%rax,%rcx), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0xfda0
movq %r15, %rdi
leaq 0xcb76(%rip), %rsi      # 0x11099
callq 0x3480
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x30d0
movq %r14, 0x28(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x28(%rsp), %r15
je 0x4708
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x470f
movl 0x10fe4(%rip), %ecx     # 0x15550
movl 0x10cfe(%rip), %eax     # 0x15270
movl 0x10d04(%rip), %esi     # 0x1527c
cmpl %eax, %ecx
jle 0x462f
movl 0x10f12(%rip), %edx     # 0x15498
addl %esi, %edx
cmpl %ecx, %edx
jge 0x487d
cmpl %eax, %esi
jl 0x4637
movl 0x10cd6(%rip), %esi     # 0x15274
movl 0x10cd4(%rip), %edx     # 0x15278
leaq 0xcadd(%rip), %rdi      # 0x11088
xorl %eax, %eax
callq 0x3060
movl 0x10edf(%rip), %r14d    # 0x15498
incl %r14d
movl %r14d, 0x10ed5(%rip)    # 0x15498
movq %r15, %r13
movl 0x10ca3(%rip), %r15d    # 0x15270
addl %r14d, %r15d
movq %r13, 0x48(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rbp
movq %rbp, %rdi
callq 0xfda0
movl %r14d, %edi
movl %r15d, %esi
movq %rbp, %rdx
callq 0x3fc6
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
leaq 0x38(%rsp), %r14
movq %r13, %r15
je 0x4619
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3260
movl 0x10c51(%rip), %eax     # 0x15270
movl 0x10c4f(%rip), %ecx     # 0x15274
leal (%rax,%rcx), %esi
decl %esi
jmp 0x4452
cmpl %ecx, %esi
jge 0x487d
leal 0x1(%rsi), %eax
movl %eax, 0x10c3c(%rip)     # 0x1527c
addl 0x10c2e(%rip), %esi     # 0x15274
leaq 0xca3b(%rip), %rdi      # 0x11088
movl $0x1, %edx
jmp 0x46fc
cmpl $0x0, 0x10e3a(%rip)     # 0x15498
je 0x487d
movl 0x10c0a(%rip), %esi     # 0x15274
movl 0x10c08(%rip), %edx     # 0x15278
leaq 0xca11(%rip), %rdi      # 0x11088
xorl %eax, %eax
callq 0x3060
movl 0x10e13(%rip), %r14d    # 0x15498
decl %r14d
movl %r14d, 0x10e09(%rip)    # 0x15498
movl 0x10bda(%rip), %r15d    # 0x15270
addl %r14d, %r15d
leaq 0x78(%rsp), %r13
movq %r13, 0x68(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0xfda0
movl %r14d, %edi
movl %r15d, %esi
movq %rbp, %rdx
callq 0x3fc6
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
leaq 0x38(%rsp), %r14
leaq 0x58(%rsp), %r15
je 0x46e9
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3260
movl 0x10b85(%rip), %esi     # 0x15274
movl 0x10b83(%rip), %edx     # 0x15278
leaq 0xc98c(%rip), %rdi      # 0x11088
xorl %eax, %eax
callq 0x3060
jmp 0x487d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x4743
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3260
cmpq $0x0, 0x30(%rsp)
je 0x477d
xorl %esi, %esi
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
cmpb $0x20, (%rax,%rsi)
jne 0x4770
movl $0x1, %edx
movq %r15, %rdi
movl $0x5c, %ecx
callq 0x34b0
incl %r14d
incl %r14d
movslq %r14d, %rsi
cmpq %rsi, 0x30(%rsp)
ja 0x4750
callq 0x30a0
movl %eax, %r15d
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0xfda0
testl %r15d, %r15d
leaq 0x38(%rsp), %r14
je 0x47d9
movl $0x1, 0x10ac2(%rip)     # 0x1527c
movl $0x0, 0x10cd4(%rip)     # 0x15498
movl $0x1, %r12d
movl 0x10aa0(%rip), %esi     # 0x15270
xorl %edi, %edi
callq 0x49be
jmp 0x4840
leaq 0xc8f8(%rip), %rdi      # 0x110d8
movl $0x442, %esi            # imm = 0x442
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x31b0
movl %eax, %r13d
leaq 0xc8e5(%rip), %rdi      # 0x110e0
cmpl $-0x1, %eax
je 0x4836
movq 0x107c9(%rip), %r14     # 0x14fd0
movq (%r14), %rdi
callq 0x3280
movl %eax, %edi
callq 0x33b0
movl %eax, %ebp
movq (%r14), %rdi
callq 0x3280
movl %r13d, %edi
movl %eax, %esi
callq 0x3220
leaq 0xc8c0(%rip), %rdi      # 0x110f1
cmpl $-0x1, %eax
jne 0x48b0
callq 0x31e0
leaq 0x38(%rsp), %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x485c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3260
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x4873
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3260
testl %r15d, %r15d
je 0x4895
leaq 0x58(%rsp), %r15
xorl %ecx, %ecx
testl %r12d, %r12d
sete %al
setne %cl
movl %ecx, %r12d
testb %al, %al
jne 0x4406
jmp 0x489e
xorl %eax, %eax
leaq 0x58(%rsp), %r15
jmp 0x488b
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdx
leaq 0xc84c(%rip), %rdi      # 0x11108
leaq 0xc84e(%rip), %rsi      # 0x11111
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3330
movq 0x106fd(%rip), %rax     # 0x14fd0
movq (%rax), %rdi
callq 0x32e0
movl %r13d, %edi
callq 0x34a0
movq 0x106e6(%rip), %rax     # 0x14fd0
movq (%rax), %rdi
callq 0x3280
movl %ebp, %edi
movl %eax, %esi
callq 0x3220
movl %ebp, %edi
callq 0x34a0
movl $0x1, %edi
callq 0x3310
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x49b6
movq 0x58(%rsp), %rsi
jmp 0x49ae
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x49b6
movq 0x98(%rsp), %rsi
jmp 0x49ae
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x49b6
movq 0x78(%rsp), %rsi
jmp 0x49ae
jmp 0x4976
jmp 0x4976
jmp 0x495b
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x49b6
movq 0x18(%rsp), %rsi
jmp 0x49ae
jmp 0x4997
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x499a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x499a
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x49b6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3260
movq %rbx, %rdi
callq 0x3450