// File: /workspace/github_c_makefile_star2_O1/evanwire[P]GitClone/client.c
// Function: add
void add(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);

  char manifest_path[sizeof(project_name) + 10];
  strcpy(manifest_path, project_name);
  strcat(manifest_path, "/.Manifest");

  char file_path[sizeof(project_name) + sizeof(file_name) + 2];
  memset(file_path, '\0', sizeof(project_name) + sizeof(file_name) + 2);
  strcpy(file_path, project_name);
  strcat(file_path, "/");
  strcat(file_path, file_name);

  //Open file to copy and manifest to copy to
  int manifest_fd = open(manifest_path, O_WRONLY | O_APPEND);
  if(manifest_fd < 0){
    printf("\nError: could not open .Manifest. Please try again.\n");
    exit(1);
  }

  int file_fd = open(file_path, O_RDONLY);
  if(file_fd < 0){
    printf("\nError: could not find %s in your project. Make sure it is in the project, and provide a path through any subdirectories when you specify the file's name. Please  Please try again.\n");
    exit(1);
  }

  //Read file contents to a single char*
  char* file_contents = readFile(file_path);
  printf("\n%s\n", file_contents);

  //Hash the file
  char* hashed_file = hashIt(file_contents);

  //Create an entry in the manifest for the new file
  int size_of_write = strlen(project_name) + strlen(hashed_file) + strlen(file_name) + 12;
  char to_be_written[size_of_write];
  strcpy(to_be_written, "A./");
  strcat(to_be_written, file_path);
  strcat(to_be_written, "~V:0~H:");
  strcat(to_be_written, hashed_file);
  strcat(to_be_written, "\n");


  int bytes_written = write(manifest_fd, to_be_written, size_of_write);
  if(bytes_written < 0){
    printf("\nError: was unable to write your file data to the .Manifest file.\n");
    exit(1);
  }

  free(hashed_file);
  free(file_contents);
  close(manifest_fd);
  close(file_fd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %r12
callq 0x11c0
testq %rax, %rax
je 0x3f42
movq %rax, %rdi
callq 0x1200
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1140
movq %rbx, %rdi
callq 0x10a0
movabsq $0x6566696e614d2e2f, %rcx # imm = 0x6566696E614D2E2F
movq %rcx, -0x70(%rbp,%rax)
movl $0x747365, -0x69(%rbp,%rax) # imm = 0x747365
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %r14
movaps %xmm0, (%r14)
movw $0x0, 0x10(%r14)
movq %r14, %rdi
movq %r12, %rsi
callq 0x1140
movq %r14, %rdi
callq 0x10a0
movw $0x2f, -0x50(%rbp,%rax)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1220
movq %rbx, %rdi
movl $0x401, %esi            # imm = 0x401
xorl %eax, %eax
callq 0x10e0
movl %eax, -0x30(%rbp)
testl %eax, %eax
js 0x3f4b
movq %r15, %rbx
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x10e0
movl %eax, -0x2c(%rbp)
testl %eax, %eax
js 0x3f54
leaq -0x50(%rbp), %rdi
callq 0x43c0
movq %rax, %r13
leaq 0x1572(%rip), %rdi      # 0x53d1
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
movq %r13, %rdi
callq 0x4476
movq %rax, %r14
movq %r12, %rdi
callq 0x10a0
movq %rax, %r12
movq %r14, %rdi
callq 0x10a0
movq %rax, %r15
addl %r12d, %r15d
movq %rbx, %rdi
callq 0x10a0
movq %rsp, -0x58(%rbp)
leal (%rax,%r15), %r12d
addl $0xc, %r12d
leaq 0xf(%r12), %rax
andq $-0x10, %rax
movq %rsp, %rcx
movq %rcx, %r15
subq %rax, %r15
negq %rax
movq %r15, %rsp
movl $0x2f2e41, (%rcx,%rax)  # imm = 0x2F2E41
movq %r15, %rdi
leaq -0x50(%rbp), %rsi
callq 0x1220
movq %r15, %rdi
callq 0x10a0
movabsq $0x3a487e303a567e, %rcx # imm = 0x3A487E303A567E
movq %rcx, (%rax,%r15)
movq %r15, %rdi
movq %r14, %rsi
callq 0x1220
movq %r15, %rdi
callq 0x10a0
movw $0xa, (%rax,%r15)
movslq %r12d, %rdx
movl -0x30(%rbp), %ebx
movl %ebx, %edi
movq %r15, %rsi
callq 0x1080
testl %eax, %eax
js 0x3f64
movq %r14, %rdi
callq 0x1160
movq %r13, %rdi
callq 0x1160
movl %ebx, %edi
callq 0x1240
movl -0x2c(%rbp), %edi
callq 0x1240
movq -0x58(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fb1(%rip), %rdi      # 0x5efa
jmp 0x3f6b
leaq 0x2088(%rip), %rdi      # 0x5fda
jmp 0x3f6b
leaq 0x14b1(%rip), %rdi      # 0x540c
xorl %eax, %eax
callq 0x1040
jmp 0x3f70
leaq 0x1f4d(%rip), %rdi      # 0x5eb8
callq 0x11d0
movl $0x1, %edi
callq 0x1170