// File: /workspace/github_c_makefile_star2_O1/sushant8421[P]create_your_own_shell/searchstring.c
// Function: Search_in_File
int Search_in_File(char *fname, char *str , char *argv) {
	FILE *fp;
	int line_num = 1;
	int find_result = 0;
	char temp[512];
	
	if((fp = fopen(fname, "r")) == NULL) {
		return(-1);
	}

	while(fgets(temp, 512, fp) != NULL) {
		if(((strstr(temp, str)) != NULL) && !(strcmp("v" , argv) == 0 || strcmp("nv" , argv) == 0)) {
			if(strcmp("n" , argv) == 0 || strcmp("nc" , argv) == 0){
				printf("%s : %d : ", fname , line_num);
			}
			printf(" %s\n", temp);
			find_result++;
		}
		else if((strstr(temp, str)) == NULL){
			if(strcmp("v" , argv) == 0 || strcmp("nv" , argv) == 0){
				printf("%s : %d : %s : \n", fname , line_num , temp);
			}
		}
		line_num++;
	}

	if(find_result == 0) {

		//printf("\nSorry, couldn't find a match.\n");
	}
	else {
		//printf("file name is : %s : " , fname) ;

		if(strcmp(argv , "c") == 0 || strcmp("nc" , argv) == 0)
			printf(" Number Of Lines Matched Are : %d \n" , find_result ) ;
		printf("\n") ;
	}

	
	//Close the file if still open.
	if(fp) {
		fclose(fp);
	}
   	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdx, %r14
movq %rsi, -0x40(%rbp)
leaq 0xda2(%rip), %rsi       # 0x2008
movq %rdi, -0x38(%rbp)
callq 0x1090
testq %rax, %rax
je 0x1398
movq %rax, %r12
leaq -0x240(%rbp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rax, %rdx
callq 0x1070
testq %rax, %rax
je 0x139f
movl $0x1, %r15d
leaq -0x240(%rbp), %r13
movl $0x0, -0x2c(%rbp)
movq %r13, %rdi
movq -0x40(%rbp), %rsi
callq 0x10c0
testq %rax, %rax
je 0x133c
movq %rax, %rbx
leaq 0xd57(%rip), %rdi       # 0x201e
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
je 0x1337
leaq 0xd43(%rip), %rdi       # 0x201d
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
je 0x1337
leaq 0xd33(%rip), %rdi       # 0x2020
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
je 0x130c
leaq 0xd22(%rip), %rdi       # 0x2022
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
jne 0x1321
leaq 0xd12(%rip), %rdi       # 0x2025
movq -0x38(%rbp), %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x1060
leaq 0xd08(%rip), %rdi       # 0x2030
movq %r13, %rsi
xorl %eax, %eax
callq 0x1060
incl -0x2c(%rbp)
jmp 0x137a
testq %rbx, %rbx
jne 0x137a
leaq 0xcdb(%rip), %rdi       # 0x201e
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
je 0x1362
leaq 0xcc7(%rip), %rdi       # 0x201d
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
jne 0x137a
leaq 0xccc(%rip), %rdi       # 0x2035
movq -0x38(%rbp), %rsi
movl %r15d, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1060
incl %r15d
movq %r13, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdx
callq 0x1070
testq %rax, %rax
jne 0x12ac
jmp 0x13a6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x13fa
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
je 0x13f0
leaq 0xc6d(%rip), %rsi       # 0x2023
movq %r14, %rdi
callq 0x1080
testl %eax, %eax
je 0x13d5
leaq 0xc59(%rip), %rdi       # 0x2022
movq %r14, %rsi
callq 0x1080
testl %eax, %eax
jne 0x13e6
leaq 0xc6a(%rip), %rdi       # 0x2046
movl %r15d, %esi
xorl %eax, %eax
callq 0x1060
movl $0xa, %edi
callq 0x1030
movq %r12, %rdi
callq 0x1050
xorl %eax, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq