// File: /workspace/github_c_makefile_star2_O3/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 0x11d0
testq %rax, %rax
je 0x40c5
movq %rax, %rdi
callq 0x1210
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1150
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 0x4387
movq %rax, %r14
leaq 0x1415(%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 0x40ce
movl %eax, %r15d
leaq -0x30(%rbp), %rdx
movq %r14, (%rdx)
leaq 0x16d0(%rip), %rsi      # 0x56be
movq %r14, -0x38(%rbp)
movq %r14, %rdi
callq 0x1240
testq %rax, %rax
je 0x408f
movq %rax, %r12
leaq 0x16b1(%rip), %r13      # 0x56be
leaq -0x30(%rbp), %r14
leaq 0x14aa(%rip), %rdi      # 0x54c2
movq %r12, %rsi
xorl %eax, %eax
callq 0x1040
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1060
testq %rax, %rax
je 0x404a
movl $0x1, %edx
movl %r15d, %edi
leaq 0x1487(%rip), %rsi      # 0x54c8
callq 0x1080
testl %eax, %eax
js 0x40af
movq %r12, %rdi
callq 0x10a0
movl %r15d, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1080
testl %eax, %eax
js 0x40af
movl $0x1, %edx
movl %r15d, %edi
movq %r13, %rsi
callq 0x1080
testl %eax, %eax
js 0x40af
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1240
movq %rax, %r12
testq %rax, %rax
jne 0x4011
movq -0x38(%rbp), %rdi
callq 0x1170
movl %r15d, %edi
callq 0x1250
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ec1(%rip), %rdi      # 0x5f77
callq 0x11e0
movl $0x1, %edi
callq 0x1180
leaq 0x1e2e(%rip), %rdi      # 0x5efa
jmp 0x40b6
leaq 0x1f05(%rip), %rdi      # 0x5fda
jmp 0x40b6