// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x11c0
testq %rax, %rax
je 0x3f13
movq %rax, %rdi
callq 0x1200
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1140
movq %r15, %rdi
callq 0x10a0
movabsq $0x6566696e614d2e2f, %rcx # imm = 0x6566696E614D2E2F
movq %rcx, -0x50(%rbp,%rax)
movl $0x747365, -0x49(%rbp,%rax) # imm = 0x747365
movq %r15, %rdi
callq 0x41b4
movq %rax, %r12
leaq 0x15ac(%rip), %rdi      # 0x53d1
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
movq %r15, %rdi
movl $0x201, %esi            # imm = 0x201
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x3f1c
movl %eax, %r15d
leaq -0x30(%rbp), %rax
movq %r12, (%rax)
leaq 0x1867(%rip), %r13      # 0x56be
pushq $0x1
popq %r14
movq %r12, -0x38(%rbp)
movq %r12, %rdi
movq %r13, %rsi
leaq -0x30(%rbp), %rdx
callq 0x1230
testq %rax, %rax
je 0x3edf
movq %rax, %r12
leaq 0x1645(%rip), %rdi      # 0x54c2
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1060
testq %rax, %rax
je 0x3ead
movl %r15d, %edi
leaq 0x1627(%rip), %rsi      # 0x54c8
movq %r14, %rdx
callq 0x1080
testl %eax, %eax
js 0x3eff
movq %r12, %rdi
callq 0x10a0
movl %r15d, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1080
testl %eax, %eax
js 0x3eff
movl %r15d, %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1080
testl %eax, %eax
js 0x3eff
movq -0x30(%rbp), %rdi
jmp 0x3e62
movq -0x38(%rbp), %rdi
callq 0x1160
movl %r15d, %edi
callq 0x1240
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2071(%rip), %rdi      # 0x5f77
callq 0x11d0
pushq $0x1
popq %rdi
callq 0x1170
leaq 0x1fe0(%rip), %rdi      # 0x5efa
jmp 0x3f06
leaq 0x20b7(%rip), %rdi      # 0x5fda
jmp 0x3f06