// File: /workspace/github_c_makefile_star2_O1/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 0x49ea(%rip), %rdi      # 0x6180
callq 0x1200
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 0x17e5
addq $-0x2, %r14
xorl %eax, %eax
movb 0x2(%rbx,%rax), %cl
testb %cl, %cl
je 0x17dd
movb %cl, (%r15,%rax)
incq %rax
cmpq %rax, %r14
jne 0x17d1
leaq -0x90(%rbp), %rbx
movq %r15, (%rbx)
leaq 0x2aa0(%rip), %rsi      # 0x4296
movq %r15, %rdi
movq %rbx, %rdx
callq 0x1290
movq %rax, %r12
movq (%rbx), %rdi
leaq 0x2ac5(%rip), %r14      # 0x42d3
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1290
movq (%rbx), %rdi
leaq 0x2ab2(%rip), %r15      # 0x42d5
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1290
movq (%rbx), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1290
movq (%rbx), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1290
movq (%rbx), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1290
movq %rax, -0x60(%rbp)
movq %r12, %rdi
callq 0x10b0
leaq 0xa(%rax), %rcx
leaq 0x19(%rax), %rbx
andq $-0x10, %rbx
movq %rsp, %r15
movq %r15, %r14
subq %rbx, %r14
movq %r14, %rsp
addq $0x7, %rax
xorl %r13d, %r13d
cmpq $0x4, %rcx
movl $0x0, %edx
cmovaeq %rax, %rdx
leaq 0x3(%r14), %rdi
xorl %esi, %esi
callq 0x10d0
negq %rbx
movb %r13b, 0x2(%r15,%rbx)
movw $0x2f2e, (%r14)         # imm = 0x2F2E
movq %r14, %rdi
movq %r12, -0x48(%rbp)
movq %r12, %rsi
callq 0x1270
movq %r14, %rdi
callq 0x10b0
movabsq $0x7374696d6d6f432f, %rcx # imm = 0x7374696D6D6F432F
movq %rcx, (%rax,%r14)
movq $0x0, -0x40(%rbp)
movb %r13b, 0x8(%rax,%r14)
movq %r14, %rdi
callq 0x1210
movq %rax, %r13
movl $0x100, %edi            # imm = 0x100
callq 0x11d0
movq %rax, %rbx
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
xorl %esi, %esi
callq 0x10d0
testq %r13, %r13
je 0x2042
movq %rbx, -0x38(%rbp)
leaq 0x2acf(%rip), %r12      # 0x43e5
movq %r13, %rdi
callq 0x1220
testq %rax, %rax
je 0x1a0e
movq %rax, %r15
leaq 0x13(%rax), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11e0
testl %eax, %eax
je 0x1957
movq %rbx, %rdi
leaq 0x2a9d(%rip), %rsi      # 0x43e4
callq 0x11e0
testl %eax, %eax
je 0x1957
cmpb $0x4, 0x12(%r15)
jne 0x1962
xorl %ebx, %ebx
testb %bl, %bl
je 0x1916
jmp 0x1a0e
movq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0x10b0
movq %rax, %r15
movq %rbx, %rdi
callq 0x10b0
movq %rsp, -0x50(%rbp)
addq %r15, %rax
addq $0x18, %rax
andq $-0x10, %rax
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq %r15, %rdi
movq %r12, %rsi
callq 0x1150
movq %r15, %rdi
callq 0x10b0
movabsq $0x7374696d6d6f432f, %rcx # imm = 0x7374696D6D6F432F
movq %rcx, (%rax,%r15)
movw $0x2f, 0x8(%rax,%r15)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1270
movq %r15, %rdi
callq 0x333a
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x11e0
testl %eax, %eax
sete %bl
jne 0x19fe
movq -0x38(%rbp), %rdi
movb $0x0, 0x2(%rdi)
movw $0x2f2e, (%rdi)         # imm = 0x2F2E
movq %r15, %rsi
callq 0x1270
movl $0x1, %eax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rsp
leaq 0x29dc(%rip), %r12      # 0x43e5
jmp 0x1959
movq %r13, %rdi
callq 0x1260
cmpl $0x1, -0x40(%rbp)
jne 0x2057
movq %r14, %rdi
callq 0x1210
movq %rax, %rbx
movq %rax, %rdi
callq 0x1220
testq %rax, %rax
movq -0x38(%rbp), %r15
je 0x1a8b
leaq 0x2a08(%rip), %r12      # 0x444b
leaq -0x490(%rbp), %r13
cmpb $0x4, 0x12(%rax)
je 0x1a7e
addq $0x13, %rax
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1060
movq %r13, %rdi
movq %r15, %rsi
callq 0x11e0
testl %eax, %eax
je 0x1a7e
movq %r13, %rdi
callq 0x1280
movq %rbx, %rdi
callq 0x1220
testq %rax, %rax
jne 0x1a4a
movq %rbx, %rdi
callq 0x1260
movq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0x10b0
movq %rsp, %rbx
addq $0x19, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1150
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 0x333a
leaq -0xa8(%rbp), %rdx
movq %rax, (%rdx)
leaq 0x269b(%rip), %rsi      # 0x4191
movq %rax, -0x88(%rbp)
movq %rax, %rdi
callq 0x1290
leaq -0xa0(%rbp), %rbx
movq %rax, (%rbx)
leaq 0x2780(%rip), %r14      # 0x4296
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1290
movq (%rbx), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1290
movq %rax, %rbx
movq %r12, %rdi
callq 0x10b0
movq %rsp, %r14
addq $0x73, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %r14, %rdi
movq %r12, %rsi
callq 0x1150
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 0x1210
movq %rax, -0x80(%rbp)
testq %rax, %rax
jne 0x1ba2
movq %r14, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x10c0
leaq 0x292c(%rip), %rsi      # 0x44d5
leaq -0x500(%rbp), %r15
movq %r15, %rdi
movq %r12, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1060
movq %r15, %rdi
callq 0x1130
leaq 0x2914(%rip), %rsi      # 0x44e3
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1060
movq %r15, %rdi
callq 0x1130
movq %rbx, %rdi
callq 0x1250
leal 0x1(%rax), %ebx
leaq -0x490(%rbp), %r14
movl $0x3e8, %edx            # imm = 0x3E8
movq %r14, %rdi
xorl %esi, %esi
callq 0x10d0
leaq 0x28dd(%rip), %rsi      # 0x44ec
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x1060
movq -0x90(%rbp), %r13
cmpb $0x0, (%r13)
je 0x1ff1
leaq 0x1(%r13), %rax
movq %rax, -0x40(%rbp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %r13, -0x38(%rbp)
movq %r13, %rdi
callq 0x10b0
cmpq %rbx, %rax
jb 0x1ff1
movslq %r15d, %rax
movb (%r13,%rax), %cl
cmpb $0x26, %cl
je 0x1c74
addq -0x40(%rbp), %rax
xorl %edx, %edx
movb %cl, -0x6a(%rbp,%rdx)
movb (%rax,%rdx), %cl
incq %rdx
cmpb $0x26, %cl
jne 0x1c62
addl %edx, %r15d
leaq -0x6a(%rbp), %rdi
callq 0x1250
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 0x1cbf
leal 0x1(%r15), %eax
movslq %eax, %rsi
addq %r13, %rsi
movl %ebx, %edx
movq %r14, %rdi
callq 0x1110
addl %ebx, %r15d
movslq %r15d, %r12
movb 0x2(%r13,%r12), %al
addq $0x2, %r12
cmpb $0x26, %al
je 0x1cec
movq %r12, %rdx
addq -0x40(%rbp), %rdx
xorl %ecx, %ecx
movb %al, -0x65(%rbp,%rcx)
movb (%rdx,%rcx), %al
incq %rcx
cmpb $0x26, %al
jne 0x1cd8
addl %r12d, %ecx
movl %ecx, %r12d
leaq -0x65(%rbp), %rdi
callq 0x1250
movl %eax, %r15d
leal 0x1(%r15), %eax
movq %rsp, %rbx
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
movslq %eax, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10d0
testl %r15d, %r15d
jle 0x1d3e
movslq %r12d, %rax
movl %r15d, %ecx
addq -0x40(%rbp), %rax
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, (%rbx,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x1d2b
addl %edx, %r12d
movq %r12, -0x50(%rbp)
movzbl (%r14), %r13d
movq %r14, %rdi
callq 0x10b0
movq %rax, %r15
movq %rsp, -0x60(%rbp)
leaq 0x1(%rax), %rdx
movq %rsp, %r12
addq $0x10, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %r12, %rdi
xorl %esi, %esi
callq 0x10d0
movl $0x1, %eax
cmpl $0x44, %r13d
je 0x1e19
cmpl $0x41, %r13d
jne 0x1e84
cmpq $0x2, %r15
movq -0x38(%rbp), %r13
jb 0x1dae
incq %r14
movq %r15, %rdx
decq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1110
movq %r15, %rax
movb $0x0, (%r12,%rax)
movq %r12, %rdi
movl $0x41, %esi
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x10f0
movl %eax, %r14d
movq %rbx, %rdi
callq 0x10b0
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x10a0
movl %r14d, %edi
callq 0x12b0
leaq -0x490(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x1270
movq %r14, %rdi
callq 0x10b0
movabsq $0x3a487e303a567e, %rcx # imm = 0x3A487E303A567E
movq %rcx, -0x490(%rbp,%rax)
jmp 0x1fad
cmpq $0x2, %r15
jb 0x1e36
incq %r14
movq %r15, %rdx
decq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1110
movq %r15, %rax
movb $0x0, (%r12,%rax)
movq %r12, %rdi
callq 0x10b0
movq %rsp, %rcx
addq $0x17, %rax
andq $-0x10, %rax
movq %rcx, %rbx
subq %rax, %rbx
movq %rbx, %rsp
negq %rax
movabsq $0x2066722d206d72, %rdx # imm = 0x2066722D206D72
movq %rdx, (%rcx,%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1270
movq %rbx, %rdi
callq 0x1130
movq -0x38(%rbp), %r13
jmp 0x1fd2
cmpq $0x2, %r15
movq -0x38(%rbp), %r13
jb 0x1ea5
incq %r14
movq %r15, %rdx
decq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1110
movq %r15, %rax
movb $0x0, (%r12,%rax)
movq %r12, %rdi
movl $0x41, %esi
movl $0x1ff, %edx            # imm = 0x1FF
xorl %eax, %eax
callq 0x10f0
movl %eax, %r14d
movq %rbx, %rdi
callq 0x10b0
movl %r14d, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x10a0
movl %r14d, %edi
callq 0x12b0
movq -0x78(%rbp), %rdi
callq 0x333a
movq %rax, %rdi
movq %r12, %rsi
callq 0x1070
movq %rax, -0x58(%rbp)
movq %rax, %rdi
leaq 0x2407(%rip), %r14      # 0x4308
movq %r14, %rsi
leaq -0x58(%rbp), %r15
movq %r15, %rdx
callq 0x1290
movq -0x58(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1290
movq %rax, -0x58(%rbp)
movq %rax, %rdi
leaq 0x25c5(%rip), %r14      # 0x44f2
movq %r14, %rsi
movq %r15, %rdx
callq 0x1290
movq -0x58(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1290
movq %rax, %rdi
callq 0x1250
leal 0x1(%rax), %edx
leaq -0x95(%rbp), %r15
movq %r15, %rdi
leaq 0x23a2(%rip), %rsi      # 0x4305
xorl %eax, %eax
callq 0x1060
leaq -0x490(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x1270
movq %r14, %rdi
callq 0x10b0
movl $0x3a567e, -0x490(%rbp,%rax) # imm = 0x3A567E
movq %r14, %rdi
movq %r15, %rsi
callq 0x1270
movq %r14, %rdi
callq 0x10b0
movl $0x3a487e, -0x490(%rbp,%rax) # imm = 0x3A487E
movq %rbx, %rdi
callq 0x33ce
movq %r14, %rdi
movq %rax, %rsi
callq 0x1270
movq %r14, %rdi
callq 0x10b0
movw $0xa, -0x490(%rbp,%rax)
movslq -0x50(%rbp), %rbx
addq $0x2, %rbx
movq -0x60(%rbp), %rsp
movq -0x48(%rbp), %rsp
cmpb $0x0, (%r13,%rbx)
movl %ebx, %r15d
jne 0x1c3e
movq -0x78(%rbp), %rdi
movl $0x201, %esi            # imm = 0x201
xorl %eax, %eax
callq 0x10f0
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 0x1190
movq -0x80(%rbp), %rdi
callq 0x1260
leaq 0x24b9(%rip), %rsi      # 0x44f4
movl $0x10, %edx
jmp 0x2063
xorl %edi, %edi
callq 0x1260
leaq 0x23a1(%rip), %rsi      # 0x43f1
movl $0x59, %edx
jmp 0x2063
leaq 0x23f3(%rip), %rsi      # 0x4451
movl $0x7a, %edx
movl -0x2c(%rbp), %edi
callq 0x10a0
leaq 0x410e(%rip), %rdi      # 0x6180
callq 0x1100
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq