// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rdx
addq $0x3, %rdx
movq %rdx, -0x68(%rbp)
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
addq $0x12, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x60(%rbp)
movq %rdi, %rsp
movq %rdx, -0x20(%rbp)
xorl %esi, %esi
callq 0x10d0
movq -0x60(%rbp), %rax
movb $0x63, (%rax)
movb $0x20, 0x1(%rax)
movl $0x2, -0x24(%rbp)
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x522a
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x521d
movq -0x60(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0xc(%rbp), %rdx
movb (%rcx,%rdx), %dl
movslq -0x24(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x521f
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x51d3
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x8(%rbp), %rcx
leaq 0x22a5(%rip), %rdi      # 0x74e2
movb $0x0, %al
callq 0x1040
movq -0x60(%rbp), %rdi
callq 0x5be0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x297e(%rip), %rsi      # 0x7bda
callq 0x1190
cmpl $0x0, %eax
jne 0x527e
leaq 0x22a8(%rip), %rdi      # 0x7515
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x30(%rbp), %rdi
leaq 0x1dec(%rip), %rsi      # 0x7075
callq 0x1190
cmpl $0x0, %eax
jne 0x52ab
leaq 0x2306(%rip), %rdi      # 0x75a0
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x52ad
movl $0x8, %edi
callq 0x1180
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x11b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x52db
movl $0x1, -0x44(%rbp)
jmp 0x5443
callq 0x1030
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x5314
movq -0x38(%rbp), %rdi
leaq 0x22fa(%rip), %rsi      # 0x75f1
callq 0x1140
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1200
movq -0x38(%rbp), %rdi
callq 0x1120
jmp 0x532c
leaq 0x22dd(%rip), %rdi      # 0x75f8
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x532e
leaq 0x236d(%rip), %rdi      # 0x76a2
movl $0x241, %esi            # imm = 0x241
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x10f0
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jge 0x5367
leaq 0x22bc(%rip), %rdi      # 0x7612
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movl -0x48(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x10b0
movl -0x7c(%rbp), %edi
movq -0x78(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x53ae
leaq 0x22be(%rip), %rdi      # 0x765b
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0xa, %rax
addq $0x19, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x88(%rbp)
movq %rdi, %rsp
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rsi
callq 0x1140
movq -0x88(%rbp), %rdi
leaq 0x22ad(%rip), %rsi      # 0x76a1
callq 0x1200
movq -0x88(%rbp), %rsi
leaq 0x22a5(%rip), %rdi      # 0x76ac
movb $0x0, %al
callq 0x1040
movq -0x88(%rbp), %rsi
leaq 0x2286(%rip), %rdi      # 0x76a2
callq 0x10e0
movq -0x40(%rbp), %rdi
callq 0x11e0
movq -0x30(%rbp), %rdi
callq 0x1160
movq -0x38(%rbp), %rdi
callq 0x1160
movl $0x1, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nop