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

  //Report an error assuming the project does not exist
  if(ENOENT == errno){
    closedir(dir);
    strcpy(sendBuff, "x");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;

  //project does exist, so continue
  }else if (dir){
    //do nothing and continue

  //opendir() failed
  }else{
    printf("\nERROR: opendir() failed.\n");
    strcpy(sendBuff, "e");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;
  }

  //Open the needed Manifest file
  char* manifestPath = (char*)malloc(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
    */
  if(manifest_fd < 0){
    printf("\nError: Was unable to open/create the .Manifest file. Please try again.\n");
    exit(1);
  }
  char* fileContents=readFile(manifestPath);
  printf("Message: -%s- size: %d\n", fileContents, strlen(fileContents));
  write(connfd, fileContents, strlen(fileContents));
  return;
}

// 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 0x3995
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3988
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 0x398a
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3939
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x10e0
movq -0x460(%rbp), %rdi
callq 0x1220
movq %rax, -0x438(%rbp)
callq 0x1030
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x3a68
movq -0x438(%rbp), %rdi
callq 0x1260
leaq -0x430(%rbp), %rdi
leaq 0x1aef(%rip), %rsi      # 0x54d9
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x488(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x488(%rbp), %rsi
movq %rax, %rdx
leaq 0x1a8b(%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 0x3c0e
cmpq $0x0, -0x438(%rbp)
je 0x3a77
jmp 0x3b11
leaq 0x1932(%rip), %rdi      # 0x53b0
movb $0x0, %al
callq 0x1040
leaq -0x430(%rbp), %rdi
leaq 0x1938(%rip), %rsi      # 0x53cb
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x4a0(%rbp), %rsi
movq %rax, %rdx
leaq 0x19e2(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x494(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x490(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x494(%rbp), %edi
movq -0x490(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
jmp 0x3c0e
jmp 0x3b13
movq -0x468(%rbp), %rdi
addq $0xb, %rdi
callq 0x11e0
movq -0x460(%rbp), %rsi
movq %rax, -0x448(%rbp)
movq -0x448(%rbp), %rdi
callq 0x1160
movq -0x448(%rbp), %rdi
leaq 0x1916(%rip), %rsi      # 0x5461
callq 0x1270
movq -0x448(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1100
movl %eax, -0x44c(%rbp)
cmpl $0x0, -0x44c(%rbp)
jge 0x3b87
leaq 0x1857(%rip), %rdi      # 0x53cd
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x11b0
movq -0x448(%rbp), %rdi
callq 0x4cb0
movq %rax, -0x458(%rbp)
movq -0x458(%rbp), %rax
movq %rax, -0x4b8(%rbp)
movq -0x458(%rbp), %rdi
callq 0x10c0
movq -0x4b8(%rbp), %rsi
movq %rax, %rdx
leaq 0x18e0(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x4ac(%rbp)
movq -0x458(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movq -0x458(%rbp), %rdi
callq 0x10c0
movl -0x4ac(%rbp), %edi
movq -0x4a8(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)