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

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

  //Report if server responded with an error
  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);
  }
  
  //Verify the project exists on the client side
  DIR* dir = opendir(projectName);
  if(!dir){
    printf("\nError: the project you specified does not seem to exist on the client side. Please create the project before running again.\n");
    exit(1);
  }
  closedir(dir);

  char manifest_path[sizeof(projectName) + 10];
  strcpy(manifest_path, projectName);
  strcat(manifest_path, "/.Manifest");



  //Read client manifest contents to a single char*
  char* clientManifest = readFile(manifest_path);


  
  //initialize for tokenizing clientMan and serverMan by line
  char* clientToken;
  char* serverToken;
  char* serverSaveptr=malloc(strlen(response));
  char* clientSaveptr = malloc(strlen(clientManifest));
  strcpy(serverSaveptr,response);
  strcpy(clientSaveptr,clientManifest);

  //helper variables for comparisons
  //REMEMBER TO FREE UPDATE FILE PATH, CONFLICT FILE PATH, AND COMMAND AS NEEDED
  int update_fd;
  int conflict_fd;
  char* updateFilePath=(char*)malloc(strlen(projectName) + 8);
  strcpy(updateFilePath, projectName);
  strcat(updateFilePath, "/.Update");
  char* conflictFilePath=(char*)malloc(strlen(projectName) + 10);
  strcpy(conflictFilePath, projectName);
  strcat(conflictFilePath, "/.Conflict");
  clientToken=strtok_r(clientSaveptr,"\n",&clientSaveptr);
  serverToken=strtok_r(serverSaveptr,"\n",&serverSaveptr);
  char* command=(char*)malloc(strlen(projectName)+strlen(conflictFilePath)+30);

  //FULL SUCCESS CASE
  //check to see if client and server manifests are same version numbers
  //if so the client is up to date and .update can be empty.
  //create new update and remove old one
  strcpy(command,"rm -rf ");
  strcat(command,updateFilePath);
  system(command);
  command=(char*)malloc(sizeof(projectName)+sizeof(conflictFilePath)+30);
  strcpy(command,"rm -rf ");
  strcat(command,conflictFilePath);
  system(command);
  update_fd = open(updateFilePath, O_WRONLY | O_CREAT, 0777);
  if(strcmp(clientToken,serverToken)==0){
    //remove .Conflict

    printf("Up To Date\n");
    free(updateFilePath);
    free(conflictFilePath);
    close(update_fd);
    return;

  }
  char* serverManCopy=(char*)malloc(strlen(response)+1);
  strcpy(serverManCopy,response);
  char* serverSaveptr2;
  int bytes_written;
  char* serverLineCopy=(char*)malloc(strlen(response));

  //create loop to tokenize server and check for files the client needs to download
  //skip project version line
  serverToken=strtok_r(serverManCopy,"\n",&serverSaveptr2);
  while(serverToken=strtok_r(NULL,"\n",&serverSaveptr2)){
    char* innerServerSaveptr;
    char* innerServerToken;
    strcpy(serverLineCopy,serverToken);
    innerServerToken=strtok_r(serverLineCopy,"~",&innerServerSaveptr);
    //Server file name should be in innerServerToken
    //if it isn't in client manifest, client will be notifed to download
    //in .Update. Else, we continue
    if(strstr(clientManifest,innerServerToken)==NULL){
      strcpy(command,"A");
      strcat(command,serverToken);
      strcat(command,"\n");
      bytes_written = write(update_fd, command, strlen(command));
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Update. Will attempt to write the original information back into it.\n");
        exit(1);
      }
      printf(command);
    }

  }

  //now we must loop through and see if the client has files that the server got rid of
  char* clientManCopy=(char*)malloc(strlen(clientManifest)+1);
  strcpy(clientManCopy,clientManifest);
  char* clientSaveptr2;
  char* clientLineCopy=(char*)malloc(strlen(response));
  
  //skip project version line
  clientToken=strtok_r(clientManCopy,"\n",&clientSaveptr2);
  while(clientToken=strtok_r(NULL,"\n",&clientSaveptr2)){
    char* innerClientSaveptr;
    char* innerClientToken;
    strcpy(clientLineCopy,clientToken);
    innerClientToken=strtok_r(clientLineCopy,"~",&innerClientSaveptr);
    //Server file name should be in innerServerToken
    //if it isn't in client manifest, client will be notifed to download
    //in .Update. Else, we continue
    if(strstr(response,innerClientToken)==NULL){
      strcpy(command,"D");
      strcat(command,clientToken);
      strcat(command,"\n");
      bytes_written = write(update_fd, command, strlen(command));
      if(bytes_written < 0){
        printf("\nError: was unable to edit .Update. Will attempt to write the original information back into it.\n");
        exit(1);
      }
      printf(command);
    }

  }



  //loop for conflict and modify
  strcpy(serverManCopy,response);
  char* serverSaveptr3;
  char* innerClientToken3;
  char* innerServerToken3;
  char* filePath=(char*)malloc(strlen(clientManifest));
  char* liveHash=(char*)malloc(strlen(clientManifest));


  
  serverToken=strtok_r(serverManCopy,"\n",&serverSaveptr3);
  //for every file in server
  while(serverToken=strtok_r(NULL,"\n",&serverSaveptr3)){

    strcpy(clientManCopy,clientManifest);
    char* clientSaveptr3;
    clientToken =strtok_r(clientManCopy,"\n", &clientSaveptr3);

    //for every file in client
    while (clientToken=strtok_r(NULL,"\n", &clientSaveptr3)){
      char* innerServerSaveptr3;
      char* innerClientSaveptr3;
      //tokenize file names for each
      strcpy(clientLineCopy,clientToken);
      strcpy(serverLineCopy,serverToken);
      innerClientToken3=strtok_r(clientLineCopy,"~",&innerClientSaveptr3);
      innerServerToken3=strtok_r(serverLineCopy,"~",&innerServerSaveptr3);
      strcpy(filePath,innerClientToken3);



      //if the files have the same name we got some comparisons to make
      if(strcmp(innerClientToken3,innerServerToken3)==0){
        //now we check if the version numbers are the different
        innerClientToken3=strtok_r(NULL,"~",&innerClientSaveptr3);
        innerServerToken3=strtok_r(NULL,"~",&innerServerSaveptr3);

        //if they are different we must compare the live hash of the file
        //to the hash in the client manifest. If they are the same
        //its a modify. if they are different its a conflict
        if(strcmp(innerServerToken3,innerClientToken3)!=0){
          innerClientToken3=strtok_r(NULL,"~",&innerClientSaveptr3);
          char* fileContents=readFile(filePath);
          //innerClientToken3=strtok_r(NULL,"\n",&innerClientSaveptr3);

          char* fileHash=hashIt(fileContents);
          strcpy(liveHash,"H:");
          strcat(liveHash,fileHash);

          //if fileHashes are the same all it's a modify
          if(strcmp(liveHash,innerClientToken3)==0){
            strcpy(command,"M");
            strcat(command,serverToken);
            strcat(command,"\n");
            bytes_written = write(update_fd, command, strlen(command));
            if(bytes_written < 0){
              printf("\nError: was unable to edit .Update. Will attempt to write the original information back into it.\n");
              exit(1);
            }
            printf(command);
          }

          //else it's a conflict
          else{
            conflict_fd=open(conflictFilePath,O_WRONLY|O_CREAT|O_APPEND,0777);
            strcpy(command,"C");
            strcat(command,serverToken);
            strcat(command,"\n");
            bytes_written = write(conflict_fd, command, strlen(command));
            if(bytes_written < 0){
              printf("\nError: was unable to edit .Conflict. Will attempt to write the original information back into it.\n");
              exit(1);
            }
            printf(command);
            close(conflict_fd);
          }
          
          
        }

      }


    }
    
  }
  free(clientManCopy);
  free(serverManCopy);
  free(clientLineCopy);
  free(serverLineCopy);
  free(filePath);
  free(liveHash);
  free(conflictFilePath);
  free(updateFilePath);
  close(update_fd);
  return;
  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rdx
