// File: /workspace/github_c_makefile_star2_O3/evanwire[P]GitClone/server.c
// Function: push
void push(char* command, int connfd){
  //lock the repository
  pthread_mutex_lock(&lock);

  //Parse message from client
  char message[strlen(command) - 1];
  memset(message, 0, sizeof(message));
  int i;
  for(i = 2; i < strlen(command); i++){
      if(command[i]){
        message[i - 2] = command[i];
      }
      
  }

  //Isolate project name
  char* saveptr = message;
  char* projectName = strtok_r(saveptr, " ", &saveptr);

  char numberStorage[10];
  memset(numberStorage, '\0', 10);
  char* token = strtok_r(saveptr, "$", &saveptr);
  sprintf(numberStorage, "%s", token);

  int numFiles = atoi(numberStorage);

  token = strtok_r(saveptr, "&", &saveptr);
  token = strtok_r(saveptr, "&", &saveptr);
  token = strtok_r(saveptr, "&", &saveptr);
  char* commitContents = strtok_r(saveptr, "$", &saveptr);
  
  char* sendbuff;

  //Search for a commit file that matches the one that the client sent
  char commits_path[strlen(projectName) + 10];
  memset(commits_path, 0, strlen(projectName) + 10);
  strcpy(commits_path, "./");
  strcat(commits_path, projectName);
  strcat(commits_path, "/Commits");
  DIR* dir = opendir(commits_path);

  int does_commit_exist = 0;
  char* activeCommit = malloc(256 * sizeof(char));
  memset(activeCommit, 0, 256);


  //If commits directory does not exist, alert client they must create one first
  if(dir == NULL){
    closedir(dir);
    sendbuff = "\nError: no commits exist on the server currently. Run the commit command before you push.";
    write(connfd, sendbuff, strlen(sendbuff));
    pthread_mutex_unlock(&lock);
    return;
  }else{
    struct dirent* ent;
    int newCommitName = 0;
    //for each dirent in the directory
    while((ent = readdir(dir)) != NULL){
      char* fname = ent->d_name;
      //if its a folder, skip over it
      if(strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0 || ent->d_type  == DT_DIR){
        continue;

      //if it is not a folder, we can assume that the dirent is a file. Thus, we can open it and compare its contents to the message from the client
      }else{
        char pathOfCurrentCommit[strlen(projectName) + strlen(ent->d_name) + 9];
        strcpy(pathOfCurrentCommit, projectName);
        strcat(pathOfCurrentCommit, "/Commits/");
        strcat(pathOfCurrentCommit, ent->d_name);
        char* contents = readFile(pathOfCurrentCommit);
        if(strcmp(contents, commitContents) == 0){
          strcpy(activeCommit, "./");
          strcat(activeCommit, pathOfCurrentCommit);
          does_commit_exist = 1;
          break;
        }
      }
    }
  }
  closedir(dir);
  //If the commit exists on the server, delete all others
  if(does_commit_exist == 1){
    DIR* dir2 = opendir(commits_path);
    struct dirent* ent;
    char filepath[256];
    
    while((ent = readdir(dir2)) != NULL){
      if(ent->d_type == DT_DIR){
        continue;
      }
      sprintf(filepath, "%s/%s", commits_path, ent->d_name);
      if(strcmp(filepath, activeCommit) != 0){
        remove(filepath);
      }
      
    }
    closedir(dir2);

  //If the commit does not exist on the server, report that to the client
  }else{
    sendbuff = "\nError: no commit file exists on the server that matches the one you pushed. Please run the commit command before pushing.";
    write(connfd, sendbuff, strlen(sendbuff));
    pthread_mutex_unlock(&lock);
    return;
  }



  

  //Get the current project's version number to name the archive
  char manifestPath[strlen(projectName) + 10];
  strcpy(manifestPath, projectName);
  strcat(manifestPath, "/.Manifest");
  char* manifest_contents = readFile(manifestPath);
  char* aptr = manifest_contents;
  char* version_num = strtok_r(aptr, "\n", &aptr);
  char* aptr2 = version_num;
  version_num = strtok_r(aptr2, " ", &aptr2);
  version_num = strtok_r(aptr2, " ", &aptr2);
  //Store the current project in an archive
  char historyPath[strlen(projectName) + 100];
  strcpy(historyPath, projectName);
  strcat(historyPath, "/History");
  strcat(historyPath, "/");
  DIR* historydir = opendir(historyPath);
  if(historydir == NULL){
    int result = mkdir(historyPath, 0777);
  }
  char cmd[100];
  sprintf(cmd, "cp -avr %s %s", projectName, version_num);
  system(cmd);
  sprintf(cmd, "mv %s %s", version_num, historyPath);
  system(cmd);
  
  int vnum = atoi(version_num);
  vnum++;

  //prepare the write to the new manifest
  char manifestWrite[1000];
  memset(manifestWrite, '\0', 1000);
  sprintf(manifestWrite, "V %d\n", vnum);
  
  token = saveptr;
  int idx = 0;
  while(1){
    if(token[idx] == '\0' || idx > strlen(token)){
      break;
    }
    char file_name_sz[5];
    int subidx = 0;
    while(token[idx] != '&'){
      file_name_sz[subidx] = token[idx];
      idx++;
      subidx++;
    }
    idx++;
    int fn_size = atoi(file_name_sz);
    char file_name[fn_size + 1];
    memset(file_name, '\0', fn_size + 1);

    for(i = 0; i < fn_size; i++){
      file_name[i] = token[idx];
      idx++;
    }
    
    char file_sz[5];
    subidx = 0;
    idx++;
    while(token[idx] != '&'){
      file_sz[subidx] = token[idx];
      idx++;
      subidx++;
    }
    idx++;
    int file_size = atoi(file_sz);
    char file[file_size + 1];
    memset(file, '\0', file_size + 1);
    for(i = 0; i < file_size; i++){
      file[i] = token[idx];
      idx++;
    }
    idx++;


    if(file_name[0] == 'A'){
      char fn[strlen(file_name)+1];
      memset(fn, '\0', strlen(file_name) + 1);
      for(i = 1; i < strlen(file_name); i++){
        fn[i-1] = file_name[i];
      }
      fn[i] = '\0';

      int newFileFd = open(fn, O_WRONLY | O_CREAT, 0777);
      int b = write(newFileFd, file, strlen(file));
      close(newFileFd);

      strcat(manifestWrite, fn);
      strcat(manifestWrite, "~V:0~H:");
      strcat(manifestWrite, hashIt(file));
      strcat(manifestWrite, "\n");
    }else if(file_name[0] == 'D'){
      char fn[strlen(file_name)+1];
      memset(fn, '\0', strlen(file_name) + 1);
      for(i = 1; i < strlen(file_name); i++){
        fn[i-1] = file_name[i];
      }
      fn[i] = '\0';
      char cmdd[strlen(fn) + 8];
      strcpy(cmdd, "rm -rf ");
      strcat(cmdd, fn);
      system(cmdd);

    }else{
      char fn[strlen(file_name)+1];
      memset(fn, '\0', strlen(file_name) + 1);
      for(i = 1; i < strlen(file_name); i++){
        fn[i-1] = file_name[i];
      }
      fn[i] = '\0';

      int newFileFd = open(fn, O_WRONLY | O_CREAT, 0777);
      int b = write(newFileFd, file, strlen(file));
      close(newFileFd);

      char* idk = readFile(manifestPath);
      char* apointer = strstr(idk, fn);
      char* tokenizing = strtok_r(apointer, "~", &apointer);
      tokenizing = strtok_r(apointer, "~", &apointer);
      apointer = tokenizing;
      tokenizing = strtok_r(apointer, ":", &apointer);
      tokenizing = strtok_r(apointer, ":", &apointer);
      
      int newNum = atoi(tokenizing);
      newNum++;
      char buff[5];
      sprintf(buff, "%d", newNum);

      strcat(manifestWrite, fn);
      strcat(manifestWrite, "~V:");
      strcat(manifestWrite, buff);
      strcat(manifestWrite, "~H:");
      strcat(manifestWrite, hashIt(file));
      strcat(manifestWrite, "\n");

    }
    


  }
  

  int manfd = open(manifestPath, O_WRONLY | O_TRUNC);
  write(manfd, manifestWrite, strlen(manifestWrite));
  
  

  
  //Unlock the repository*/
  free(manifest_contents);
  closedir(historydir);
  sendbuff = "\nSuccessful push";
  write(connfd, sendbuff, strlen(sendbuff));
  pthread_mutex_unlock(&lock);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movl %esi, -0x2c(%rbp)
movq %rdi, %rbx
leaq 0x49e1(%rip), %rdi      # 0x6188
callq 0x1210
movq %rbx, %rdi
callq 0x10b0
movq %rax, %r14
leaq -0x1(%rax), %rdx
movq %rsp, %r15
addq $0xe, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
cmpq $0x3, %r14
jb 0x17f6
addq $-0x2, %r14
xorl %eax, %eax
movb 0x2(%rbx,%rax), %cl
testb %cl, %cl
je 0x17ee
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r14
jne 0x17e2
leaq -0x90(%rbp), %rbx
movq %r15, (%rbx)
leaq 0x2a8f(%rip), %rsi      # 0x4296
movq %r15, %rdi
movq %rbx, %rdx
callq 0x12a0
movq %rax, %r13
movq (%rbx), %rdi
leaq 0x2ab4(%rip), %r14      # 0x42d3
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12a0
movq (%rbx), %rdi
leaq 0x2aa1(%rip), %r12      # 0x42d5
movq %r12, %rsi
movq %rbx, %rdx
callq 0x12a0
movq (%rbx), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x12a0
movq (%rbx), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x12a0
movq (%rbx), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12a0
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x10b0
leaq 0xa(%rax), %rcx
leaq 0x19(%rax), %r15
andq $-0x10, %r15
movq %rsp, %r12
movq %r12, %r14
subq %r15, %r14
movq %r14, %rsp
addq $0x7, %rax
xorl %ebx, %ebx
cmpq $0x4, %rcx
movl $0x0, %edx
cmovaeq %rax, %rdx
leaq 0x3(%r14), %rdi
xorl %esi, %esi
callq 0x10d0
negq %r15
movb %bl, 0x2(%r12,%r15)
movw $0x2f2e, (%r14)         # imm = 0x2F2E
movq %r14, %rdi
movq %r13, -0x50(%rbp)
movq %r13, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x10b0
movabsq $0x7374696d6d6f432f, %rcx # imm = 0x7374696D6D6F432F
movq %rcx, (%rax,%r14)
movb %bl, 0x8(%rax,%r14)
movq %r14, -0x40(%rbp)
movq %r14, %rdi
callq 0x1220
movq %rax, %r13
movl $0x1, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x10f0
movq %rax, -0x38(%rbp)
testq %r13, %r13
je 0x19f6
movq %r13, %rdi
callq 0x1230
testq %rax, %rax
je 0x19dd
movq %rax, %rbx
movq -0x50(%rbp), %r14
cmpb $0x2e, 0x13(%rbx)
jne 0x1946
cmpb $0x0, 0x14(%rbx)
je 0x19c9
cmpb $0x2e, 0x14(%rbx)
jne 0x1946
cmpb $0x0, 0x15(%rbx)
je 0x19c9
cmpb $0x4, 0x12(%rbx)
je 0x19c9
addq $0x13, %rbx
movq %r14, %rdi
callq 0x10b0
movq %rax, %r12
movq %rbx, %rdi
callq 0x10b0
movq %rsp, %r15
addq %r12, %rax
addq $0x18, %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %r12, %rdi
movq %r14, %rsi
callq 0x1160
movq %r12, %rdi
callq 0x10b0
movabsq $0x7374696d6d6f432f, %rcx # imm = 0x7374696D6D6F432F
movq %rcx, (%rax,%r12)
movw $0x2f, 0x8(%rax,%r12)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1280
movq %r12, %rdi
callq 0x3333
movq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x11f0
testl %eax, %eax
je 0x1a0e
movq %r15, %rsp
movq %r13, %rdi
callq 0x1230
movq %rax, %rbx
testq %rax, %rax
jne 0x1926
movq %r13, %rdi
callq 0x1270
leaq 0x2a62(%rip), %rsi      # 0x444e
movl $0x7a, %edx
jmp 0x204a
xorl %edi, %edi
callq 0x1270
leaq 0x29ea(%rip), %rsi      # 0x43ee
movl $0x59, %edx
jmp 0x204a
movq -0x38(%rbp), %rdi
movb $0x0, 0x2(%rdi)
movw $0x2f2e, (%rdi)         # imm = 0x2F2E
movq %r12, %rsi
callq 0x1280
movq %r15, %rsp
movq %r13, %rdi
callq 0x1270
movq -0x40(%rbp), %rdi
callq 0x1220
movq %rax, %rbx
movq %rax, %rdi
callq 0x1230
testq %rax, %rax
je 0x1a98
leaq 0x29fa(%rip), %r12      # 0x4448
leaq -0x490(%rbp), %r13
cmpb $0x4, 0x12(%rax)
je 0x1a8b
addq $0x13, %rax
movq %r13, %rdi
movq %r12, %rsi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1060
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x11f0
testl %eax, %eax
je 0x1a8b
movq %r13, %rdi
callq 0x1290
movq %rbx, %rdi
callq 0x1230
testq %rax, %rax
jne 0x1a55
movq %rbx, %rdi
callq 0x1270
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x10b0
movq %rsp, %rbx
addq $0x19, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1160
movq %rbx, %rdi
callq 0x10b0
movabsq $0x6566696e614d2e2f, %rcx # imm = 0x6566696E614D2E2F
movq %rcx, (%rax,%rbx)
movl $0x747365, 0x7(%rax,%rbx) # imm = 0x747365
movq %rbx, -0x78(%rbp)
movq %rbx, %rdi
callq 0x3333
leaq -0xa8(%rbp), %rdx
movq %rax, (%rdx)
leaq 0x268e(%rip), %rsi      # 0x4191
movq %rax, -0x88(%rbp)
movq %rax, %rdi
callq 0x12a0
leaq -0xa0(%rbp), %rbx
movq %rax, (%rbx)
leaq 0x2773(%rip), %r14      # 0x4296
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12a0
movq (%rbx), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12a0
movq %rax, %rbx
movq %r15, %rdi
callq 0x10b0
movq %rsp, %r14
addq $0x73, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %r14, %rdi
movq %r15, %rsi
callq 0x1160
movq %r14, %rdi
callq 0x10b0
movabsq $0x79726f747369482f, %rcx # imm = 0x79726F747369482F
movq %rcx, (%rax,%r14)
movb $0x0, 0x8(%rax,%r14)
movq %r14, %rdi
callq 0x10b0
movw $0x2f, (%rax,%r14)
movq %r14, %rdi
callq 0x1220
movq %rax, -0x80(%rbp)
testq %rax, %rax
jne 0x1baf
movq %r14, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x10c0
leaq 0x291c(%rip), %rsi      # 0x44d2
leaq -0x500(%rbp), %r12
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1060
movq %r12, %rdi
callq 0x1140
leaq 0x2904(%rip), %rsi      # 0x44e0
movq %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1060
movq %r12, %rdi
callq 0x1140
movq %rbx, %rdi
callq 0x1260
leal 0x1(%rax), %ebx
leaq -0x490(%rbp), %r14
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rdi
xorl %esi, %esi
callq 0x10d0
leaq 0x28cd(%rip), %rsi      # 0x44e9
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1060
movq -0x90(%rbp), %r13
movb (%r13), %bl
testb %bl, %bl
je 0x1ffb
leaq 0x1(%r13), %rax
movq %rax, -0x38(%rbp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r13, -0x60(%rbp)
movq %r13, %rdi
callq 0x10b0
cmpq %r14, %rax
jb 0x1ffb
cmpb $0x26, %bl
je 0x1c7e
movslq %r15d, %rax
addq -0x38(%rbp), %rax
xorl %ecx, %ecx
movb %bl, -0x6a(%rbp,%rcx)
movb (%rax,%rcx), %bl
incq %rcx
cmpb $0x26, %bl
jne 0x1c6c
addl %ecx, %r15d
leaq -0x6a(%rbp), %rdi
callq 0x1260
movl %eax, %ebx
movq %rsp, -0x48(%rbp)
leal 0x1(%rbx), %eax
movq %rsp, %r14
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
movslq %eax, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10d0
testl %ebx, %ebx
jle 0x1cc9
leal 0x1(%r15), %eax
movslq %eax, %rsi
addq %r13, %rsi
movl %ebx, %edx
movq %r14, %rdi
callq 0x1120
addl %ebx, %r15d
movslq %r15d, %r12
movb 0x2(%r13,%r12), %al
addq $0x2, %r12
cmpb $0x26, %al
je 0x1cf6
movq %r12, %rdx
addq -0x38(%rbp), %rdx
xorl %ecx, %ecx
movb %al, -0x65(%rbp,%rcx)
movb (%rdx,%rcx), %al
incq %rcx
cmpb $0x26, %al
jne 0x1ce2
addl %r12d, %ecx
movl %ecx, %r12d
leaq -0x65(%rbp), %rdi
callq 0x1260
movl %eax, %ebx
leal 0x1(%rbx), %eax
movq %rsp, %r15
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
subq %rcx, %r15
movq %r15, %rsp
movslq %eax, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x10d0
testl %ebx, %ebx
jle 0x1d44
movslq %r12d, %rax
movl %ebx, %ecx
addq -0x38(%rbp), %rax
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, (%r15,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x1d31
addl %edx, %r12d
movq %r12, -0x50(%rbp)
movzbl (%r14), %r13d
movq %r14, %rdi
callq 0x10b0
movq %rax, %r12
movq %rsp, -0x40(%rbp)
leaq 0x1(%rax), %rdx
movq %rsp, %rbx
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10d0
movl $0x1, %eax
cmpl $0x44, %r13d
je 0x1e1e
cmpl $0x41, %r13d
jne 0x1e88
cmpq $0x2, %r12
movq -0x60(%rbp), %r13
jb 0x1db4
incq %r14
movq %r12, %rdx
decq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
movq %r12, %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
movl $0x41, %esi
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x1100
movl %eax, %r14d
movq %r15, %rdi
callq 0x10b0
movl %r14d, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10a0
movl %r14d, %edi
callq 0x12c0
leaq -0x490(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x10b0
movabsq $0x3a487e303a567e, %rcx # imm = 0x3A487E303A567E
movq %rcx, -0x490(%rbp,%rax)
jmp 0x1fb0
cmpq $0x2, %r12
jb 0x1e3b
incq %r14
movq %r12, %rdx
decq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
movq %r12, %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
callq 0x10b0
movq %rsp, %rcx
addq $0x17, %rax
andq $-0x10, %rax
movq %rcx, %r14
subq %rax, %r14
movq %r14, %rsp
negq %rax
movabsq $0x2066722d206d72, %rdx # imm = 0x2066722D206D72
movq %rdx, (%rcx,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x1140
movq -0x60(%rbp), %r13
jmp 0x1fd5
cmpq $0x2, %r12
movq -0x60(%rbp), %r13
jb 0x1ea9
incq %r14
movq %r12, %rdx
decq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1120
movq %r12, %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
movl $0x41, %esi
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x1100
movl %eax, %r14d
movq %r15, %rdi
callq 0x10b0
movl %r14d, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10a0
movl %r14d, %edi
callq 0x12c0
movq -0x78(%rbp), %rdi
callq 0x3333
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1070
movq %rax, -0x58(%rbp)
movq %rax, %rdi
leaq 0x2404(%rip), %r14      # 0x4308
movq %r14, %rsi
leaq -0x58(%rbp), %r12
movq %r12, %rdx
callq 0x12a0
movq -0x58(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x12a0
movq %rax, -0x58(%rbp)
movq %rax, %rdi
leaq 0x25bf(%rip), %r14      # 0x44ef
movq %r14, %rsi
movq %r12, %rdx
callq 0x12a0
movq -0x58(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x12a0
movq %rax, %rdi
callq 0x1260
leal 0x1(%rax), %edx
leaq -0x95(%rbp), %r12
movq %r12, %rdi
leaq 0x239f(%rip), %rsi      # 0x4305
xorl %eax, %eax
callq 0x1060
leaq -0x490(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x10b0
movl $0x3a567e, -0x490(%rbp,%rax) # imm = 0x3A567E
movq %r14, %rdi
movq %r12, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x10b0
movl $0x3a487e, -0x490(%rbp,%rax) # imm = 0x3A487E
movq %r15, %rdi
callq 0x33bf
movq %r14, %rdi
movq %rax, %rsi
callq 0x1280
movq %r14, %rdi
callq 0x10b0
movw $0xa, -0x490(%rbp,%rax)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq -0x50(%rbp), %r14
addq $0x2, %r14
movq %rcx, %rsp
movq %rax, %rsp
movb (%r13,%r14), %bl
movl %r14d, %r15d
testb %bl, %bl
jne 0x1c4d
movq -0x78(%rbp), %rdi
movl $0x201, %esi            # imm = 0x201
xorl %eax, %eax
callq 0x1100
movl %eax, %ebx
leaq -0x490(%rbp), %r14
movq %r14, %rdi
callq 0x10b0
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10a0
movq -0x88(%rbp), %rdi
callq 0x11a0
movq -0x80(%rbp), %rdi
callq 0x1270
leaq 0x24ac(%rip), %rsi      # 0x44f1
movl $0x10, %edx
movl -0x2c(%rbp), %edi
callq 0x10a0
leaq 0x412f(%rip), %rdi      # 0x6188
callq 0x1110
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq