// File: /workspace/github_c_makefile_star2_O3/evanwire[P]GitClone/client.c
// Function: create
void create(char* newProject){
  //Prepare message to server
  int i;
  char to_be_written[strlen(newProject) + 3];
  memset(to_be_written, 0, sizeof(to_be_written));
  to_be_written[0] = 'c';
  to_be_written[1] = ' ';
  int message_idx = 2;
  for(i = 0; i < strlen(newProject); i++){
    if(newProject[i]){
      to_be_written[message_idx] = newProject[i];
      message_idx++;
    }
  }
  printf("\nWritten to server: -%s- Size: %d passed in: -%s-\n", to_be_written, sizeof(to_be_written), newProject);

  //Connect to server, store the response
  char* response = connect_to_WTFserver(to_be_written);

  //Report if server responded with an error
  /*
    TODO: Make a method for receiving and alerting user of errors
      -Basically, if the server response begins with a certain character or some indicator of an error, it will send the server response to that method which will print
        the error message out to the user, without including the indicator we decide to use.
  */
  if(strcmp(response, "x") == 0){
    printf("\nError: That project already exists. You can download the current version of the project that is on the server with the checkout command.\n");
    exit(1);
  }else if(strcmp(response, "e") == 0){
    printf("\nError: The server ran into an error processing your request. Please try again.\n");
    exit(1);
  }

  //create repository if it doesn't already exist
  char* command =malloc(sizeof(newProject+7));
  DIR* dir = opendir(newProject);

  //the project exists on the client side do nothing
  if (dir){
    return;
  //Project does not exist so we create it
  }else if (ENOENT == errno){
    strcpy(command,"mkdir ");
    strcat(command, newProject);
    system(command);
  //opendir() failed for some reason
  }else{
    printf("\nERROR: opendir() failed\n");
    exit(1);
  }

  //Create the .Manifest and place it in the new directory
  //Create the .Manifest file
  int manifest_fd = open(".Manifest", O_WRONLY | O_TRUNC | O_CREAT, 0777);

  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, response, strlen(response));
  if(write_size < 0){
    printf("\nError: Was unable to write to the .Manifest file. Please try again.\n");
    exit(1);
  }

  char filepath[10 + strlen(newProject)];
  strcpy(filepath, newProject);
  strcat(filepath, "/.Manifest");
  printf("\n%s\n", filepath);
  rename(".Manifest", filepath);

  closedir(dir);
  free(response);
  free(command);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x10a0
movq %rax, %r12
leaq 0x3(%rax), %rdx
movq %rsp, %r13
leaq 0x12(%rax), %r14
andq $-0x10, %r14
movq %r13, %r15
subq %r14, %r15
movq %r15, %rsp
negq %r14
movq %r15, %rdi
xorl %esi, %esi
movq %rdx, -0x30(%rbp)
callq 0x10c0
movw $0x2063, (%r13,%r14)    # imm = 0x2063
testq %r12, %r12
je 0x3ad4
movl $0x2, %eax
xorl %ecx, %ecx
movb (%rbx,%rcx), %dl
testb %dl, %dl
je 0x3acc
cltq
movb %dl, (%r15,%rax)
incl %eax
incq %rcx
cmpq %rcx, %r12
jne 0x3abd
leaq 0x18b1(%rip), %rdi      # 0x538c
movq %r15, %rsi
movq -0x30(%rbp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1040
movq %r15, %rdi
callq 0x41ca
movq %rax, %r14
movzbl (%rax), %eax
cmpl $0x65, %eax
je 0x3b17
cmpl $0x78, %eax
jne 0x3b22
cmpb $0x0, 0x1(%r14)
jne 0x3b22
leaq 0x231c(%rip), %rdi      # 0x5e2e
jmp 0x3c5c
cmpb $0x0, 0x1(%r14)
je 0x3c55
movl $0x8, %edi
callq 0x1190
movq %rax, %r15
movq %rbx, %rdi
callq 0x11d0
testq %rax, %rax
jne 0x3c2b
callq 0x1030
cmpl $0x2, (%rax)
jne 0x3c3a
movl $0x207269, 0x3(%r15)    # imm = 0x207269
movl $0x69646b6d, (%r15)     # imm = 0x69646B6D
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1230
movq %r15, %rdi
callq 0x1130
leaq 0x1850(%rip), %rdi      # 0x53c7
movl $0x241, %esi            # imm = 0x241
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x10f0
testl %eax, %eax
js 0x3c43
movl %eax, %r12d
movq %r14, %rdi
callq 0x10a0
movl %r12d, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1080
testl %eax, %eax
js 0x3c4c
movq %rbx, %rdi
callq 0x10a0
movq %rsp, %r12
addq $0x19, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1150
movq %r12, %rdi
callq 0x10a0
movabsq $0x6566696e614d2e2f, %rcx # imm = 0x6566696E614D2E2F
movq %rcx, (%rax,%r12)
movl $0x747365, 0x7(%rax,%r12) # imm = 0x747365
leaq 0x17d6(%rip), %rdi      # 0x53d1
movq %r12, %rsi
xorl %eax, %eax
callq 0x1040
leaq 0x17bb(%rip), %rdi      # 0x53c7
movq %r12, %rsi
callq 0x10d0
xorl %edi, %edi
callq 0x1210
movq %r14, %rdi
callq 0x1170
movq %r15, %rdi
callq 0x1170
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2147(%rip), %rdi      # 0x5d88
jmp 0x3c5c
leaq 0x219c(%rip), %rdi      # 0x5de6
jmp 0x3c5c
leaq 0x214e(%rip), %rdi      # 0x5da1
jmp 0x3c5c
leaq 0x23f6(%rip), %rdi      # 0x6052
callq 0x11e0
movl $0x1, %edi
callq 0x1180