// File: /workspace/github_c_makefile_star2_O0/evanwire[P]GitClone/server.c
// Function: create
void create(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 already exists
  if(dir){
    closedir(dir);
    strcpy(sendBuff, "x");
    printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
    write(connfd, sendBuff, strlen(sendBuff));
    return;

  //project does not currently exist, so we create it
  }else if (ENOENT == errno){
    char command[strlen(project_name) + 6];
    strcpy(command,"mkdir ");
    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;
  }

  //Create the .Manifest file
  int manifest_fd = open(".Manifest", O_WRONLY | O_TRUNC | O_CREAT, 0777);

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

  int write_size = write(manifest_fd, "V 0\n", 4);
  if(write_size < 0){
    printf("\nError: Was unable to write to the .Manifest file. Please try again.\n");
    exit(1);
  }

  char filepath[10 + strlen(project_name)];
  strcpy(filepath, project_name);
  strcat(filepath, "/.Manifest");
  printf("\n%s\n", filepath);
  rename(".Manifest", filepath);
  /*
  TODO: Make the manifest file header more unique to each project
  */

  close(manifest_fd);
  //send manifest to client
  strcpy(sendBuff, "V 0\n");
  printf("Message: -%s- size: %d\n", sendBuff, strlen(sendBuff));
  write(connfd, sendBuff, strlen(sendBuff));
  //cleanup
  closedir(dir);


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
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, -0x468(%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 0x2a9e
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2a91
movq -0x468(%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 0x2a93
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2a42
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x10e0
movq -0x468(%rbp), %rdi
callq 0x1220
movq %rax, -0x438(%rbp)
cmpq $0x0, -0x438(%rbp)
je 0x2b6a
movq -0x438(%rbp), %rdi
callq 0x1260
leaq -0x430(%rbp), %rdi
leaq 0x29ed(%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 0x2989(%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 0x2e27
callq 0x1030
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x2bf4
movq -0x468(%rbp), %rdi
callq 0x10c0
movq %rax, %rcx
movq %rcx, %rax
addq $0x6, %rax
movq %rsp, %rdx
movq %rdx, -0x448(%rbp)
addq $0x15, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x490(%rbp)
movq %rdi, %rsp
movq %rax, -0x450(%rbp)
leaq 0x27e8(%rip), %rsi      # 0x53a9
callq 0x1160
movq -0x468(%rbp), %rsi
movq -0x490(%rbp), %rdi
callq 0x1270
movq -0x490(%rbp), %rdi
callq 0x1140
movq -0x448(%rbp), %rax
movq %rax, %rsp
jmp 0x2c8e
leaq 0x27b5(%rip), %rdi      # 0x53b0
movb $0x0, %al
callq 0x1040
leaq -0x430(%rbp), %rdi
leaq 0x27bb(%rip), %rsi      # 0x53cb
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x4a8(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x4a8(%rbp), %rsi
movq %rax, %rdx
leaq 0x2865(%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 0x2e27
jmp 0x2c90
leaq 0x27cb(%rip), %rdi      # 0x5462
movl $0x241, %esi            # imm = 0x241
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x1100
movl %eax, -0x454(%rbp)
cmpl $0x0, -0x454(%rbp)
jge 0x2ccf
leaq 0x270f(%rip), %rdi      # 0x53cd
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x11b0
movl -0x454(%rbp), %edi
leaq 0x273a(%rip), %rsi      # 0x5416
movl $0x4, %edx
callq 0x10b0
movl %eax, -0x458(%rbp)
cmpl $0x0, -0x458(%rbp)
jge 0x2d0d
leaq 0x271f(%rip), %rdi      # 0x541b
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x11b0
movq -0x468(%rbp), %rdi
callq 0x10c0
movq -0x468(%rbp), %rsi
movq %rax, %rcx
movq %rcx, %rax
addq $0xa, %rax
addq $0x19, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x4c8(%rbp)
movq %rdi, %rsp
movq %rax, -0x460(%rbp)
callq 0x1160
movq -0x4c8(%rbp), %rdi
leaq 0x2705(%rip), %rsi      # 0x5461
callq 0x1270
movq -0x4c8(%rbp), %rsi
leaq 0x26fd(%rip), %rdi      # 0x546c
movb $0x0, %al
callq 0x1040
movq -0x4c8(%rbp), %rsi
leaq 0x26de(%rip), %rdi      # 0x5462
callq 0x10f0
movl -0x454(%rbp), %edi
callq 0x12b0
leaq -0x430(%rbp), %rdi
leaq 0x2674(%rip), %rsi      # 0x5416
callq 0x1160
leaq -0x430(%rbp), %rax
movq %rax, -0x4c0(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movq -0x4c0(%rbp), %rsi
movq %rax, %rdx
leaq 0x26d3(%rip), %rdi      # 0x54a5
movb $0x0, %al
callq 0x1040
movl -0xc(%rbp), %eax
movl %eax, -0x4b4(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x10c0
movl -0x4b4(%rbp), %edi
movq -0x4b0(%rbp), %rsi
movq %rax, %rdx
callq 0x10b0
movq -0x438(%rbp), %rdi
callq 0x1260
movl $0x0, -0x43c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)