// File: /workspace/github_c_makefile_star2_O2/sushant8421[P]create_your_own_shell/my_shell.c
// Function: main
int main() {
    char **command;
    char *input;
    pid_t child_pid;
    int stat_loc;

    while (1) {
        	input = readline("cheetah@sushant>> ");

        	command = get_input(input);

        	if (!command[0]) {      /* Handle empty commands */
            		free(input);
            		free(command);
            		continue;
       		}
		if(strcmp(command[0], "exit") == 0){
			printf("\tgoodbye!!\n") ;
			exit(0) ;
		}

		if(strcmp(command[0], "SS") == 0){
			int t =  SS(command[3] , command);
		//exit(0) ;
		}

		if(strcmp(command[0], "break") == 0){
			int x ;
			pid_t ch ;
			if((ch = fork()) < 0){
    				printf("child is not created\n") ;
    			}
    			else if(ch > 0){
    				waitpid(ch, &stat_loc, WUNTRACED);
    			}
    			else{
    				if(x=execv("./break", command)<0)
    					printf("execution error in break()\n");
			}
			//exit(0) ;
		}

		if(strcmp(command[0], "cwd") == 0){
			int x ;
			pid_t ch ;
			if((ch = fork()) < 0){
    			printf("child is not created\n") ;
    		}
    		else if(ch > 0){
    			waitpid(ch, &stat_loc, WUNTRACED);
    		}
    		else{
    			if(x=execv("./cwd", command)<0)
    				printf("execution error in cwd()\n");
			}
		//exit(0) ;
		}


		if(strcmp(command[0], "move") == 0){
			int x ;
			pid_t ch ;
			if((ch = fork()) < 0){
    				printf("child is not created\n") ;
    			}
    			else if(ch > 0){
    				waitpid(ch, &stat_loc, WUNTRACED);
    			}
    			else{
    				if(x=execv("./move", command)<0)
    					printf("execution error in move()\n");
			}
			//exit(0) ;
		}
	

		if (strcmp(command[0], "help") == 0){
			child_pid = fork();
        		if (child_pid < 0) {
            			perror("Fork failed");
            			exit(1);
       	 		}

        		else if (child_pid == 0) {
            		/* Never returns if the call is successful */
				printf("\t\t ### help ####\n\n ") ;
        			printf("1.cwd - Display Current Working Directory \n Syntax : cwd (No Arguments Required)") ;
        			printf("\n\n") ;
        			printf("2.move - for moving File/Directory from Source_dir to Destination_dir \n Syntax : move [source_path] [destination_path]\n") ;
        			printf("\n3.SS - Search a given String in whole directory (Always take 4 arguments)\n ");
        			printf("Syntax : SS [options] [search_string] [directory_path]\n") ;
        			printf("options : n - position of line in the text file(line_no)\n");
        			printf("\t c - no_of_lines in which the search_string in present\n") ;
                		printf("\t v - Display those lines in which the search_string is not present\n") ;
        			printf("\t nc - for implementing both n and c options simultaneously\n\n ") ;
        			printf("4.break - Split the given file \n Syntax : break [options] [file_name_path]\n");
        			printf("options : int_value - in how many lines you want to break the file\n");
        			printf("\n5.exit -for getting out of the shell\n\n") ;

                		exit(1);
            		}


    	 		else {
            			waitpid(child_pid, &stat_loc, WUNTRACED);
        		}
		}
		
	}

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xcc9(%rip), %rbx       # 0x2044
leaq 0xcef(%rip), %r14       # 0x2071
movq %rbx, %rdi
callq 0x1080
movq %rax, %r12
movq %rax, %rdi
callq 0x121c
movq %rax, %r15
movq (%rax), %r13
testq %r13, %r13
je 0x1409
movq %r13, %rdi
leaq 0xcad(%rip), %rsi       # 0x2057
callq 0x1090
testl %eax, %eax
je 0x1537
cmpb $0x53, (%r13)
jne 0x13db
cmpb $0x53, 0x1(%r13)
jne 0x13db
cmpb $0x0, 0x2(%r13)
jne 0x13db
movq 0x18(%r15), %rdi
movq %r15, %rsi
callq 0x129d
movq (%r15), %r13
movq %r13, %rdi
leaq 0xc79(%rip), %rsi       # 0x205e
callq 0x1090
testl %eax, %eax
jne 0x1443
callq 0x1110
testl %eax, %eax
js 0x141e
je 0x142c
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x10c0
jmp 0x1443
movq %r12, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
jmp 0x1382
leaq 0xdaa(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x1443
leaq 0xc29(%rip), %rdi       # 0x205c
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x1516
movq (%r15), %rdi
leaq 0xc19(%rip), %rsi       # 0x2066
callq 0x1090
testl %eax, %eax
jne 0x1496
callq 0x1110
testl %eax, %eax
js 0x1471
je 0x147f
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x10c0
jmp 0x1496
leaq 0xd57(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x1496
leaq 0xbde(%rip), %rdi       # 0x2064
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x1522
movq (%r15), %rdi
leaq 0xbcc(%rip), %rsi       # 0x206c
callq 0x1090
testl %eax, %eax
jne 0x14e5
callq 0x1110
testl %eax, %eax
js 0x14c4
je 0x14d2
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x10c0
jmp 0x14e5
leaq 0xd04(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x14e5
leaq 0xb91(%rip), %rdi       # 0x206a
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x152e
movq (%r15), %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
jne 0x1382
callq 0x1110
testl %eax, %eax
js 0x154a
je 0x155b
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x10c0
jmp 0x1382
leaq 0xc64(%rip), %rdi       # 0x2181
jmp 0x1425
leaq 0xc73(%rip), %rdi       # 0x219c
jmp 0x1478
leaq 0xc80(%rip), %rdi       # 0x21b5
jmp 0x14cb
leaq 0xebe(%rip), %rdi       # 0x23fc
callq 0x1040
xorl %edi, %edi
callq 0x10f0
leaq 0xb25(%rip), %rdi       # 0x2076
callq 0x10d0
jmp 0x15ff
leaq 0xb20(%rip), %rdi       # 0x2082
xorl %eax, %eax
callq 0x1070
leaq 0xb26(%rip), %rdi       # 0x2096
xorl %eax, %eax
callq 0x1070
leaq 0xe7c(%rip), %rdi       # 0x23fa
callq 0x1040
leaq 0xc5a(%rip), %rdi       # 0x21e4
callq 0x1040
leaq 0xb51(%rip), %rdi       # 0x20e7
xorl %eax, %eax
callq 0x1070
leaq 0xcb7(%rip), %rdi       # 0x225b
callq 0x1040
leaq 0xce2(%rip), %rdi       # 0x2292
callq 0x1040
leaq 0xd0f(%rip), %rdi       # 0x22cb
callq 0x1040
leaq 0xd3b(%rip), %rdi       # 0x2303
callq 0x1040
leaq 0xb60(%rip), %rdi       # 0x2134
xorl %eax, %eax
callq 0x1070
leaq 0xd65(%rip), %rdi       # 0x2347
callq 0x1040
leaq 0xda4(%rip), %rdi       # 0x2392
callq 0x1040
leaq 0xddb(%rip), %rdi       # 0x23d5
callq 0x1040
pushq $0x1
popq %rdi
callq 0x10f0