// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
leaq 0xc43(%rip), %rdi       # 0x2069
callq 0x1080
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1220
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x145a
movq -0x18(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rdi
callq 0x1030
jmp 0x141f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xc14(%rip), %rsi       # 0x207c
callq 0x1090
cmpl $0x0, %eax
jne 0x1487
leaq 0xc08(%rip), %rdi       # 0x2081
movb $0x0, %al
callq 0x1070
xorl %edi, %edi
callq 0x10f0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xbf8(%rip), %rsi       # 0x208d
callq 0x1090
cmpl $0x0, %eax
jne 0x14b3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x12f0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xbd1(%rip), %rsi       # 0x2092
callq 0x1090
cmpl $0x0, %eax
jne 0x153c
callq 0x1110
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jge 0x14e8
leaq 0xb64(%rip), %rdi       # 0x2043
movb $0x0, %al
callq 0x1070
jmp 0x153a
cmpl $0x0, -0x2c(%rbp)
jle 0x1501
movl -0x2c(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x1538
movq -0x10(%rbp), %rsi
leaq 0xb84(%rip), %rdi       # 0x2090
callq 0x1100
cmpl $0x0, %eax
setl %al
movb %al, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, -0x28(%rbp)
testb $0x1, %al
jne 0x1528
jmp 0x1536
leaq 0xb69(%rip), %rdi       # 0x2098
movb $0x0, %al
callq 0x1070
jmp 0x1538
jmp 0x153a
jmp 0x153c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xb6c(%rip), %rsi       # 0x20b6
callq 0x1090
cmpl $0x0, %eax
jne 0x15c5
callq 0x1110
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jge 0x1571
leaq 0xadb(%rip), %rdi       # 0x2043
movb $0x0, %al
callq 0x1070
jmp 0x15c3
cmpl $0x0, -0x34(%rbp)
jle 0x158a
movl -0x34(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x15c1
movq -0x10(%rbp), %rsi
leaq 0xb1f(%rip), %rdi       # 0x20b4
callq 0x1100
cmpl $0x0, %eax
setl %al
movb %al, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, -0x30(%rbp)
testb $0x1, %al
jne 0x15b1
jmp 0x15bf
leaq 0xb02(%rip), %rdi       # 0x20ba
movb $0x0, %al
callq 0x1070
jmp 0x15c1
jmp 0x15c3
jmp 0x15c5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xb03(%rip), %rsi       # 0x20d6
callq 0x1090
cmpl $0x0, %eax
jne 0x164e
callq 0x1110
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jge 0x15fa
leaq 0xa52(%rip), %rdi       # 0x2043
movb $0x0, %al
callq 0x1070
jmp 0x164c
cmpl $0x0, -0x3c(%rbp)
jle 0x1613
movl -0x3c(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x164a
movq -0x10(%rbp), %rsi
leaq 0xab6(%rip), %rdi       # 0x20d4
callq 0x1100
cmpl $0x0, %eax
setl %al
movb %al, %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, -0x38(%rbp)
testb $0x1, %al
jne 0x163a
jmp 0x1648
leaq 0xa9a(%rip), %rdi       # 0x20db
movb $0x0, %al
callq 0x1070
jmp 0x164a
jmp 0x164c
jmp 0x164e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0xa9a(%rip), %rsi       # 0x20f6
callq 0x1090
cmpl $0x0, %eax
jne 0x176d
callq 0x1110
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x168e
leaq 0xa7c(%rip), %rdi       # 0x20fb
callq 0x10d0
movl $0x1, %edi
callq 0x10f0
cmpl $0x0, -0x1c(%rbp)
jne 0x1758
leaq 0xa68(%rip), %rdi       # 0x2107
movb $0x0, %al
callq 0x1070
leaq 0xa6e(%rip), %rdi       # 0x211b
movb $0x0, %al
callq 0x1070
leaq 0xd5a(%rip), %rdi       # 0x2415
movb $0x0, %al
callq 0x1070
leaq 0xaa3(%rip), %rdi       # 0x216c
movb $0x0, %al
callq 0x1070
leaq 0xb0d(%rip), %rdi       # 0x21e4
movb $0x0, %al
callq 0x1070
leaq 0xb4c(%rip), %rdi       # 0x2231
movb $0x0, %al
callq 0x1070
leaq 0xb76(%rip), %rdi       # 0x2269
movb $0x0, %al
callq 0x1070
leaq 0xba2(%rip), %rdi       # 0x22a3
movb $0x0, %al
callq 0x1070
leaq 0xbcd(%rip), %rdi       # 0x22dc
movb $0x0, %al
callq 0x1070
leaq 0xc04(%rip), %rdi       # 0x2321
movb $0x0, %al
callq 0x1070
leaq 0xc35(%rip), %rdi       # 0x2360
movb $0x0, %al
callq 0x1070
leaq 0xc73(%rip), %rdi       # 0x23ac
movb $0x0, %al
callq 0x1070
leaq 0xca9(%rip), %rdi       # 0x23f0
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x10f0
movl -0x1c(%rbp), %edi
leaq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x10c0
jmp 0x176b
jmp 0x176d
jmp 0x141f