// File: /workspace/github_c_makefile_star2_O3/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 0xca2(%rip), %rbx       # 0x2044
leaq 0xcc8(%rip), %r14       # 0x2071
movq %rbx, %rdi
callq 0x1080
movq %rax, %r13
movq %rax, %rdi
callq 0x121c
movq %rax, %r15
movq (%rax), %r12
testq %r12, %r12
je 0x1434
movq %r12, %rdi
leaq 0xc86(%rip), %rsi       # 0x2057
callq 0x1090
testl %eax, %eax
je 0x1568
cmpb $0x53, (%r12)
jne 0x1404
cmpb $0x53, 0x1(%r12)
jne 0x1404
cmpb $0x0, 0x2(%r12)
jne 0x1404
movq 0x18(%r15), %rdi
movq %r15, %rsi
callq 0x12af
movq (%r15), %r12
movq %r12, %rdi
leaq 0xc50(%rip), %rsi       # 0x205e
callq 0x1090
testl %eax, %eax
jne 0x146e
callq 0x1110
testl %eax, %eax
js 0x1449
je 0x1457
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x146e
movq %r13, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
jmp 0x13a9
leaq 0xd7f(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x146e
leaq 0xbfe(%rip), %rdi       # 0x205c
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x1547
movq (%r15), %rdi
leaq 0xbee(%rip), %rsi       # 0x2066
callq 0x1090
testl %eax, %eax
jne 0x14c3
callq 0x1110
testl %eax, %eax
js 0x149e
je 0x14ac
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x14c3
leaq 0xd2a(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x14c3
leaq 0xbb1(%rip), %rdi       # 0x2064
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x1553
movq (%r15), %rdi
leaq 0xb9f(%rip), %rsi       # 0x206c
callq 0x1090
testl %eax, %eax
jne 0x1514
callq 0x1110
testl %eax, %eax
js 0x14f3
je 0x1501
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x1514
leaq 0xcd5(%rip), %rdi       # 0x21cf
callq 0x1040
jmp 0x1514
leaq 0xb62(%rip), %rdi       # 0x206a
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
js 0x155f
movq (%r15), %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
jne 0x13a9
callq 0x1110
testl %eax, %eax
js 0x157b
je 0x158c
movl %eax, %edi
leaq -0x2c(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x13a9
leaq 0xc33(%rip), %rdi       # 0x2181
jmp 0x1450
leaq 0xc42(%rip), %rdi       # 0x219c
jmp 0x14a5
leaq 0xc4f(%rip), %rdi       # 0x21b5
jmp 0x14fa
leaq 0xe8d(%rip), %rdi       # 0x23fc
callq 0x1040
xorl %edi, %edi
callq 0x10f0
leaq 0xaf4(%rip), %rdi       # 0x2076
callq 0x10d0
jmp 0x1630
leaq 0xaef(%rip), %rdi       # 0x2082
xorl %eax, %eax
callq 0x1070
leaq 0xaf5(%rip), %rdi       # 0x2096
xorl %eax, %eax
callq 0x1070
leaq 0xe4b(%rip), %rdi       # 0x23fa
callq 0x1040
leaq 0xc29(%rip), %rdi       # 0x21e4
callq 0x1040
leaq 0xb20(%rip), %rdi       # 0x20e7
xorl %eax, %eax
callq 0x1070
leaq 0xc86(%rip), %rdi       # 0x225b
callq 0x1040
leaq 0xcb1(%rip), %rdi       # 0x2292
callq 0x1040
leaq 0xcde(%rip), %rdi       # 0x22cb
callq 0x1040
leaq 0xd0a(%rip), %rdi       # 0x2303
callq 0x1040
leaq 0xb2f(%rip), %rdi       # 0x2134
xorl %eax, %eax
callq 0x1070
leaq 0xd34(%rip), %rdi       # 0x2347
callq 0x1040
leaq 0xd73(%rip), %rdi       # 0x2392
callq 0x1040
leaq 0xdaa(%rip), %rdi       # 0x23d5
callq 0x1040
movl $0x1, %edi
callq 0x10f0