// File: /workspace/github_cpp_makefile_star2_O2/Cristian-Castillo[P]Multithreaded-HTTP-Server/./httpserver_definitions.cpp
// Function: f_check_copy(char*, int)
void *f_check_copy(char *file_name, int clientSocket)
{
    /* 
       if a copy is not found in a directory then copyX_found = 0. 
       If file is found in the directory then copyX_found = 1  for X in (1,2,3)
    */
    int copy1_found, copy2_found, copy3_found;
    copy1_found = 0;
    copy2_found = 0;
    copy3_found = 0;

    /* Checking if the file requested by user exists in ./copy1 directory */
    DIR *dir;
    struct dirent *listD;
    dir = opendir("./copy1");
    
    if(dir == NULL){
        perror("Error: Unable to open current server directory copy1.\n)");
        copy1_found = 0;
    }
    else{
        while((listD = readdir(dir)) != NULL){
            if((strcmp(file_name, listD->d_name) == 0) && (listD->d_type == DT_REG)){
                copy1_found = 1;
            }
        }
    }
    dir = opendir("./copy2");
    
    if(dir == NULL){
        perror("Error: Unable to open current server directory copy2.\n)");
        copy2_found = 0;
    }
    else{
        while((listD = readdir(dir)) != NULL){

            if((strcmp(file_name, listD->d_name) == 0) && (listD->d_type == DT_REG)){
                copy2_found = 1;
            }
        }
    }
    dir = opendir("./copy3");
    
    if(dir == NULL){
        perror("Error: Unable to open current server directory copy3.\n)");
        copy3_found = 0;
    }
    else{
        while((listD = readdir(dir)) != NULL){
            if((strcmp(file_name, listD->d_name) == 0) && (listD->d_type == DT_REG)){
                copy3_found = 1;
            }
        }
    }
    closedir(dir);


    /* 
       If a file's permission is locking us out, then copyX_no_permission = 1. 
       But if we have the permission, copyX_no_permission = 0 
    */
    int copy1_no_permission, copy2_no_permission, copy3_no_permission;
    copy1_no_permission = 0;
    copy2_no_permission = 0;
    copy3_no_permission = 0;

    struct http_node *child;
    child = &spawnNode;

    /* Opening a file in directory ./copy1 */
    char path_with_name1[20]; 
    strcpy (path_with_name1,"copy1/");
    strcat (path_with_name1, file_name);

    int file_copy1 = open(path_with_name1, O_RDONLY,0664);
    if(copy1_found == 1){ /* Indicatese if file was found in directory */
    
    /* if this condition is met that means file in directory but no permission to open  //f_void_client_error_not_found(clientSocket);} */
        if(file_copy1 == -1) {copy1_no_permission = 1;}  
    }
    /* copy1_permission = f_int_permission_put(path_with_name1, clientSocket); */

    /* Opening a file in directory ./copy2 */
    char path_with_name2[20]; 

    strcpy (path_with_name2,"copy2/");

    strcat (path_with_name2, file_name);

    int file_copy2 = open(path_with_name2, O_RDONLY,0664);
    if(copy2_found == 1){
        if(file_copy2 == -1) {copy2_no_permission = 1;} /* {f_void_client_error_not_found(clientSocket);} */
    }
    /* copy2_permission = f_int_permission_put(path_with_name2, clientSocket); */

    /* Opening a file in directory ./copy3 */
    char path_with_name3[20]; 

    strcpy (path_with_name3,"copy3/");

    strcat (path_with_name3, file_name);

    int file_copy3 = open(path_with_name3, O_RDONLY,0664);
    if(copy3_found == 1){
        if(file_copy3 == -1){
            copy3_no_permission = 1; /* {f_void_client_error_not_found(clientSocket);} */
        } 
    }
    /* copy3_permission = f_int_permission_put(path_with_name3, clientSocket); */


    /* getting the content length of each file within each ./copyX directory for X in (1,2,3) */
    struct stat buf1;
    fstat(file_copy1,&buf1);
    int get_length1 = buf1.st_size;
    ////////////////////////////////////////////////////////////////////////////////////
    struct stat buf2;
    fstat(file_copy2,&buf2);
    int get_length2 = buf2.st_size;
    ////////////////////////////////////////////////////////////////////////////////////
    struct stat buf3;
    fstat(file_copy3,&buf3);
    int get_length3 = buf3.st_size;
    ////////////////////////////////////////////////////////////////////////////////////


    char *buff1 = (char*)malloc(get_length1*sizeof(char*));
    char *buff2 = (char*)malloc(get_length2*sizeof(char*));
    char *buff3 = (char*)malloc(get_length3*sizeof(char*));

    /* 
        If two files are found to be the same in regards to content length 
        and ascii character comparison, then copyXY = 1 
    */
    int copy12_same, copy13_same, copy23_same;
    copy12_same = copy13_same = copy23_same = 0;

    ssize_t check_bytes_recv1;
    ssize_t check_bytes_recv2;
    ssize_t check_bytes_recv3;

    /* Checking to see if the the file in ./copy1 is the same in ./copy2 in terms of ascii content and length */
    ssize_t write_bytes = 0;

    if((get_length1 == get_length2) && (file_copy1 != -1) && (file_copy2 !=-1)){
        lseek(file_copy1, 0*sizeof(char), SEEK_SET);
        lseek(file_copy2, 0*sizeof(char), SEEK_SET);
        while(((check_bytes_recv1 = read(file_copy1,buff1,get_length1)) >= 0) && ((check_bytes_recv2 = read(file_copy2,buff2,get_length2)) >= 0) ){
            write_bytes += check_bytes_recv1;
  
            sleep(2);
            /* comparing ascii values */
            if(strcmp(buff1,buff2) != 0){
                break;
            }
            if(write_bytes == get_length1){

                copy12_same = 1;
                break;
            }
        }
    }

     /* 
        Checking to see if the the file in ./copy1 is the same in
        ./copy3 in terms of ascii content and length 
    */
    memset(buff1, 0, get_length1);
    memset(buff2, 0, get_length2);
    
    if(copy12_same == 0 && (get_length1 == get_length3)  && (file_copy1 != -1) && (file_copy3 !=-1)){
        
            lseek(file_copy1, 0*sizeof(char), SEEK_SET);
            lseek(file_copy3, 0*sizeof(char), SEEK_SET);
            write_bytes = 0;
            
            while((check_bytes_recv1 = read(file_copy1,buff1,get_length1)) >= 0 && (check_bytes_recv3 = read(file_copy3,buff3,get_length3)) >= 0){
            write_bytes += check_bytes_recv1;
            
            if(strcmp(buff1,buff3) != 1){
                break;
            }
            if(write_bytes == get_length1){
    
                copy13_same = 1;
                break;
            }
        }
    }

    /* Checking to see if the the file in ./copy2 is the same in ./copy3 in terms of ascii content and length */
    memset(buff1, 0, get_length1);
    memset(buff3, 0, get_length3);
    
    if((copy12_same == 0) && (copy13_same == 0) && (get_length2 == get_length3)  && (file_copy2 != -1) && (file_copy3 !=-1)){
        
        lseek(file_copy2, 0*sizeof(char), SEEK_SET);
        lseek(file_copy3, 0*sizeof(char), SEEK_SET);
        write_bytes = 0;
        

        while((check_bytes_recv2 = read(file_copy2,buff2,get_length2)) >= 0 && (check_bytes_recv3 = read(file_copy3,buff3,get_length3)) >= 0){
            write_bytes += check_bytes_recv2;

            sleep(2);
            if(strcmp(buff2,buff3) != 0){
                break;
            }
            if(write_bytes == get_length2){
  
                copy23_same = 1;
                break;
            }
        }
    }
    memset(buff1, 0, get_length1);
    memset(buff3, 0, get_length3);

    lseek(file_copy1, 0*sizeof(char), SEEK_SET);
    lseek(file_copy2, 0*sizeof(char), SEEK_SET);
    
    free(buff1);
    free(buff2);
    free(buff3);

    close(file_copy3);

    /* 
       NOTE: the number of files that gives us no permission 
       to open is always less than or equal to the number of files that exist 
    */ 

    /* calculates the number of files that gives no permission for us to open in directorys ./copyX */
    int num_of_no_permission_files = copy1_no_permission + copy2_no_permission + copy3_no_permission;

    /* calculates the number of files that exists in the directory ./copyX */
    int num_of_files_that_exist = copy1_found + copy2_found + copy3_found;

    /* If all three files are not found or no permission, the status code should be 500 */
    if((num_of_files_that_exist == 0) || (num_of_no_permission_files == 3)){
       /* printf("500 internal error\n"); */
        close(file_copy1);
        close(file_copy2);
        f_void_intr_error(clientSocket);
    }

    /*  GET file with 2/3 or 3/3 files giving no permissions  */
    if(num_of_no_permission_files >=2 ){                
        /* printf("403 error per post @385 endosred by Daniel Alvs #2 & 3 ALSO @336 #1\n");*/
        close(file_copy1);
        close(file_copy2);
        f_void_client_error_forbid(clientSocket);
    }

    /*  GET file with 1/3 files giving no permissions, 1/3 files that don't exist, 1/3 files that do exist and we have permission */
    if((num_of_files_that_exist == 2) && (num_of_no_permission_files == 1)){                
        /* printf("500 error per post @385 endosred by Daniel Alvs #4 ALSO @336 #2\n"); */
        close(file_copy1);
        close(file_copy2);
        f_void_intr_error(clientSocket);
    }

    /*  GET with 2/3 files that don't exist, and file with 1/3 files giving no permissions   */
    if((num_of_files_that_exist == 1) && (num_of_no_permission_files == 1)){                
        /* printf("404 error per post @385 endosred by Daniel Alvs #5 ALSO @336 #3\n"); */
        close(file_copy1);
        close(file_copy2);
        f_void_client_error_not_found(clientSocket);
    }

    if(copy12_same == 1 || copy13_same == 1){

        /* sending HTTP 200 */
        f_client_req_found(file_copy1,clientSocket); 
        ssize_t send_bytes = 0;

        char *buffs = (char*)malloc(get_length1*sizeof(char*));

        /* Store file contents */
        while((child->content_length = read(file_copy1,buffs,sizeof(buffs))) != 0){

            /* printf("if you see then that means i am writing into the client socket\n"); */
            send_bytes +=  write(clientSocket,buffs,child->content_length);
            if(send_bytes == get_length1){break;}
        }
        close(file_copy1);
        close(file_copy2);
            
        if(child->content_length == 0){
            free(buffs);
            return NULL;
        }
        else{ 
            /* Internal error of 500 Content failuire*/
            f_void_intr_error(clientSocket);
            free(buffs);
            return NULL;   
        }

    }
    else if(copy23_same == 1){

        f_client_req_found(file_copy2,clientSocket);
        ssize_t send_bytes;

        char *buffs = (char*)malloc(get_length2*sizeof(char*));
        
        /* Store file contents */
        while((child->content_length = read(file_copy2,buffs,sizeof(buffs))) != 0){
            send_bytes =  write(clientSocket,buffs,child->content_length);
            if(send_bytes == get_length2){break;}
        }
        close(file_copy1);
        close(file_copy2);
            
        if(child->content_length == 0){
            free(buffs);
            return NULL;
        }
        else{ 
            /* Internal error of 500 Content failuire */
            f_void_intr_error(clientSocket);
            free(buffs);
            return NULL;
                
        }
    }
    else{
        close(file_copy1);
        close(file_copy2);
        f_void_intr_error(clientSocket);
        return NULL;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %esi, %r12d
movq %rdi, %rbx
leaq 0xe4e8(%rip), %rdi      # 0x13724
callq 0x4590
pushq $0x1
popq %rbp
testq %rax, %rax
je 0x527a
movq %rax, %r14
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x45b0
testq %rax, %rax
je 0x5289
movq %rax, %r15
leaq 0x13(%rax), %rsi
movq %rbx, %rdi
callq 0x4520
testl %eax, %eax
jne 0x524f
cmpb $0x8, 0x12(%r15)
cmovel %ebp, %r13d
jmp 0x524f
leaq 0xe4ab(%rip), %rdi      # 0x1372c
callq 0x4310
xorl %r13d, %r13d
leaq 0xe4d4(%rip), %rdi      # 0x13764
callq 0x4590
testq %rax, %rax
je 0x52d7
movq %rax, %r14
movl $0x0, 0x2c(%rsp)
movq %r14, %rdi
callq 0x45b0
testq %rax, %rax
je 0x52eb
movq %rax, %r15
leaq 0x13(%rax), %rsi
movq %rbx, %rdi
callq 0x4520
testl %eax, %eax
jne 0x52a5
cmpb $0x8, 0x12(%r15)
movl 0x2c(%rsp), %eax
cmovel %ebp, %eax
movl %eax, 0x2c(%rsp)
jmp 0x52a5
leaq 0xe48e(%rip), %rdi      # 0x1376c
callq 0x4310
movl $0x0, 0x2c(%rsp)
leaq 0xe4b2(%rip), %rdi      # 0x137a4
callq 0x4590
movq %rax, %r14
testq %rax, %rax
movl %r12d, 0x5c(%rsp)
je 0x533e
movl $0x0, 0x28(%rsp)
movq %r14, %rdi
callq 0x45b0
testq %rax, %rax
je 0x5352
movq %rax, %r15
leaq 0x13(%rax), %rsi
movq %rbx, %rdi
callq 0x4520
testl %eax, %eax
jne 0x530c
cmpb $0x8, 0x12(%r15)
movl 0x28(%rsp), %eax
cmovel %ebp, %eax
movl %eax, 0x28(%rsp)
jmp 0x530c
leaq 0xe467(%rip), %rdi      # 0x137ac
callq 0x4310
movl $0x0, 0x28(%rsp)
movq %r14, %rdi
callq 0x45e0
movl $0x79706f63, %r15d      # imm = 0x79706F63
leaq 0xc0(%rsp), %r14
movl %r15d, (%r14)
movl $0x2f3179, 0x3(%r14)    # imm = 0x2F3179
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4660
movl $0x0, 0x24(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x42b0
movl %eax, %r12d
movl %r13d, 0x58(%rsp)
movl %r13d, %eax
xorl $0x1, %eax
movl %r12d, %ecx
notl %ecx
orl %eax, %ecx
sete 0x40(%rsp)
leaq 0xa0(%rsp), %r14
movl %r15d, (%r14)
movl $0x2f3279, 0x3(%r14)    # imm = 0x2F3279
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4660
movq %r14, %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x42b0
movl %eax, %ebp
cmpl $0x1, 0x2c(%rsp)
sete 0x14(%rsp)
cmpl $-0x1, %eax
sete 0x10(%rsp)
leaq 0x80(%rsp), %r14
movl %r15d, (%r14)
movl $0x2f3379, 0x3(%r14)    # imm = 0x2F3379
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4660
movq %r14, %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x42b0
movl %eax, %r15d
movl 0x28(%rsp), %eax
xorl $0x1, %eax
movl %r15d, %ecx
notl %ecx
orl %eax, %ecx
sete 0x23(%rsp)
leaq 0x1f8(%rsp), %rbx
movl %r12d, 0x1c(%rsp)
movl %r12d, %edi
movq %rbx, %rsi
callq 0x4610
movq 0x30(%rbx), %r12
leaq 0x168(%rsp), %rbx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x4610
movq 0x30(%rbx), %r13
leaq 0xd8(%rsp), %rbx
movl %r15d, 0x18(%rsp)
movl %r15d, %edi
movq %rbx, %rsi
callq 0x4610
movq 0x30(%rbx), %r14
movq %r12, 0x30(%rsp)
movslq %r12d, %r15
leaq (,%r15,8), %rdi
movq %rdi, 0x78(%rsp)
callq 0x44f0
movq %rax, %rbx
movq %r13, 0x68(%rsp)
movslq %r13d, %rax
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rdi
movq %rdi, 0x70(%rsp)
callq 0x44f0
movq %rax, %r13
movq %r14, 0x60(%rsp)
movslq %r14d, %rax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rdi
callq 0x44f0
movq %rax, 0x38(%rsp)
movl %ebp, 0xc(%rsp)
movb $0x1, %al
cmpl $-0x1, %ebp
je 0x559b
movl %eax, 0x44(%rsp)
cmpl $-0x1, 0x1c(%rsp)
je 0x559f
movb $0x1, %r12b
movq 0x30(%rsp), %rax
cmpl 0x68(%rsp), %eax
movl $0x0, %r14d
jne 0x55a5
xorl %r12d, %r12d
movl 0x1c(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movl 0xc(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
pushq $0x2
popq %rbp
movl 0x1c(%rsp), %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x4550
testq %rax, %rax
js 0x5591
movq %rax, %r14
movl 0xc(%rsp), %edi
movq %r13, %rsi
movq 0x48(%rsp), %rdx
callq 0x4550
testq %rax, %rax
js 0x5591
movl %ebp, %edi
callq 0x42d0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4520
testl %eax, %eax
jne 0x5591
addq %r14, %r12
cmpq %r15, %r12
jne 0x553b
movb $0x1, %al
movl %eax, 0x24(%rsp)
xorl %r12d, %r12d
jmp 0x55a2
movl $0x0, 0x24(%rsp)
jmp 0x559f
movl %eax, 0x44(%rsp)
movb $0x1, %r12b
xorl %r14d, %r14d
movb 0x14(%rsp), %bpl
andb 0x10(%rsp), %bpl
movl $0x0, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x4220
movq %r13, %rdi
xorl %esi, %esi
movq 0x48(%rsp), %rdx
callq 0x4220
testb %r12b, %r12b
je 0x568c
cmpl $-0x1, 0x1c(%rsp)
movq 0x38(%rsp), %rdi
movl $0x0, %ecx
je 0x5695
cmpl $-0x1, 0x18(%rsp)
je 0x5695
movq 0x30(%rsp), %rax
cmpl 0x60(%rsp), %eax
jne 0x5695
movl %r12d, 0x30(%rsp)
movb %bpl, 0x14(%rsp)
xorl %r12d, %r12d
movl 0x1c(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movl 0x18(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movq 0x38(%rsp), %rbp
movl 0x1c(%rsp), %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x4550
testq %rax, %rax
js 0x569f
movq %rax, %r14
movl 0x18(%rsp), %edi
movq %rbp, %rsi
movq 0x50(%rsp), %rdx
callq 0x4550
testq %rax, %rax
js 0x56b0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4520
cmpl $0x1, %eax
jne 0x569f
addq %r14, %r12
cmpq %r15, %r12
jne 0x5637
movb $0x1, %al
movl %eax, 0x10(%rsp)
movl $0x0, 0x44(%rsp)
jmp 0x56a7
movq 0x38(%rsp), %rdi
xorl %ecx, %ecx
jmp 0x56ca
movl $0x0, 0x10(%rsp)
jmp 0x56ca
movl $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movq 0x38(%rsp), %rdi
jmp 0x56bd
movl $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movq %rbp, %rdi
movb 0x14(%rsp), %bpl
xorl %r14d, %r14d
movl 0x30(%rsp), %r12d
movb 0x40(%rsp), %al
movb %al, %r14b
movl %r14d, 0x14(%rsp)
movzbl %bpl, %eax
movl %eax, 0x30(%rsp)
movb 0x23(%rsp), %al
movb %al, %cl
movl %ecx, 0x40(%rsp)
xorl %r14d, %r14d
xorl %esi, %esi
movq 0x50(%rsp), %rdx
callq 0x4220
andb 0x44(%rsp), %r12b
cmpb $0x1, %r12b
jne 0x57a6
xorl %r14d, %r14d
cmpl $-0x1, 0xc(%rsp)
je 0x57a6
cmpl $-0x1, 0x18(%rsp)
je 0x57a6
movq 0x60(%rsp), %rax
cmpl %eax, 0x68(%rsp)
jne 0x57a6
xorl %ebp, %ebp
movl 0xc(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movl 0x18(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movq 0x48(%rsp), %rdx
movq 0x38(%rsp), %r12
movl 0xc(%rsp), %edi
movq %r13, %rsi
callq 0x4550
testq %rax, %rax
js 0x57a3
movq %rax, %r14
movl 0x18(%rsp), %edi
movq %r12, %rsi
movq 0x50(%rsp), %rdx
callq 0x4550
testq %rax, %rax
js 0x57a3
pushq $0x2
popq %rdi
callq 0x42d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x4520
testl %eax, %eax
jne 0x57a3
addq %r14, %rbp
movq 0x48(%rsp), %rdx
cmpq %rdx, %rbp
jne 0x5750
movb $0x1, %r14b
jmp 0x57a6
xorl %r14d, %r14d
movl 0x1c(%rsp), %ebp
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movl 0xc(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x46c0
movq %rbx, %rdi
callq 0x4430
movq %r13, %rdi
movl %ebp, %r13d
callq 0x4430
movq 0x38(%rsp), %rdi
callq 0x4430
movl 0x18(%rsp), %edi
callq 0x4700
movl 0x30(%rsp), %eax
addl 0x14(%rsp), %eax
addl 0x40(%rsp), %eax
movl 0x2c(%rsp), %ebx
addl 0x58(%rsp), %ebx
addl 0x28(%rsp), %ebx
movl 0x5c(%rsp), %ebp
je 0x580b
cmpl $0x3, %eax
jne 0x5829
movl %r13d, %edi
movl %eax, %r12d
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
movl %ebp, %edi
callq 0x4d86
movl %r12d, %eax
cmpl $0x2, %eax
jb 0x5848
movl %r13d, %edi
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
movl %ebp, %edi
callq 0x4ac3
jmp 0x588e
cmpl $0x2, %ebx
jne 0x586c
cmpl $0x1, %eax
jne 0x586c
movl %r13d, %edi
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
movl %ebp, %edi
callq 0x4d86
jmp 0x588e
cmpl $0x1, %ebx
jne 0x588e
cmpl $0x1, %eax
jne 0x588e
movl %r13d, %edi
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
movl %ebp, %edi
callq 0x4d78
movl 0x24(%rsp), %eax
orb 0x10(%rsp), %al
cmpb $0x1, %al
jne 0x58e7
movl %r13d, %edi
movl %ebp, %esi
callq 0x4e6f
movq 0x78(%rsp), %rdi
callq 0x44f0
movq %rax, %rbx
xorl %r14d, %r14d
pushq $0x8
popq %r12
movl %r13d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4550
movl %eax, 0x1a000(%rip)     # 0x1f8cc
testl %eax, %eax
je 0x5938
movslq %eax, %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x4130
addq %rax, %r14
cmpq %r15, %r14
jne 0x58b8
jmp 0x5938
testb %r14b, %r14b
je 0x5963
movl 0xc(%rsp), %edi
movl %ebp, %esi
callq 0x4e6f
movq 0x70(%rsp), %rdi
callq 0x44f0
movq %rax, %rbx
pushq $0x8
popq %r14
movq 0x48(%rsp), %r15
movl 0xc(%rsp), %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4550
movl %eax, 0x19faa(%rip)     # 0x1f8cc
testl %eax, %eax
je 0x5938
movslq %eax, %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x4130
cmpq %r15, %rax
jne 0x590d
movl %r13d, %edi
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
cmpl $0x0, 0x19f7c(%rip)     # 0x1f8cc
je 0x5959
movl %ebp, %edi
callq 0x4d86
movq %rbx, %rdi
callq 0x4430
jmp 0x597b
movl %r13d, %edi
callq 0x4700
movl 0xc(%rsp), %edi
callq 0x4700
movl %ebp, %edi
callq 0x4d86
xorl %eax, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq