// File: /workspace/github_c_makefile_star2_O0/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
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10c0
movq %rax, %rdx
decq %rdx
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
addq $0xe, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x458(%rbp)
movq %rdi, %rsp
movq %rdx, -0x20(%rbp)
xorl %esi, %esi
callq 0x10e0
movl $0x2, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x460(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10c0
movq %rax, %rcx
movq -0x460(%rbp), %rax
cmpq %rcx, %rax
jae 0x2eee
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2ee1
movq -0x458(%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 0x2ee3
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2e92
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x10e0
movq -0x458(%rbp), %rdi
callq 0x1220
movq %rax, -0x438(%rbp)
callq 0x1030
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x2fb5
leaq -0x430(%rbp), %rdi
leaq 0x25a2(%rip), %rsi      # 0x54d9
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x478(%rbp), %rsi
movq %rax, %rdx
leaq 0x253e(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x46c(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x468(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x46c(%rbp), %edi
movq -0x468(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
jmp 0x316b
cmpq $0x0, -0x438(%rbp)
je 0x3048
movq -0x438(%rbp), %rdi
callq 0x1260
movq -0x458(%rbp), %rdi
callq 0x10c0
movq %rax, %rcx
movq %rcx, %rax
addq $0x9, %rax
movq %rsp, %rdx
movq %rdx, -0x448(%rbp)
addq $0x18, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x480(%rbp)
movq %rdi, %rsp
movq %rax, -0x450(%rbp)
leaq 0x245c(%rip), %rsi      # 0x5471
callq 0x1160
movq -0x458(%rbp), %rsi
movq -0x480(%rbp), %rdi
callq 0x1270
movq -0x480(%rbp), %rdi
callq 0x1140
movq -0x448(%rbp), %rax
movq %rax, %rsp
jmp 0x30e2
leaq 0x2361(%rip), %rdi      # 0x53b0
movb $0x0, %al
callq 0x1040
leaq -0x430(%rbp), %rdi
leaq 0x2367(%rip), %rsi      # 0x53cb
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x498(%rbp), %rsi
movq %rax, %rdx
leaq 0x2411(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x48c(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x488(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x48c(%rbp), %edi
movq -0x488(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movl $0x1, -0x43c(%rbp)
jmp 0x316b
jmp 0x30e4
leaq -0x430(%rbp), %rdi
leaq 0x2387(%rip), %rsi      # 0x5479
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x4b0(%rbp), %rsi
movq %rax, %rdx
leaq 0x2383(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x4a4(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x4a4(%rbp), %edi
movq -0x4a0(%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 (%rax,%rax)