// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movl %esi, %ebx
movl %edi, %ebp
leaq 0xb56d(%rip), %rsi      # 0xf4ac
xorl %edi, %edi
callq 0x32a0
movups 0xb55f(%rip), %xmm0     # 0xf4ac
movups %xmm0, 0xb594(%rip)     # 0xf4e8
movups 0xb561(%rip), %xmm0     # 0xf4bc
movups %xmm0, 0xb596(%rip)     # 0xf4f8
movups 0xb563(%rip), %xmm0     # 0xf4cc
movups %xmm0, 0xb598(%rip)     # 0xf508
movups 0xb561(%rip), %xmm0     # 0xf4d8
movups %xmm0, 0xb596(%rip)     # 0xf514
leaq 0xb563(%rip), %rdx      # 0xf4e8
andb $-0xb, 0xb568(%rip)     # 0xf4f4
xorl %edi, %edi
xorl %esi, %esi
callq 0x3330
callq 0x3b3f
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movq %r15, (%rsp)
movq %r15, %rsi
callq 0x3350
movl %ebp, %edi
movl %ebx, %esi
movq %r14, %rdx
callq 0x3cc1
leaq 0x48(%rsp), %rdi
callq 0x34d8
movl 0xb2b2(%rip), %esi      # 0xf27c
movl 0xb2b0(%rip), %edx      # 0xf280
leaq 0x70b1(%rip), %rbp      # 0xb088
movq %rbp, %rdi
xorl %eax, %eax
callq 0x3050
movl $0x1, 0xb299(%rip)      # 0xf284
andl $0x0, 0xb4b6(%rip)      # 0xf4a8
callq 0x3b3f
leaq 0x28(%rsp), %r15
pushq $0x1
popq %r12
callq 0x3360
cmpb $0xa, %al
je 0x40ec
movsbl %al, %eax
cmpl $0x41, %eax
je 0x4188
cmpl $0x42, %eax
je 0x4043
cmpl $0x3a, %eax
je 0x436c
cmpl $0x44, %eax
je 0x433f
movl $0x0, %ebx
cmpl $0x7f, %eax
jne 0x4335
jmp 0x433f
movl 0xb517(%rip), %eax      # 0xf560
movl 0xb229(%rip), %ecx      # 0xf278
movl 0xb22f(%rip), %esi      # 0xf284
cmpl %ecx, %eax
jle 0x41f5
movl 0xb445(%rip), %edx      # 0xf4a8
addl %esi, %edx
movl $0x0, %ebx
cmpl %eax, %edx
jge 0x4335
cmpl %ecx, %esi
jl 0x4202
movl 0xb1fc(%rip), %esi      # 0xf27c
movl 0xb1fa(%rip), %edx      # 0xf280
movq %rbp, %rdi
xorl %eax, %eax
callq 0x3050
movl 0xb412(%rip), %ebx      # 0xf4a8
incl %ebx
movl %ebx, 0xb40a(%rip)      # 0xf4a8
movq %rbp, %r14
movl 0xb1d1(%rip), %ebp      # 0xf278
addl %ebx, %ebp
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x3350
movl %ebx, %edi
movl %ebp, %esi
movq %r13, %rdx
callq 0x3cc1
movq %r13, %rdi
callq 0x34d8
movl 0xb1a4(%rip), %eax      # 0xf278
movl 0xb1a2(%rip), %ecx      # 0xf27c
leal (%rax,%rcx), %esi
decl %esi
xorl %ebx, %ebx
movq %r14, %rdi
pushq $0x1
popq %rdx
jmp 0x429f
movq 0xaead(%rip), %rax      # 0xefa0
movq (%rax), %rdi
callq 0x32c0
movq 0xaec6(%rip), %rdi      # 0xefc8
leaq 0xb32f(%rip), %rsi      # 0xf438
callq 0x31f0
movslq 0xb16f(%rip), %rax      # 0xf284
movslq 0xb38c(%rip), %rcx      # 0xf4a8
addq %rax, %rcx
movq 0xb71a(%rip), %rax      # 0xf840
shlq $0x5, %rcx
leaq (%rax,%rcx), %rsi
addq $-0x20, %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x6f58(%rip), %rdx      # 0xb099
callq 0xa27a
movq %r15, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0xa25b
movq %r14, %rdi
callq 0x34d8
xorl %ebx, %ebx
movslq %ebx, %rsi
cmpq %rsi, 0x30(%rsp)
jbe 0x41b3
movq 0x28(%rsp), %rax
cmpb $0x20, (%rax,%rsi)
jne 0x4184
movq %r15, %rdi
movq %r12, %rdx
pushq $0x5c
popq %rcx
callq 0x34c0
incl %ebx
incl %ebx
jmp 0x415f
movl 0xb0f6(%rip), %eax      # 0xf284
cmpl $0x2, %eax
jl 0x4225
leal -0x1(%rax), %ecx
movl %ecx, 0xb0e4(%rip)      # 0xf284
movl 0xb0d6(%rip), %ecx      # 0xf27c
leal (%rax,%rcx), %esi
addl $-0x2, %esi
xorl %ebx, %ebx
movq %rbp, %rdi
jmp 0x4216
callq 0x30a0
movq %r14, %rdi
movl %eax, %r14d
movq %r15, %rsi
callq 0x3350
testl %r14d, %r14d
je 0x42ae
movl $0x1, 0xb0ab(%rip)      # 0xf284
andl $0x0, 0xb2c8(%rip)      # 0xf4a8
movl 0xb092(%rip), %esi      # 0xf278
xorl %edi, %edi
callq 0x442e
pushq $0x1
popq %rbx
jmp 0x431e
movl $0x0, %ebx
cmpl %eax, %esi
jge 0x4335
leal 0x1(%rsi), %eax
movl %eax, 0xb079(%rip)      # 0xf284
addl 0xb06b(%rip), %esi      # 0xf27c
xorl %ebx, %ebx
movq %rbp, %rdi
pushq $0x1
popq %rdx
xorl %eax, %eax
callq 0x3050
jmp 0x4335
cmpl $0x0, 0xb27c(%rip)      # 0xf4a8
movl $0x0, %ebx
je 0x4335
movl 0xb03f(%rip), %esi      # 0xf27c
movl 0xb03d(%rip), %edx      # 0xf280
movq %rbp, %rdi
xorl %eax, %eax
callq 0x3050
movl 0xb255(%rip), %ebx      # 0xf4a8
decl %ebx
movl %ebx, 0xb24d(%rip)      # 0xf4a8
movq %rbp, %r14
movl 0xb014(%rip), %ebp      # 0xf278
addl %ebx, %ebp
leaq 0x88(%rsp), %r13
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x3350
movl %ebx, %edi
movl %ebp, %esi
movq %r13, %rdx
callq 0x3cc1
movq %r13, %rdi
callq 0x34d8
movl 0xafe8(%rip), %esi      # 0xf27c
movl 0xafe6(%rip), %edx      # 0xf280
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x3050
movq %r14, %rbp
jmp 0x4335
movq %r12, %r13
leaq 0x6e20(%rip), %rdi      # 0xb0d8
movl $0x442, %esi            # imm = 0x442
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x31a0
movl %eax, %ebx
leaq 0x6e0e(%rip), %rdi      # 0xb0e0
cmpl $-0x1, %eax
je 0x4314
movq 0xacf2(%rip), %rax      # 0xefd0
movq (%rax), %rdi
callq 0x3280
movl %eax, %edi
callq 0x33a0
movl %eax, %r12d
movq 0xacd9(%rip), %rax      # 0xefd0
movq (%rax), %rdi
callq 0x3280
movl %ebx, %edi
movl %eax, %esi
callq 0x3220
leaq 0x6de2(%rip), %rdi      # 0xb0f1
cmpl $-0x1, %eax
jne 0x437e
callq 0x31d0
xorl %ebx, %ebx
movq %r13, %r12
leaq 0x8(%rsp), %rdi
callq 0x34d8
movq %r15, %rdi
callq 0x34d8
testl %r14d, %r14d
je 0x436c
testl %ebx, %ebx
je 0x4000
jmp 0x436c
movq 0xac5a(%rip), %rax      # 0xefa0
movq (%rax), %rdi
callq 0x32c0
movl $0x1, 0xaf2c(%rip)      # 0xf284
andl $0x0, 0xb149(%rip)      # 0xf4a8
movl 0xaf13(%rip), %esi      # 0xf278
xorl %edi, %edi
callq 0x442e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdx
leaq 0x6d7e(%rip), %rdi      # 0xb108
leaq 0x6d80(%rip), %rsi      # 0xb111
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3310
movq 0xac2f(%rip), %rax      # 0xefd0
movq (%rax), %rdi
callq 0x32c0
movl %ebx, %edi
callq 0x34b0
movq 0xac19(%rip), %rax      # 0xefd0
movq (%rax), %rdi
callq 0x3280
movl %r12d, %edi
movl %eax, %esi
callq 0x3220
movl %r12d, %edi
callq 0x34b0
pushq $0x1
popq %rdi
callq 0x32f0
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x4421
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x4421
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x4421
jmp 0x440a
jmp 0x440a
jmp 0x4419
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x4421
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x34d8
jmp 0x441c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x34d8
movq %rbx, %rdi
callq 0x3430