addq $0x3, %rdx
movq %rdx, -0x158(%rbp)
movq %rsp, %rcx
movq %rcx, -0x18(%rbp)
addq $0x12, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x150(%rbp)
movq %rdi, %rsp
movq %rdx, -0x20(%rbp)
xorl %esi, %esi
callq 0x10d0
movq -0x150(%rbp), %rax
movb $0x75, (%rax)
movb $0x20, 0x1(%rax)
movl $0x2, -0x24(%rbp)
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jae 0x23cc
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x23bf
movq -0x150(%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 0x23c1
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x236c
movq -0x150(%rbp), %rsi
movq -0x158(%rbp), %rdx
movq -0x8(%rbp), %rcx
leaq 0x50fd(%rip), %rdi      # 0x74e2
movb $0x0, %al
callq 0x1040
movq -0x150(%rbp), %rdi
callq 0x5be0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x57d3(%rip), %rsi      # 0x7bda
callq 0x1190
cmpl $0x0, %eax
jne 0x2429
leaq 0x50fd(%rip), %rdi      # 0x7515
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x30(%rbp), %rdi
leaq 0x4c41(%rip), %rsi      # 0x7075
callq 0x1190
cmpl $0x0, %eax
jne 0x2456
leaq 0x515b(%rip), %rdi      # 0x75a0
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
jmp 0x2458
movq -0x8(%rbp), %rdi
callq 0x11b0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x2484
leaq 0x5274(%rip), %rdi      # 0x76e7
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x38(%rbp), %rdi
callq 0x11e0
leaq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
leaq -0x50(%rbp), %rdi
leaq 0x51fc(%rip), %rsi      # 0x76a1
callq 0x1200
leaq -0x50(%rbp), %rdi
callq 0x5e50
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1140
movq -0x78(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1180
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
movq -0x88(%rbp), %rdi
leaq 0x5879(%rip), %rsi      # 0x7dae
callq 0x1200
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0xa, %rdi
callq 0x1180
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1140
movq -0x90(%rbp), %rdi
leaq 0x5894(%rip), %rsi      # 0x7e08
callq 0x1200
movq -0x78(%rbp), %rdi
leaq 0x5bc5(%rip), %rsi      # 0x8149
leaq -0x78(%rbp), %rdx
callq 0x1210
movq %rax, -0x60(%rbp)
movq -0x70(%rbp), %rdi
leaq 0x5bad(%rip), %rsi      # 0x8149
leaq -0x70(%rbp), %rdx
callq 0x1210
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10b0
movq %rax, -0x168(%rbp)
movq -0x90(%rbp), %rdi
callq 0x10b0
movq -0x168(%rbp), %rdi
addq %rax, %rdi
addq $0x1e, %rdi
callq 0x1180
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
leaq 0x5a58(%rip), %rsi      # 0x8045
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
callq 0x1120
movl $0x2e, %edi
callq 0x1180
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
leaq 0x5a15(%rip), %rsi      # 0x8045
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
callq 0x1120
movq -0x88(%rbp), %rdi
movl $0x41, %esi
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x10f0
movl %eax, -0x7c(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
jne 0x26be
leaq 0x5acd(%rip), %rdi      # 0x8155
movb $0x0, %al
callq 0x1040
movq -0x88(%rbp), %rdi
callq 0x1160
movq -0x90(%rbp), %rdi
callq 0x1160
movl -0x7c(%rbp), %edi
callq 0x1220
movl $0x1, -0x9c(%rbp)
jmp 0x2de5
movq -0x30(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1140
movq -0x30(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rdi
leaq 0x5a39(%rip), %rsi      # 0x8149
leaq -0xb0(%rbp), %rdx
callq 0x1210
movq %rax, -0x68(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x5a1e(%rip), %rsi      # 0x8149
leaq -0xb0(%rbp), %rdx
callq 0x1210
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x2838
movq -0xc0(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1140
movq -0xc0(%rbp), %rdi
leaq 0x584f(%rip), %rsi      # 0x7fb2
leaq -0xc8(%rbp), %rdx
callq 0x1210
movq %rax, -0xd0(%rbp)
movq -0x58(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x1070
cmpq $0x0, %rax
jne 0x2833
movq -0x98(%rbp), %rdi
leaq 0x59c3(%rip), %rsi      # 0x8161
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
leaq 0x5988(%rip), %rsi      # 0x8149
callq 0x1200
movl -0x7c(%rbp), %eax
movl %eax, -0x174(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x98(%rbp), %rdi
callq 0x10b0
movl -0x174(%rbp), %edi
movq -0x170(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jge 0x2825
leaq 0x594f(%rip), %rdi      # 0x8163
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x98(%rbp), %rdi
movb $0x0, %al
callq 0x1040
jmp 0x2720
movq -0x58(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1180
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1140
movq -0x30(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0xe8(%rbp)
movq -0xd8(%rbp), %rdi
leaq 0x58bf(%rip), %rsi      # 0x8149
leaq -0xe0(%rbp), %rdx
callq 0x1210
movq %rax, -0x60(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x58a4(%rip), %rsi      # 0x8149
leaq -0xe0(%rbp), %rdx
callq 0x1210
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x29b2
movq -0xe8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1140
movq -0xe8(%rbp), %rdi
leaq 0x56d5(%rip), %rsi      # 0x7fb2
leaq -0xf0(%rbp), %rdx
callq 0x1210
movq %rax, -0xf8(%rbp)
movq -0x30(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x1070
cmpq $0x0, %rax
jne 0x29ad
movq -0x98(%rbp), %rdi
leaq 0x4ff1(%rip), %rsi      # 0x7909
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
leaq 0x580e(%rip), %rsi      # 0x8149
callq 0x1200
movl -0x7c(%rbp), %eax
movl %eax, -0x184(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x98(%rbp), %rdi
callq 0x10b0
movl -0x184(%rbp), %edi
movq -0x180(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jge 0x299f
leaq 0x57d5(%rip), %rdi      # 0x8163
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x98(%rbp), %rdi
movb $0x0, %al
callq 0x1040
jmp 0x289a
movq -0xa8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1140
movq -0x58(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0x118(%rbp)
movq -0x58(%rbp), %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1180
movq %rax, -0x120(%rbp)
movq -0xa8(%rbp), %rdi
leaq 0x5749(%rip), %rsi      # 0x8149
leaq -0x100(%rbp), %rdx
callq 0x1210
movq %rax, -0x68(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x572e(%rip), %rsi      # 0x8149
leaq -0x100(%rbp), %rdx
callq 0x1210
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x2d73
movq -0xd8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1140
movq -0xd8(%rbp), %rdi
leaq 0x56f6(%rip), %rsi      # 0x8149
leaq -0x128(%rbp), %rdx
callq 0x1210
movq %rax, -0x60(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x56db(%rip), %rsi      # 0x8149
leaq -0x128(%rbp), %rdx
callq 0x1210
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x2d6e
movq -0xe8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x1140
movq -0xc0(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1140
movq -0xe8(%rbp), %rdi
leaq 0x54fc(%rip), %rsi      # 0x7fb2
leaq -0x138(%rbp), %rdx
callq 0x1210
movq %rax, -0x108(%rbp)
movq -0xc0(%rbp), %rdi
leaq 0x54db(%rip), %rsi      # 0x7fb2
leaq -0x130(%rbp), %rdx
callq 0x1210
movq %rax, -0x110(%rbp)
movq -0x118(%rbp), %rdi
movq -0x108(%rbp), %rsi
callq 0x1140
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
jne 0x2d69
xorl %eax, %eax
movl %eax, %edi
leaq 0x548e(%rip), %rsi      # 0x7fb2
leaq -0x138(%rbp), %rdx
callq 0x1210
movq %rax, -0x108(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x5470(%rip), %rsi      # 0x7fb2
leaq -0x130(%rbp), %rdx
callq 0x1210
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
je 0x2d67
xorl %eax, %eax
movl %eax, %edi
leaq 0x5436(%rip), %rsi      # 0x7fb2
leaq -0x138(%rbp), %rdx
callq 0x1210
movq %rax, -0x108(%rbp)
movq -0x118(%rbp), %rdi
callq 0x5e50
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rdi
callq 0x5f60
movq %rax, -0x148(%rbp)
movq -0x120(%rbp), %rdi
leaq 0x4c96(%rip), %rsi      # 0x7859
callq 0x1140
movq -0x120(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x1200
movq -0x120(%rbp), %rdi
movq -0x108(%rbp), %rsi
callq 0x1190
cmpl $0x0, %eax
jne 0x2c9f
movq -0x98(%rbp), %rdi
leaq 0x5448(%rip), %rsi      # 0x804d
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
leaq 0x5521(%rip), %rsi      # 0x8149
callq 0x1200
movl -0x7c(%rbp), %eax
movl %eax, -0x194(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x98(%rbp), %rdi
callq 0x10b0
movl -0x194(%rbp), %edi
movq -0x190(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jge 0x2c8c
leaq 0x54e8(%rip), %rdi      # 0x8163
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x98(%rbp), %rdi
movb $0x0, %al
callq 0x1040
jmp 0x2d65
movq -0x90(%rbp), %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x1ff, %edx            # imm = 0x1FF
movb $0x0, %al
callq 0x10f0
movl %eax, -0x80(%rbp)
movq -0x98(%rbp), %rdi
leaq 0x54fd(%rip), %rsi      # 0x81c5
callq 0x1140
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x1200
movq -0x98(%rbp), %rdi
leaq 0x545e(%rip), %rsi      # 0x8149
callq 0x1200
movl -0x80(%rbp), %eax
movl %eax, -0x1a4(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x10b0
movl -0x1a4(%rbp), %edi
movq -0x1a0(%rbp), %rsi
movq %rax, %rdx
callq 0x1090
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jge 0x2d4f
leaq 0x5489(%rip), %rdi      # 0x81c7
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movq -0x98(%rbp), %rdi
movb $0x0, %al
callq 0x1040
movl -0x80(%rbp), %edi
callq 0x1220
jmp 0x2d67
jmp 0x2d69
jmp 0x2a63
jmp 0x2a10
movq -0xd8(%rbp), %rdi
callq 0x1160
movq -0xa8(%rbp), %rdi
callq 0x1160
movq -0xe8(%rbp), %rdi
callq 0x1160
movq -0xc0(%rbp), %rdi
callq 0x1160
movq -0x118(%rbp), %rdi
callq 0x1160
movq -0x120(%rbp), %rdi
callq 0x1160
movq -0x90(%rbp), %rdi
callq 0x1160
movq -0x88(%rbp), %rdi
callq 0x1160
movl -0x7c(%rbp), %edi
callq 0x1220
movl $0x1, -0x9c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)