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

  //Project does not exist so we can't destroy it, inform client
  if(ENOENT == errno){
    strcpy(sendBuff, "x");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;

  //project does exist so we destroy it
  }else if (dir){
    closedir(dir);
    char command[strlen(project_name) + 9];
    strcpy(command,"rm -rf ");
    strcat(command, project_name);
    system(command);

  //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;
  }


  //send success message to client
  strcpy(sendBuff, "Destroying the project was a success!");
  printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
  write(connfd, sendBuff, strlen(sendBuff));


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x400, %rsp            # imm = 0x400
movl %esi, %ebx
movq %rdi, %r15
callq 0x10b0
movq %rax, %r12
leaq -0x1(%rax), %rdx
movq %rsp, %r14
addq $0xe, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %r14, %rdi
xorl %esi, %esi
callq 0x10d0
cmpq $0x3, %r12
jb 0x233f
addq $-0x2, %r12
xorl %eax, %eax
movb 0x2(%r15,%rax), %cl
testb %cl, %cl
je 0x2337
movb %cl, (%r14,%rax)
incq %rax
cmpq %rax, %r12
jne 0x232a
leaq -0x420(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x10d0
movq %r14, %rdi
callq 0x1210
movq %rax, %r15
callq 0x1030
cmpl $0x2, (%rax)
jne 0x2375
movw $0x78, -0x420(%rbp)
jmp 0x240c
testq %r15, %r15
je 0x23f7
movq %r15, %rdi
callq 0x1260
movq %r14, %rdi
callq 0x10b0
movq %rsp, %r12
movq %rsp, %rcx
addq $0x18, %rax
andq $-0x10, %rax
movq %rcx, %r15
subq %rax, %r15
movq %r15, %rsp
negq %rax
movabsq $0x2066722d206d72, %rdx # imm = 0x2066722D206D72
movq %rdx, (%rcx,%rax)
movq %r15, %rdi
movq %r14, %rsi
callq 0x1270
movq %r15, %rdi
callq 0x1130
movq %r12, %rsp
movabsq $0x21737365636375, %rax # imm = 0x21737365636375
movq %rax, -0x402(%rbp)
movups 0x1edd(%rip), %xmm0     # 0x42bd
movaps %xmm0, -0x410(%rbp)
movups 0x1ebf(%rip), %xmm0     # 0x42ad
movaps %xmm0, -0x420(%rbp)
jmp 0x240c
leaq 0x229e(%rip), %rdi      # 0x469c
callq 0x1230
movw $0x65, -0x420(%rbp)
leaq -0x420(%rbp), %r14
movq %r14, %rdi
callq 0x10b0
leaq 0x1eb7(%rip), %rdi      # 0x42d9
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x10b0
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10a0
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq