// File: /workspace/github_c_makefile_star2_O0/evanwire[P]GitClone/client.c
// Function: commit
void commit(char* project_name){
  //Check if project exists
  DIR* dir = opendir(project_name);
  if(!dir){
    printf("\nError: project does not exist locally. Please create it first.\n");
    exit(1);
  }
  closedir(dir);

  //Check for if the local project has a .Update file
  char update_path[strlen(project_name) + 10];
  strcpy(update_path, "./");
  strcat(update_path, project_name);
  strcat(update_path, "/.Update");
  struct stat update_file;
  if(stat(update_path, &update_file) == 0){
    if(update_file.st_size > 0){
      printf("\nError: your local version of the project has a .Update file that is not empty.\n");
      exit(1);
    }
  }

  //Check for if the local project has a .Conflict file
  char conflict_path[strlen(project_name) + 12];
  strcpy(conflict_path, "./");
  strcat(conflict_path, project_name);
  strcat(conflict_path, "/.Conflict");
  struct stat conflict_file;
  if(stat(conflict_path, &conflict_file) == 0){
    printf("\nError: your local version of the project has a .Conflict file.\n");
    exit(1);
  }

  //Prepare message to server
  int i;
  char to_be_written[strlen(project_name) + 3];
  memset(to_be_written, 0, sizeof(to_be_written));
  to_be_written[0] = 'o';
  to_be_written[1] = ' ';
  int message_idx = 2;
  for(i = 0; i < strlen(project_name); i++){
    if(project_name[i]){
      to_be_written[message_idx] = project_name[i];
      message_idx++;
    }
  }

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

  if(strcmp(response, "e") == 0){
    printf("\nError: project does not exist on server. Make sure you create it first.\n");
    exit(1);
  }else if(strcmp(response, "x") == 0){
    printf("\nError: could not find the manifest file on the server.\n");
    exit(1);
  }

  //Open and tokenize local manifest file
  char manifestPath[sizeof(project_name) + 11];
  strcpy(manifestPath, project_name);
  strcat(manifestPath, "/.Manifest");
  char* local_manifest = readFile(manifestPath);

  //To tokenize the local manifest file by \n
  char* local_token;
  char* l_saveptr = local_manifest;

  //Get the first line of both manifest files and compare them, ultimately checking version numbers
  local_token = strtok_r(l_saveptr, "\n", &l_saveptr);
  for(i = 0; i < strlen(local_token); i++){
    if(local_token[i] != response[i]){
      printf("\nError: the local and server project versions do not match. Please update your local version before running again.\n");
      free(response);
      free(local_manifest);
      exit(1);
    }
  }

  //Creating a path for the commit file
  char commitPath[sizeof(project_name) + 8];
  strcpy(commitPath, project_name);
  strcat(commitPath, "/.Commit");


  int commit_fd = open(commitPath, O_WRONLY | O_TRUNC | O_CREAT, 0777);
  if(commit_fd < 0){
    printf("\nError: could not open/create the .Commit file.");
    close(commit_fd);
    free(response);
    free(local_manifest);
    exit(1);
  }

  //Write project name to commit file
  int first_write = write(commit_fd, project_name, strlen(project_name));
  if(first_write < 0){
    printf("\nError: was unable to write to .Commit file.\n");
    close(commit_fd);
    exit(1);
  }

  first_write = write(commit_fd, "\n", 1);
  if(first_write < 0){
    printf("\nError: was unable to write to .Commit file.\n");
    close(commit_fd);
    exit(1);
  }

  //Loop through local manifest, looking for where files were added, removed or modified
  while(local_token = strtok_r(l_saveptr, "\n", &l_saveptr)){

    //If a file was added locally but not on the server yet*********
    if(local_token[0] == 'A'){

      //Tokenize this line of the local manifest to make it easier to identify the file path and its hash
      char* token;
      char* saveptr = local_token;
      token = strtok_r(saveptr, "~", &saveptr);


      //Write A<filepath> to .Commit
      int bytes_written = write(commit_fd, token, strlen(token));
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }


      //Navigate to the file's hash, which we can do manually since the layout of the manifest file is standardized
      token = strtok_r(saveptr, "~", &saveptr);
      token = strtok_r(saveptr, "~", &saveptr);
      char* inner_token;
      char* inner_saveptr = token;
      inner_token = strtok_r(inner_saveptr, ":", &inner_saveptr);
      inner_token = strtok_r(inner_saveptr, ":", &inner_saveptr);


      //Write a separator symbol and the file's hash to .Commit
      bytes_written = write(commit_fd, "^", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }
      bytes_written = write(commit_fd, inner_token, strlen(inner_token));
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }
      bytes_written = write(commit_fd, "\n", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }



      //If a file was removed locally but not on the server yet*********
    }else if(local_token[0] == 'D'){
      //Tokenize this line of the local manifest to make it easier to identify the file path and its hash
      char* token;
      char* saveptr = local_token;
      token = strtok_r(saveptr, "~", &saveptr);


      //Write R<filepath> to .Commit
      int bytes_written = write(commit_fd, token, strlen(token));
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }


      //Navigate to the file's hash, which we can do manually since the layout of the manifest file is standardized
      token = strtok_r(saveptr, "~", &saveptr);
      token = strtok_r(saveptr, "~", &saveptr);
      char* inner_token;
      char* inner_saveptr = token;
      inner_token = strtok_r(inner_saveptr, ":", &inner_saveptr);
      inner_token = strtok_r(inner_saveptr, ":", &inner_saveptr);


      //Write a separator symbol and the file's hash to .Commit
      bytes_written = write(commit_fd, "^", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }
      bytes_written = write(commit_fd, inner_token, strlen(inner_token));
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }
      bytes_written = write(commit_fd, "\n", 1);
      if(bytes_written < 0){
        printf("\nError: was unable to write to .Commit file.\n");
        close(commit_fd);
        exit(1);
      }

      //If a file has not been added or removed on local manifest (checking for modifications)*********
    }else{
      //Tokenize this line of the local manifest to make it easier to identify the file path and its hash
      char* token;
      char* saveptr = local_token;
      token = strtok_r(saveptr, "~", &saveptr);

      //Preserve server response in temporary buffer so that strtok does not mess it up
      char* temp_buff = (char*)malloc(strlen(response) + 1);
      if(temp_buff == NULL){
        printf("\nError: could not use malloc().\n");
        exit(1);
      }
      strcpy(temp_buff, response);


      //Get a pointer to this file in the server's manifest
      char* file_in_server = strstr(temp_buff, token);
      if(!file_in_server){
        printf("\nError: commit failed. Found a local file that was not recently added that could not be found on the server.\n");
        char command[strlen(commitPath) + 7];
        strcpy(command, "rm -rf ");
        strcat(command, commitPath);
        system(command);
        exit(1);
      }

      //Storing the path for the file so we can hash it later if we need to
      char* buff_for_file_path = malloc(strlen(token) + 1);
      strcpy(buff_for_file_path, token);



      //Navigate to both the server and the client's hash
      token = strtok_r(saveptr, "~", &saveptr);
      char* v_num_storage = malloc(strlen(token) + 1);
      strcpy(v_num_storage, token);
      token = strtok_r(saveptr, "~", &saveptr);
      char* l_inner_token;
      char* l_inner_saveptr = token;
      l_inner_token = strtok_r(l_inner_saveptr, ":", &l_inner_saveptr);
      l_inner_token = strtok_r(l_inner_saveptr, ":", &l_inner_saveptr);

      char* temp_token;
      char* t_saveptr = file_in_server;
      temp_token = strtok_r(t_saveptr, "\n", &t_saveptr);
      char* s_token;
      char* s_saveptr = temp_token;
      s_token = strtok_r(s_saveptr, "~", &s_saveptr);
      s_token = strtok_r(s_saveptr, "~", &s_saveptr);
      char* version_number_storage = malloc(strlen(s_token) + 1);
      strcpy(version_number_storage, s_token);
      s_token = strtok_r(s_saveptr, "~", &s_saveptr);
      char* s_inner_token;
      char* s_inner_saveptr = s_token;
      s_inner_token = strtok_r(s_inner_saveptr, ":", &s_inner_saveptr);
      s_inner_token = strtok_r(s_inner_saveptr, ":", &s_inner_saveptr);


      //If they have the same hash
      if(strcmp(l_inner_token, s_inner_token) == 0){
        char* file_contents = readFile(buff_for_file_path);
        char* file_hash= hashIt(file_contents);

        //Extract version numbers
        char* yet_another_token;
        char* yet_another_saveptr = version_number_storage;
        yet_another_token = strtok_r(yet_another_saveptr, ":", &yet_another_saveptr);
        yet_another_token = strtok_r(yet_another_saveptr, ":", &yet_another_saveptr);
        int versionNumber_s = atoi(yet_another_token);

        char* hopefullly_last_token;
        char* hopefully_last_saveptr = v_num_storage;
        hopefullly_last_token = strtok_r(hopefully_last_saveptr, ":", &hopefully_last_saveptr);
        hopefullly_last_token = strtok_r(hopefully_last_saveptr, ":", &hopefully_last_saveptr);
        int versionNumber_l = atoi(hopefullly_last_token);


        //If the file's live has is  different than the one on the local manifest
        if(strcmp(file_hash, l_inner_token) != 0){
          //Increment version number of local copy
          versionNumber_l++;
          char numStorage[5];
          sprintf(numStorage, "%d", versionNumber_l);

          //Add to the .Commit
          int bytes_written = write(commit_fd, "M", 1);
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, buff_for_file_path, strlen(buff_for_file_path));
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, "^", 1);
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, numStorage, strlen(numStorage));
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, "^", 1);
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, file_hash, strlen(file_hash));
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }
          bytes_written = write(commit_fd, "\n", 1);
          if(bytes_written < 0){
            printf("\nError: was unable to write to .Commit file.\n");
            close(commit_fd);
            exit(1);
          }

          //different hashes, compare the version numbers to see if client must sync its repository
        }else{
          if(versionNumber_s > versionNumber_l){
            printf("\nError: please synch this project to the server's project before committing changes.");
            char command[strlen(commitPath) + 7];
            strcpy(command, "rm -rf ");
            strcat(command, commitPath);
            system(command);
            exit(1);
          }
        }

        free(file_contents);
        free(file_hash);
      }

      free(version_number_storage);
      free(temp_buff);
      free(buff_for_file_path);
    }

  }
  close(commit_fd);
  struct stat commit;
  stat(commitPath, &commit);
  int size = commit.st_size;
  if(size == 0){
    char command[strlen(commitPath) + 7];
    strcpy(command, "rm -rf ");
    strcat(command, commitPath);
    system(command);
  }else{
    char* commit_contents = readFile(commitPath);
    char sendBuff[strlen(commit_contents) + strlen(project_name) + 3];
    memset(sendBuff, 0, strlen(commit_contents) + strlen(project_name) + 3);
    strcpy(sendBuff, "z ");
    strcat(sendBuff, project_name);
    strcat(sendBuff, " ");
    strcat(sendBuff, commit_contents);
    char* server_response_2 = connect_to_WTFserver(sendBuff);
    printf("\n%s", server_response_2);
    free(commit_contents);
    free(server_response_2);
  }

  printf("\n");

  free(response);
  free(local_manifest);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x11b0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x36ab
leaq 0x46d3(%rip), %rdi      # 0x7d6d
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x10(%rbp), %rdi
callq 0x11e0
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0xa, %rax
movq %rsp, %rdx
movq %rdx, -0x18(%rbp)
addq $0x19, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x3b8(%rbp)
movq %rdi, %rsp
movq %rax, -0x20(%rbp)
leaq 0x4160(%rip), %rsi      # 0x7851
callq 0x1140
movq -0x3b8(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1200
movq -0x3b8(%rbp), %rdi
leaq 0x469a(%rip), %rsi      # 0x7dae
callq 0x1200
movq -0x3b8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1130
cmpl $0x0, %eax
jne 0x3752
cmpq $0x0, -0x80(%rbp)
jle 0x3750
leaq 0x4678(%rip), %rdi      # 0x7db7
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x3752
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0xc, %rax
addq $0x1b, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x3c0(%rbp)
movq %rdi, %rsp
movq %rax, -0xb8(%rbp)
leaq 0x40c6(%rip), %rsi      # 0x7851
callq 0x1140
movq -0x3c0(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1200
movq -0x3c0(%rbp), %rdi
leaq 0x465a(%rip), %rsi      # 0x7e08
callq 0x1200
movq -0x3c0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x1130
cmpl $0x0, %eax
jne 0x37e3
leaq 0x4641(%rip), %rdi      # 0x7e13
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rdx
addq $0x3, %rdx
addq $0x12, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x3c8(%rbp)
movq %rdi, %rsp
movq %rdx, -0x158(%rbp)
xorl %esi, %esi
callq 0x10d0
movq -0x3c8(%rbp), %rax
movb $0x6f, (%rax)
movb $0x20, 0x1(%rax)
movl $0x2, -0x15c(%rbp)
movl $0x0, -0x14c(%rbp)
movslq -0x14c(%rbp), %rax
movq %rax, -0x3d0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x3d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x38b3
movq -0x8(%rbp), %rax
movslq -0x14c(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x38a0
movq -0x3c8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14c(%rbp), %rdx
movb (%rcx,%rdx), %dl
movslq -0x15c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x38a2
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x383b
movq -0x3c8(%rbp), %rdi
callq 0x5be0
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
leaq 0x37a1(%rip), %rsi      # 0x7075
callq 0x1190
cmpl $0x0, %eax
jne 0x38f6
leaq 0x456f(%rip), %rdi      # 0x7e54
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x168(%rbp), %rdi
leaq 0x42d6(%rip), %rsi      # 0x7bda
callq 0x1190
cmpl $0x0, %eax
jne 0x3926
leaq 0x4589(%rip), %rdi      # 0x7e9e
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x3928
leaq -0x180(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
leaq -0x180(%rbp), %rdi
leaq 0x3d5b(%rip), %rsi      # 0x76a1
callq 0x1200
leaq -0x180(%rbp), %rdi
callq 0x5e50
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdi
leaq 0x47cf(%rip), %rsi      # 0x8149
leaq -0x198(%rbp), %rdx
callq 0x1210
movq %rax, -0x190(%rbp)
movl $0x0, -0x14c(%rbp)
movslq -0x14c(%rbp), %rax
movq %rax, -0x3d8(%rbp)
movq -0x190(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x3d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x3a2e
movq -0x190(%rbp), %rax
movslq -0x14c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x168(%rbp), %rcx
movslq -0x14c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x3a18
leaq 0x44e8(%rip), %rdi      # 0x7ed7
movb $0x0, %al
callq 0x1040
movq -0x168(%rbp), %rdi
callq 0x1160
movq -0x188(%rbp), %rdi
callq 0x1160
movl $0x1, %edi
callq 0x1170
jmp 0x3a1a
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x3997
leaq -0x1b0(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
leaq -0x1b0(%rbp), %rdi
leaq 0x44ff(%rip), %rsi      # 0x7f4b
callq 0x1200
leaq -0x1b0(%rbp), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x10f0
movl %eax, -0x1b4(%rbp)
cmpl $0x0, -0x1b4(%rbp)
jge 0x3ab3
leaq 0x44d5(%rip), %rdi      # 0x7f54
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movq -0x168(%rbp), %rdi
callq 0x1160
movq -0x188(%rbp), %rdi
callq 0x1160
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x3e4(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x3e0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movl -0x3e4(%rbp), %edi
movq -0x3e0(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x1b8(%rbp)
cmpl $0x0, -0x1b8(%rbp)
jge 0x3b1a
leaq 0x4486(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x4622(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x1b8(%rbp)
cmpl $0x0, -0x1b8(%rbp)
jge 0x3b63
leaq 0x443d(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
jmp 0x3b65
movq -0x198(%rbp), %rdi
leaq 0x45d6(%rip), %rsi      # 0x8149
leaq -0x198(%rbp), %rdx
callq 0x1210
movq %rax, -0x190(%rbp)
cmpq $0x0, %rax
je 0x47f4
movq -0x190(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jne 0x3dd5
movq -0x190(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rdi
leaq 0x43f3(%rip), %rsi      # 0x7fb2
leaq -0x1c8(%rbp), %rdx
callq 0x1210
movq %rax, -0x1c0(%rbp)
movl -0x1b4(%rbp), %eax
movl %eax, -0x3f4(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x3f0(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x10b0
movl -0x3f4(%rbp), %edi
movq -0x3f0(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
jge 0x3c3f
leaq 0x4361(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movq -0x1c8(%rbp), %rdi
leaq 0x4365(%rip), %rsi      # 0x7fb2
leaq -0x1c8(%rbp), %rdx
callq 0x1210
movq %rax, -0x1c0(%rbp)
movq -0x1c8(%rbp), %rdi
leaq 0x4344(%rip), %rsi      # 0x7fb2
leaq -0x1c8(%rbp), %rdx
callq 0x1210
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rdi
leaq 0x3bbd(%rip), %rsi      # 0x785a
leaq -0x1e0(%rbp), %rdx
callq 0x1210
movq %rax, -0x1d8(%rbp)
movq -0x1e0(%rbp), %rdi
leaq 0x3b9c(%rip), %rsi      # 0x785a
leaq -0x1e0(%rbp), %rdx
callq 0x1210
movq %rax, -0x1d8(%rbp)
movl -0x1b4(%rbp), %edi
leaq 0x42d6(%rip), %rsi      # 0x7fb4
movl $0x1, %edx
callq 0x1090
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
jge 0x3d1a
leaq 0x4286(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x404(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0x400(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x10b0
movl -0x404(%rbp), %edi
movq -0x400(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
jge 0x3d87
leaq 0x4219(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x43b5(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
jge 0x3dd0
leaq 0x41d0(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
jmp 0x47ef
movq -0x190(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x44, %eax
jne 0x401a
movq -0x190(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rdi
leaq 0x41ae(%rip), %rsi      # 0x7fb2
leaq -0x1f0(%rbp), %rdx
callq 0x1210
movq %rax, -0x1e8(%rbp)
movl -0x1b4(%rbp), %eax
movl %eax, -0x414(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x410(%rbp)
movq -0x1e8(%rbp), %rdi
callq 0x10b0
movl -0x414(%rbp), %edi
movq -0x410(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x1f4(%rbp)
cmpl $0x0, -0x1f4(%rbp)
jge 0x3e84
leaq 0x411c(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movq -0x1f0(%rbp), %rdi
leaq 0x4120(%rip), %rsi      # 0x7fb2
leaq -0x1f0(%rbp), %rdx
callq 0x1210
movq %rax, -0x1e8(%rbp)
movq -0x1f0(%rbp), %rdi
leaq 0x40ff(%rip), %rsi      # 0x7fb2
leaq -0x1f0(%rbp), %rdx
callq 0x1210
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rdi
leaq 0x3978(%rip), %rsi      # 0x785a
leaq -0x208(%rbp), %rdx
callq 0x1210
movq %rax, -0x200(%rbp)
movq -0x208(%rbp), %rdi
leaq 0x3957(%rip), %rsi      # 0x785a
leaq -0x208(%rbp), %rdx
callq 0x1210
movq %rax, -0x200(%rbp)
movl -0x1b4(%rbp), %edi
leaq 0x4091(%rip), %rsi      # 0x7fb4
movl $0x1, %edx
callq 0x1090
movl %eax, -0x1f4(%rbp)
cmpl $0x0, -0x1f4(%rbp)
jge 0x3f5f
leaq 0x4041(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x424(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x420(%rbp)
movq -0x200(%rbp), %rdi
callq 0x10b0
movl -0x424(%rbp), %edi
movq -0x420(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x1f4(%rbp)
cmpl $0x0, -0x1f4(%rbp)
jge 0x3fcc
leaq 0x3fd4(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x4170(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x1f4(%rbp)
cmpl $0x0, -0x1f4(%rbp)
jge 0x4015
leaq 0x3f8b(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
jmp 0x47ed
movq -0x190(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rdi
leaq 0x3f7c(%rip), %rsi      # 0x7fb2
leaq -0x218(%rbp), %rdx
callq 0x1210
movq %rax, -0x210(%rbp)
movq -0x168(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0x220(%rbp)
cmpq $0x0, -0x220(%rbp)
jne 0x408a
leaq 0x3f3d(%rip), %rdi      # 0x7fb6
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x220(%rbp), %rdi
movq -0x168(%rbp), %rsi
callq 0x1140
movq -0x220(%rbp), %rdi
movq -0x210(%rbp), %rsi
callq 0x1070
movq %rax, -0x228(%rbp)
cmpq $0x0, -0x228(%rbp)
jne 0x4147
leaq 0x3f0b(%rip), %rdi      # 0x7fd7
xorl %eax, %eax
callq 0x1040
leaq -0x1b0(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0x7, %rax
movq %rsp, %rdx
movq %rdx, -0x230(%rbp)
addq $0x16, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x430(%rbp)
movq %rdi, %rsp
movq %rax, -0x238(%rbp)
leaq 0x3f2c(%rip), %rsi      # 0x8045
callq 0x1140
movq -0x430(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x1200
movq -0x430(%rbp), %rdi
callq 0x1120
movl $0x1, %edi
callq 0x1170
movq -0x210(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rdi
movq -0x210(%rbp), %rsi
callq 0x1140
movq -0x218(%rbp), %rdi
leaq 0x3e2b(%rip), %rsi      # 0x7fb2
leaq -0x218(%rbp), %rdx
callq 0x1210
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rdi
movq -0x210(%rbp), %rsi
callq 0x1140
movq -0x218(%rbp), %rdi
leaq 0x3dd8(%rip), %rsi      # 0x7fb2
leaq -0x218(%rbp), %rdx
callq 0x1210
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rdi
leaq 0x3651(%rip), %rsi      # 0x785a
leaq -0x258(%rbp), %rdx
callq 0x1210
movq %rax, -0x250(%rbp)
movq -0x258(%rbp), %rdi
leaq 0x3630(%rip), %rsi      # 0x785a
leaq -0x258(%rbp), %rdx
callq 0x1210
movq %rax, -0x250(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x268(%rbp), %rdi
leaq 0x3ef0(%rip), %rsi      # 0x8149
leaq -0x268(%rbp), %rdx
callq 0x1210
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
leaq 0x3d2a(%rip), %rsi      # 0x7fb2
leaq -0x278(%rbp), %rdx
callq 0x1210
movq %rax, -0x270(%rbp)
movq -0x278(%rbp), %rdi
leaq 0x3d09(%rip), %rsi      # 0x7fb2
leaq -0x278(%rbp), %rdx
callq 0x1210
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rdi
movq -0x270(%rbp), %rsi
callq 0x1140
movq -0x278(%rbp), %rdi
leaq 0x3cb6(%rip), %rsi      # 0x7fb2
leaq -0x278(%rbp), %rdx
callq 0x1210
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rdi
leaq 0x352f(%rip), %rsi      # 0x785a
leaq -0x290(%rbp), %rdx
callq 0x1210
movq %rax, -0x288(%rbp)
movq -0x290(%rbp), %rdi
leaq 0x350e(%rip), %rsi      # 0x785a
leaq -0x290(%rbp), %rdx
callq 0x1210
movq %rax, -0x288(%rbp)
movq -0x250(%rbp), %rdi
movq -0x288(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
jne 0x47c9
movq -0x240(%rbp), %rdi
callq 0x5e50
movq %rax, -0x298(%rbp)
movq -0x298(%rbp), %rdi
callq 0x5f60
movq %rax, -0x2a0(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rdi
leaq 0x349d(%rip), %rsi      # 0x785a
leaq -0x2b0(%rbp), %rdx
callq 0x1210
movq %rax, -0x2a8(%rbp)
movq -0x2b0(%rbp), %rdi
leaq 0x347c(%rip), %rsi      # 0x785a
leaq -0x2b0(%rbp), %rdx
callq 0x1210
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rdi
callq 0x11d0
movl %eax, -0x2b4(%rbp)
movq -0x248(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0x2c8(%rbp), %rdi
leaq 0x343b(%rip), %rsi      # 0x785a
leaq -0x2c8(%rbp), %rdx
callq 0x1210
movq %rax, -0x2c0(%rbp)
movq -0x2c8(%rbp), %rdi
leaq 0x341a(%rip), %rsi      # 0x785a
leaq -0x2c8(%rbp), %rdx
callq 0x1210
movq %rax, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rdi
callq 0x11d0
movl %eax, -0x2cc(%rbp)
movq -0x2a0(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
je 0x471b
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
leaq -0x2d1(%rbp), %rdi
movl -0x2cc(%rbp), %edx
leaq 0x3c90(%rip), %rsi      # 0x8134
movb $0x0, %al
callq 0x1060
movl -0x1b4(%rbp), %edi
leaq 0x3b95(%rip), %rsi      # 0x804d
movl $0x1, %edx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x44f4
leaq 0x3aac(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x43c(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x438(%rbp)
movq -0x240(%rbp), %rdi
callq 0x10b0
movl -0x43c(%rbp), %edi
movq -0x438(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x4561
leaq 0x3a3f(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x3a46(%rip), %rsi      # 0x7fb4
movl $0x1, %edx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x45aa
leaq 0x39f6(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x44c(%rbp)
leaq -0x2d1(%rbp), %rax
movq %rax, -0x448(%rbp)
leaq -0x2d1(%rbp), %rdi
callq 0x10b0
movl -0x44c(%rbp), %edi
movq -0x448(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x4617
leaq 0x3989(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x3990(%rip), %rsi      # 0x7fb4
movl $0x1, %edx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x4660
leaq 0x3940(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %eax
movl %eax, -0x45c(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x458(%rbp)
movq -0x2a0(%rbp), %rdi
callq 0x10b0
movl -0x45c(%rbp), %edi
movq -0x458(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x46cd
leaq 0x38d3(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
movl -0x1b4(%rbp), %edi
leaq 0x3a6f(%rip), %rsi      # 0x8149
movl $0x1, %edx
callq 0x1090
movl %eax, -0x2d8(%rbp)
cmpl $0x0, -0x2d8(%rbp)
jge 0x4716
leaq 0x388a(%rip), %rdi      # 0x7f84
movb $0x0, %al
callq 0x1040
movl -0x1b4(%rbp), %edi
callq 0x1220
movl $0x1, %edi
callq 0x1170
jmp 0x47b1
movl -0x2b4(%rbp), %eax
cmpl -0x2cc(%rbp), %eax
jle 0x47af
leaq 0x391b(%rip), %rdi      # 0x804f
xorl %eax, %eax
callq 0x1040
leaq -0x1b0(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0x7, %rax
movq %rsp, %rdx
movq %rdx, -0x2e0(%rbp)
addq $0x16, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x468(%rbp)
movq %rdi, %rsp
movq %rax, -0x2e8(%rbp)
leaq 0x38c4(%rip), %rsi      # 0x8045
callq 0x1140
movq -0x468(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x1200
movq -0x468(%rbp), %rdi
callq 0x1120
movl $0x1, %edi
callq 0x1170
jmp 0x47b1
movq -0x298(%rbp), %rdi
callq 0x1160
movq -0x2a0(%rbp), %rdi
callq 0x1160
movq -0x280(%rbp), %rdi
callq 0x1160
movq -0x220(%rbp), %rdi
callq 0x1160
movq -0x240(%rbp), %rdi
callq 0x1160
jmp 0x47ef
jmp 0x3b65
movl -0x1b4(%rbp), %edi
callq 0x1220
leaq -0x1b0(%rbp), %rdi
leaq -0x378(%rbp), %rsi
callq 0x1130
movq -0x348(%rbp), %rax
movl %eax, -0x37c(%rbp)
cmpl $0x0, -0x37c(%rbp)
jne 0x48a1
leaq -0x1b0(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq %rcx, %rax
addq $0x7, %rax
movq %rsp, %rdx
movq %rdx, -0x388(%rbp)
addq $0x16, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x470(%rbp)
movq %rdi, %rsp
movq %rax, -0x390(%rbp)
leaq 0x37d7(%rip), %rsi      # 0x8045
callq 0x1140
movq -0x470(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x1200
movq -0x470(%rbp), %rdi
callq 0x1120
movq -0x388(%rbp), %rax
movq %rax, %rsp
jmp 0x49d4
leaq -0x1b0(%rbp), %rdi
callq 0x5e50
movq %rax, -0x398(%rbp)
movq -0x398(%rbp), %rdi
callq 0x10b0
movq %rax, -0x488(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq -0x488(%rbp), %rcx
movq %rax, %rdx
leaq 0x3(%rcx,%rdx), %rax
movq %rsp, %rsi
movq %rsi, -0x3a0(%rbp)
leaq 0x12(%rcx,%rdx), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x478(%rbp)
movq %rcx, %rsp
movq %rax, -0x3a8(%rbp)
movq -0x398(%rbp), %rdi
callq 0x10b0
movq %rax, -0x480(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq -0x480(%rbp), %rdx
movq -0x478(%rbp), %rdi
addq %rax, %rdx
addq $0x3, %rdx
xorl %esi, %esi
callq 0x10d0
movq -0x478(%rbp), %rdi
leaq 0x3755(%rip), %rsi      # 0x80a4
callq 0x1140
movq -0x478(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1200
movq -0x478(%rbp), %rdi
leaq 0x36d9(%rip), %rsi      # 0x804b
callq 0x1200
movq -0x478(%rbp), %rdi
movq -0x398(%rbp), %rsi
callq 0x1200
movq -0x478(%rbp), %rdi
callq 0x5be0
movq %rax, -0x3b0(%rbp)
movq -0x3b0(%rbp), %rsi
leaq 0x36fc(%rip), %rdi      # 0x80a7
movb $0x0, %al
callq 0x1040
movq -0x398(%rbp), %rdi
callq 0x1160
movq -0x3b0(%rbp), %rdi
callq 0x1160
movq -0x3a0(%rbp), %rax
movq %rax, %rsp
leaq 0x376e(%rip), %rdi      # 0x8149
movb $0x0, %al
callq 0x1040
movq -0x168(%rbp), %rdi
callq 0x1160
movq -0x188(%rbp), %rdi
callq 0x1160
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)