// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdx, -0x118(%rbp)
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
leaq 0x13049(%rip), %rsi     # 0x1754c
xorl %edi, %edi
movl %edi, -0x11c(%rbp)
callq 0x33a0
movl -0x11c(%rbp), %esi
movups 0x1305b(%rip), %xmm0    # 0x17578
movups %xmm0, 0x13090(%rip)    # 0x175b4
movups 0x13041(%rip), %xmm0    # 0x1756c
movups %xmm0, 0x13076(%rip)    # 0x175a8
movups 0x13023(%rip), %xmm0    # 0x1755c
movups %xmm0, 0x13058(%rip)    # 0x17598
movups 0x13005(%rip), %xmm0    # 0x1754c
movups %xmm0, 0x1303a(%rip)    # 0x17588
leaq 0x13033(%rip), %rdx     # 0x17588
movb 0x13039(%rip), %al      # 0x17594
andb $-0x9, %al
movb %al, 0x13031(%rip)      # 0x17594
movb 0x1302b(%rip), %al      # 0x17594
andb $-0x3, %al
movb %al, 0x13023(%rip)      # 0x17594
movl %esi, %edi
callq 0x3440
callq 0x3fd0
movq -0x118(%rbp), %rsi
movl -0x4(%rbp), %eax
movl %eax, -0x110(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x10c(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x3150
movl -0x110(%rbp), %edi
movl -0x10c(%rbp), %esi
movq -0x108(%rbp), %rdx
callq 0x4190
jmp 0x45c0
leaq -0x30(%rbp), %rdi
callq 0x3628
movl 0x12d55(%rip), %esi     # 0x17324
movl 0x12d53(%rip), %edx     # 0x17328
leaq 0xda6c(%rip), %rdi      # 0x12048
movb $0x0, %al
callq 0x3070
movl $0x0, -0x44(%rbp)
movl $0x1, 0x12d38(%rip)     # 0x1732c
movl $0x0, 0x12f4a(%rip)     # 0x17548
callq 0x3fd0
callq 0x3470
movb %al, -0x3d(%rbp)
movsbl -0x3d(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x120(%rbp)
subl $0xa, %eax
je 0x4964
jmp 0x4626
movl -0x120(%rbp), %eax
subl $0x3a, %eax
je 0x4690
jmp 0x4633
movl -0x120(%rbp), %eax
subl $0x41, %eax
je 0x469c
jmp 0x4640
movl -0x120(%rbp), %eax
subl $0x42, %eax
je 0x47a1
jmp 0x4651
movl -0x120(%rbp), %eax
subl $0x44, %eax
je 0x4928
jmp 0x4662
movl -0x120(%rbp), %eax
subl $0x7f, %eax
je 0x4928
jmp 0x4cbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3628
jmp 0x4cd2
movl $0x1, -0x44(%rbp)
jmp 0x4cbc
cmpl $0x2, 0x12c89(%rip)     # 0x1732c
jl 0x46db
movl 0x12c81(%rip), %eax     # 0x1732c
addl $-0x1, %eax
movl %eax, 0x12c78(%rip)     # 0x1732c
movl 0x12c72(%rip), %esi     # 0x1732c
addl 0x12c64(%rip), %esi     # 0x17324
subl $0x1, %esi
leaq 0xd97e(%rip), %rdi      # 0x12048
movl $0x1, %edx
movb $0x0, %al
callq 0x3070
jmp 0x4cbc
cmpl $0x0, 0x12e66(%rip)     # 0x17548
je 0x479a
movl 0x12c36(%rip), %esi     # 0x17324
movl 0x12c34(%rip), %edx     # 0x17328
leaq 0xd94d(%rip), %rdi      # 0x12048
xorl %eax, %eax
callq 0x3070
movq -0x118(%rbp), %rsi
movl 0x12e39(%rip), %eax     # 0x17548
decl %eax
movl %eax, 0x12e31(%rip)     # 0x17548
movl 0x12e2b(%rip), %ecx     # 0x17548
movl %ecx, -0x130(%rbp)
movl 0x12bf7(%rip), %eax     # 0x17320
addl %ecx, %eax
movl %eax, -0x12c(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x3150
movl -0x130(%rbp), %edi
movl -0x12c(%rbp), %esi
movq -0x128(%rbp), %rdx
callq 0x4190
jmp 0x475b
leaq -0x68(%rbp), %rdi
callq 0x3628
movl 0x12bba(%rip), %esi     # 0x17324
movl 0x12bb8(%rip), %edx     # 0x17328
leaq 0xd8d1(%rip), %rdi      # 0x12048
movb $0x0, %al
callq 0x3070
jmp 0x479c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3628
jmp 0x4cd2
jmp 0x479c
jmp 0x4cbc
movl 0x12e59(%rip), %eax     # 0x17600
cmpl 0x12b73(%rip), %eax     # 0x17320
jle 0x48e2
movl 0x12b67(%rip), %eax     # 0x17320
movl 0x12b61(%rip), %ecx     # 0x17320
subl 0x12b67(%rip), %ecx     # 0x1732c
subl %ecx, %eax
addl 0x12d7b(%rip), %eax     # 0x17548
cmpl 0x12e2d(%rip), %eax     # 0x17600
jge 0x48e0
movl 0x12b4d(%rip), %eax     # 0x1732c
cmpl 0x12b3b(%rip), %eax     # 0x17320
jge 0x481d
movl 0x12b3f(%rip), %eax     # 0x1732c
addl $0x1, %eax
movl %eax, 0x12b36(%rip)     # 0x1732c
movl 0x12b30(%rip), %esi     # 0x1732c
addl 0x12b22(%rip), %esi     # 0x17324
subl $0x1, %esi
leaq 0xd83c(%rip), %rdi      # 0x12048
movl $0x1, %edx
movb $0x0, %al
callq 0x3070
jmp 0x4cbc
movl 0x12b01(%rip), %esi     # 0x17324
movl 0x12aff(%rip), %edx     # 0x17328
leaq 0xd818(%rip), %rdi      # 0x12048
xorl %eax, %eax
callq 0x3070
movq -0x118(%rbp), %rsi
movl 0x12d04(%rip), %eax     # 0x17548
incl %eax
movl %eax, 0x12cfc(%rip)     # 0x17548
movl 0x12cf6(%rip), %ecx     # 0x17548
movl %ecx, -0x140(%rbp)
movl 0x12ac2(%rip), %eax     # 0x17320
addl %ecx, %eax
movl %eax, -0x13c(%rbp)
leaq -0x88(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x3150
movl -0x140(%rbp), %edi
movl -0x13c(%rbp), %esi
movq -0x138(%rbp), %rdx
callq 0x4190
jmp 0x4893
leaq -0x88(%rbp), %rdi
callq 0x3628
movl 0x12a7b(%rip), %esi     # 0x17320
addl 0x12a79(%rip), %esi     # 0x17324
subl $0x1, %esi
leaq 0xd793(%rip), %rdi      # 0x12048
movl $0x1, %edx
movb $0x0, %al
callq 0x3070
jmp 0x48e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3628
jmp 0x4cd2
jmp 0x4923
movl 0x12a44(%rip), %eax     # 0x1732c
cmpl 0x12d12(%rip), %eax     # 0x17600
jge 0x4921
movl 0x12a36(%rip), %eax     # 0x1732c
addl $0x1, %eax
movl %eax, 0x12a2d(%rip)     # 0x1732c
movl 0x12a27(%rip), %esi     # 0x1732c
addl 0x12a19(%rip), %esi     # 0x17324
subl $0x1, %esi
leaq 0xd733(%rip), %rdi      # 0x12048
movl $0x1, %edx
movb $0x0, %al
callq 0x3070
jmp 0x4923
jmp 0x4cbc
movq 0x12669(%rip), %rax     # 0x16f98
movq (%rax), %rdi
callq 0x33c0
movl $0x1, 0x129eb(%rip)     # 0x1732c
movl $0x0, 0x12bfd(%rip)     # 0x17548
movl $0x1, -0x44(%rbp)
movl 0x129c8(%rip), %esi     # 0x17320
xorl %edi, %edi
callq 0x4ce0
jmp 0x4cbc
movq 0x1262d(%rip), %rax     # 0x16f98
movq (%rax), %rdi
callq 0x33c0
movq 0x1264e(%rip), %rdi     # 0x16fc8
leaq 0x12b57(%rip), %rsi     # 0x174d8
callq 0x3290
movl 0x129a0(%rip), %edx     # 0x1732c
movl 0x12bb6(%rip), %eax     # 0x17548
movl %eax, %ecx
movl %edx, %eax
leal -0x1(%rax,%rcx), %eax
movslq %eax, %rsi
leaq 0x12f3c(%rip), %rdi     # 0x178e0
callq 0xe230
movq %rax, %rsi
leaq 0xd6a6(%rip), %rdx      # 0x12059
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xe2a0
movq -0x148(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
callq 0xe250
jmp 0x49e2
leaq -0xc8(%rbp), %rdi
callq 0x3628
movl $0x0, -0xcc(%rbp)
movslq -0xcc(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3200
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
jae 0x4ac4
movslq -0xcc(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3600
movq %rax, -0x158(%rbp)
jmp 0x4a41
movq -0x158(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x4aae
movslq -0xcc(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
movl $0x1, %edx
movl $0x5c, %ecx
callq 0x3610
jmp 0x4a6f
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x4aae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3628
jmp 0x4cd2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4cae
jmp 0x4ab0
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x49f8
callq 0x30d0
movl %eax, -0xd0(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3150
jmp 0x4ae4
cmpl $0x0, -0xd0(%rbp)
jne 0x4c53
leaq 0xd5a0(%rip), %rdi      # 0x12098
xorl %eax, %eax
movl $0x442, %esi            # imm = 0x442
movl $0x180, %edx            # imm = 0x180
callq 0x3220
movl %eax, -0x15c(%rbp)
jmp 0x4b11
movl -0x15c(%rbp), %eax
movl %eax, -0xf4(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0xf4(%rbp), %eax
jne 0x4b64
leaq 0xd56f(%rip), %rdi      # 0x120a0
callq 0x3260
jmp 0x4b38
movl $0x1, -0xf8(%rbp)
jmp 0x4c87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3628
jmp 0x4cae
movq 0x12465(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
callq 0x3350
movl %eax, %edi
callq 0x34d0
movl %eax, -0xfc(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0x160(%rbp)
movq 0x1243d(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
callq 0x3350
movl -0x160(%rbp), %edi
movl %eax, %esi
callq 0x32c0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x4bd0
leaq 0xd4f7(%rip), %rdi      # 0x120b1
callq 0x3260
jmp 0x4bc1
movl $0x1, -0xf8(%rbp)
jmp 0x4c87
leaq -0xf0(%rbp), %rdi
callq 0x3140
movq %rax, %rdx
leaq 0xd4e2(%rip), %rdi      # 0x120c8
leaq 0xd4e4(%rip), %rsi      # 0x120d1
xorl %eax, %eax
movl %eax, %ecx
callq 0x3420
movq 0x123d3(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
callq 0x33c0
jmp 0x4c07
movl -0xf4(%rbp), %edi
callq 0x35e0
jmp 0x4c14
movl -0xfc(%rbp), %eax
movl %eax, -0x164(%rbp)
movq 0x123a9(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
callq 0x3350
movl -0x164(%rbp), %edi
movl %eax, %esi
callq 0x32c0
movl -0xfc(%rbp), %edi
callq 0x35e0
jmp 0x4c49
movl $0x1, %edi
callq 0x33f0
movl $0x1, 0x126cf(%rip)     # 0x1732c
movl $0x0, 0x128e1(%rip)     # 0x17548
movl $0x1, -0x44(%rbp)
movl 0x126ac(%rip), %esi     # 0x17320
xorl %edi, %edi
callq 0x4ce0
jmp 0x4c7d
movl $0x4, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3628
leaq -0xa8(%rbp), %rdi
callq 0x3628
movl -0xf8(%rbp), %eax
subl $0x1, %eax
je 0x4cc9
jmp 0x4cac
jmp 0x4cbc
leaq -0xa8(%rbp), %rdi
callq 0x3628
jmp 0x4cd2
cmpl $0x0, -0x44(%rbp)
je 0x4cc4
jmp 0x4cc9
jmp 0x4603
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3570
nopl (%rax,%rax)