// File: /workspace/github_c_makefile_star2_O0/evanwire[P]GitClone/client.c
// Function: remove_file
void remove_file(char* project_name, char* file_name){
 //Verify the project exists on the client side
  DIR* dir = opendir(project_name);
  if(!dir){
    printf("\nError: the project you specified does not seem to exist on the client side. Please create the project before running again.\n");
    exit(1);
  }
  closedir(dir);

  //Generate the path of the manifest file
  char manifest_path[sizeof(project_name) + 10];
  strcpy(manifest_path, project_name);
  strcat(manifest_path, "/.Manifest");

  //read manifest file to a single char*
  char* manifest_contents = readFile(manifest_path);
  printf("\n%s\n", manifest_contents);

  //open manifest fd for writing
  int manifest_fd = open(manifest_path, O_WRONLY | O_TRUNC);
  if(manifest_fd < 0){
    printf("\nError: could not open .Manifest. Please try again.\n");
    exit(1);
  }

  //tokenize the manifest file by every line
  char* token;
  char* saveptr = manifest_contents;
  int bytes_written;

  //loop through the tokens
  while(token = strtok_r(saveptr, "\n", &saveptr)){
    printf("\n-%s-", token);
    //if the file name is not found in this line of the manifest, write it back to the manifest
    if(strstr(token, file_name) == NULL){
      bytes_written = write(manifest_fd, token, strlen(token));
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Manifest. Will attempt to write the original information back into it.\n");
        exit(1);
      }
      bytes_written = write(manifest_fd, "\n", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Manifest. Will attempt to write the original information back into it.\n");
        exit(1);
      }
    }
    //if the filename is found in this line of the manifest, write it back to the manifest with an R in front
    else {
      //write the R
      int bytes_written = write(manifest_fd, "D", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Manifest. Will attempt to write the original information back into it.\n");
        exit(1);
      }
      //write the rest of the line back
      bytes_written = write(manifest_fd, token, strlen(token));
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Manifest. Will attempt to write the original information back into it.\n");
        exit(1);
      }
      bytes_written = write(manifest_fd, "\n", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Manifest. Will attempt to write the original information back into it.\n");
        exit(1);
      }
    }

  }
  free(manifest_contents);
  close(manifest_fd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x11b0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x584f
leaq 0x1ea9(%rip), %rdi      # 0x76e7
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x18(%rbp), %rdi
callq 0x11e0
leaq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
leaq -0x30(%rbp), %rdi
leaq 0x1e31(%rip), %rsi      # 0x76a1
callq 0x1200
leaq -0x30(%rbp), %rdi
callq 0x5e50
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
leaq 0x1e1f(%rip), %rdi      # 0x76ac
movb $0x0, %al
callq 0x1040
leaq -0x30(%rbp), %rdi
movl $0x201, %esi            # imm = 0x201
movb $0x0, %al
callq 0x10f0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x58c5
leaq 0x1eb1(%rip), %rdi      # 0x7765
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x2871(%rip), %rsi      # 0x8149
leaq -0x50(%rbp), %rdx
callq 0x1210
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x5a51
movq -0x48(%rbp), %rsi
leaq 0x1fa5(%rip), %rdi      # 0x789f
movb $0x0, %al
callq 0x1040
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1070
cmpq $0x0, %rax
jne 0x5999
movl -0x3c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rdi
callq 0x10b0
movl -0x64(%rbp), %edi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0x595f
leaq 0x1f57(%rip), %rdi      # 0x78a5
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movl -0x3c(%rbp), %edi
leaq 0x27e0(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0x5994
leaq 0x1f22(%rip), %rdi      # 0x78a5
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x5a4c
movl -0x3c(%rbp), %edi
leaq 0x1f66(%rip), %rsi      # 0x7909
movl $0x1, %edx
callq 0x1090
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jge 0x59ce
leaq 0x1ee8(%rip), %rdi      # 0x78a5
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rdi
callq 0x10b0
movl -0x74(%rbp), %edi
movq -0x70(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jge 0x5a15
leaq 0x1ea1(%rip), %rdi      # 0x78a5
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movl -0x3c(%rbp), %edi
leaq 0x272a(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jge 0x5a4a
leaq 0x1e6c(%rip), %rdi      # 0x78a5
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x5a4c
jmp 0x58cd
movq -0x38(%rbp), %rdi
callq 0x1160
movl -0x3c(%rbp), %edi
callq 0x1220
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)