// File: /workspace/github_c_makefile_star2_O0/evanwire[P]GitClone/server.c
// Function: commit
void commit(char* command, int connfd){
  //Parse project name from the message received from the client
  char project_name[strlen(command) - 1];
  memset(project_name, 0, sizeof(project_name));
  int i;
  for(i = 2; i < strlen(command); i++){
      if(command[i]){
        project_name[i - 2] = command[i];
      }

  }

  //Set up buffer for responding to client
  char sendBuff[1024];
  memset(sendBuff, '\0', sizeof(sendBuff));

  //Attempt to open directory with the name specified by the client
  DIR* dir = opendir(project_name);

  //Check if it exists, report an error if not
  if(!dir){
    closedir(dir);
    strcpy(sendBuff, "e");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;
  }

  closedir(dir);

  //Open the needed Manifest file
  char manifestPath[sizeof(project_name) + 11];
  strcpy(manifestPath,project_name);
  strcat(manifestPath,"/.Manifest");

  int manifest_fd = open(manifestPath, O_RDONLY);

    /*
    TODO: Communicate errors like these to clients in an efficient way
        -Make a method for only communicating errors
    */

   //check if manifest exists, report an error if not
  if(manifest_fd < 0){
    close(manifest_fd);
    strcpy(sendBuff, "x");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;
  }

  close(manifest_fd);
  char* fileContents=readFile(manifestPath);

  printf("Message: -%s- size: %d", fileContents, strlen(fileContents));
  write(connfd, fileContents, strlen(fileContents));


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10c0
movq %rax, %rdx
decq %rdx
movq %rdx, -0x468(%rbp)
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
addq $0xe, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x460(%rbp)
movq %rdi, %rsp
movq %rdx, -0x20(%rbp)
xorl %esi, %esi
callq 0x10e0
movl $0x2, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x470(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10c0
movq %rax, %rcx
movq -0x470(%rbp), %rax
cmpq %rcx, %rax
jae 0x3cd5
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3cc8
movq -0x460(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movb (%rcx,%rdx), %dl
movl -0x24(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x3cca
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3c79
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x10e0
movq -0x460(%rbp), %rdi
callq 0x1220
movq %rax, -0x438(%rbp)
cmpq $0x0, -0x438(%rbp)
jne 0x3da1
movq -0x438(%rbp), %rdi
callq 0x1260
leaq -0x430(%rbp), %rdi
leaq 0x16a8(%rip), %rsi      # 0x53cb
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x488(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x488(%rbp), %rsi
movq %rax, %rdx
leaq 0x1752(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x47c(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x47c(%rbp), %edi
movq -0x478(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
jmp 0x3f45
movq -0x438(%rbp), %rdi
callq 0x1260
movq -0x468(%rbp), %rcx
movq -0x460(%rbp), %rsi
movq %rcx, %rax
addq $0xb, %rax
addq $0x1a, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x490(%rbp)
movq %rdi, %rsp
movq %rax, -0x448(%rbp)
callq 0x1160
movq -0x490(%rbp), %rdi
leaq 0x166d(%rip), %rsi      # 0x5461
callq 0x1270
movq -0x490(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1100
movl %eax, -0x44c(%rbp)
cmpl $0x0, -0x44c(%rbp)
jge 0x3eb3
movl -0x44c(%rbp), %edi
callq 0x12b0
leaq -0x430(%rbp), %rdi
leaq 0x16a4(%rip), %rsi      # 0x54d9
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x4a8(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x4a8(%rbp), %rsi
movq %rax, %rdx
leaq 0x1640(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x49c(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x49c(%rbp), %edi
movq -0x498(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
jmp 0x3f45
movl -0x44c(%rbp), %edi
callq 0x12b0
movq -0x490(%rbp), %rdi
callq 0x4cb0
movq %rax, -0x458(%rbp)
movq -0x458(%rbp), %rax
movq %rax, -0x4c0(%rbp)
movq -0x458(%rbp), %rdi
callq 0x10c0
movq -0x4c0(%rbp), %rsi
movq %rax, %rdx
leaq 0x15c1(%rip), %rdi      # 0x54bd
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x4b4(%rbp)
movq -0x458(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movq -0x458(%rbp), %rdi
callq 0x10c0
movl -0x4b4(%rbp), %edi
movq -0x4b0(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x0, -0x43c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)