// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rsi, %r12
leaq 0xdce(%rip), %rsi       # 0x2008
movq %rdi, -0x38(%rbp)
callq 0x1080
testq %rax, %rax
je 0x13ab
movq %rax, %rbx
pushq $0x1
popq %r13
leaq -0x240(%rbp), %r14
movl $0x0, -0x2c(%rbp)
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdx
callq 0x1070
testq %rax, %rax
je 0x1372
movq %r14, %rdi
movq %r12, %rsi
callq 0x10b0
movzbl (%r15), %ecx
testq %rax, %rax
je 0x12a3
cmpl $0x76, %ecx
jne 0x12bc
cmpb $0x0, 0x1(%r15)
jne 0x1322
jmp 0x136a
cmpl $0x76, %ecx
jne 0x1338
cmpb $0x0, 0x1(%r15)
jne 0x136a
jmp 0x1352
leal -0x6e(%rcx), %eax
negl %eax
movl %eax, %edx
cmpl $0x6e, %ecx
jne 0x12d9
movzbl 0x1(%r15), %edx
subl $0x76, %edx
jne 0x12d7
movzbl 0x2(%r15), %edx
negl %edx
testl %edx, %edx
je 0x136a
movl %eax, %edx
cmpb $0x6e, %cl
jne 0x12ef
movzbl 0x1(%r15), %edx
negl %edx
testl %edx, %edx
je 0x130d
cmpb $0x6e, %cl
jne 0x1309
movzbl 0x1(%r15), %eax
subl $0x63, %eax
jne 0x1307
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
jne 0x1322
leaq 0xd09(%rip), %rdi       # 0x201d
movq -0x38(%rbp), %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1060
leaq 0xcff(%rip), %rdi       # 0x2028
movq %r14, %rsi
xorl %eax, %eax
callq 0x1060
incl -0x2c(%rbp)
jmp 0x136a
subl $0x6e, %ecx
jne 0x134c
movzbl 0x1(%r15), %ecx
subl $0x76, %ecx
jne 0x134c
movzbl 0x2(%r15), %ecx
negl %ecx
testl %ecx, %ecx
jne 0x136a
leaq 0xcd4(%rip), %rdi       # 0x202d
movq -0x38(%rbp), %rsi
movl %r13d, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1060
incl %r13d
jmp 0x1261
movl -0x2c(%rbp), %esi
testl %esi, %esi
je 0x139f
movzbl (%r15), %eax
cmpl $0x63, %eax
jne 0x13c0
cmpb $0x0, 0x1(%r15)
jne 0x1397
leaq 0xcae(%rip), %rdi       # 0x203e
xorl %eax, %eax
callq 0x1060
pushq $0xa
popq %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1050
xorl %eax, %eax
jmp 0x13ae
pushq $-0x1
popq %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl $0x6e, %eax
jne 0x13d4
movzbl 0x1(%r15), %eax
subl $0x63, %eax
jne 0x13d4
movzbl 0x2(%r15), %eax
negl %eax
testl %eax, %eax
jne 0x1397
jmp 0x1389