// File: 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
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
leaq 0x2e9ac(%rip), %rdi     # 0x357da
callq 0x5700
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6e53
leaq 0x2e99d(%rip), %rdi     # 0x357e2
callq 0x53f0
movl $0x0, -0x18(%rbp)
jmp 0x6e96
jmp 0x6e55
movq -0x28(%rbp), %rdi
callq 0x5720
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6e94
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x13, %rsi
callq 0x5670
cmpl $0x0, %eax
jne 0x6e92
movq -0x30(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x6e92
movl $0x1, -0x18(%rbp)
jmp 0x6e55
jmp 0x6e96
leaq 0x2e97d(%rip), %rdi     # 0x3581a
callq 0x5700
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6ec2
leaq 0x2e96e(%rip), %rdi     # 0x35822
callq 0x53f0
movl $0x0, -0x1c(%rbp)
jmp 0x6f05
jmp 0x6ec4
movq -0x28(%rbp), %rdi
callq 0x5720
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6f03
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x13, %rsi
callq 0x5670
cmpl $0x0, %eax
jne 0x6f01
movq -0x30(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x6f01
movl $0x1, -0x1c(%rbp)
jmp 0x6ec4
jmp 0x6f05
leaq 0x2e94e(%rip), %rdi     # 0x3585a
callq 0x5700
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6f31
leaq 0x2e93f(%rip), %rdi     # 0x35862
callq 0x53f0
movl $0x0, -0x20(%rbp)
jmp 0x6f74
jmp 0x6f33
movq -0x28(%rbp), %rdi
callq 0x5720
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6f72
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x13, %rsi
callq 0x5670
cmpl $0x0, %eax
jne 0x6f70
movq -0x30(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x6f70
movl $0x1, -0x20(%rbp)
jmp 0x6f33
jmp 0x6f74
movq -0x28(%rbp), %rdi
callq 0x5750
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
leaq 0x48a23(%rip), %rax     # 0x4f9bc
movq %rax, -0x48(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x2e81d(%rip), %rsi     # 0x357c5
callq 0x5450
leaq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5820
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
movb $0x0, %al
callq 0x5380
movl %eax, -0x64(%rbp)
cmpl $0x1, -0x18(%rbp)
jne 0x6fe4
cmpl $-0x1, -0x64(%rbp)
jne 0x6fe2
movl $0x1, -0x34(%rbp)
jmp 0x6fe4
leaq -0x80(%rbp), %rdi
leaq 0x2e7dd(%rip), %rsi     # 0x357cc
callq 0x5450
leaq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5820
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
movb $0x0, %al
callq 0x5380
movl %eax, -0x84(%rbp)
cmpl $0x1, -0x1c(%rbp)
jne 0x7031
cmpl $-0x1, -0x84(%rbp)
jne 0x702f
movl $0x1, -0x38(%rbp)
jmp 0x7031
leaq -0xa0(%rbp), %rdi
leaq 0x2e794(%rip), %rsi     # 0x357d3
callq 0x5450
leaq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5820
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x1b4, %edx            # imm = 0x1B4
movb $0x0, %al
callq 0x5380
movl %eax, -0xa4(%rbp)
cmpl $0x1, -0x20(%rbp)
jne 0x7087
cmpl $-0x1, -0xa4(%rbp)
jne 0x7085
movl $0x1, -0x3c(%rbp)
jmp 0x7087
movl -0x64(%rbp), %edi
leaq -0x138(%rbp), %rsi
callq 0x57a0
movq -0x108(%rbp), %rax
movl %eax, -0x13c(%rbp)
movl -0x84(%rbp), %edi
leaq -0x1d0(%rbp), %rsi
callq 0x57a0
movq -0x1a0(%rbp), %rax
movl %eax, -0x1d4(%rbp)
movl -0xa4(%rbp), %edi
leaq -0x268(%rbp), %rsi
callq 0x57a0
movq -0x238(%rbp), %rax
movl %eax, -0x26c(%rbp)
movslq -0x13c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x5640
movq %rax, -0x278(%rbp)
movslq -0x1d4(%rbp), %rdi
shlq $0x3, %rdi
callq 0x5640
movq %rax, -0x280(%rbp)
movslq -0x26c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x5640
movq %rax, -0x288(%rbp)
movl $0x0, -0x294(%rbp)
movl $0x0, -0x290(%rbp)
movl $0x0, -0x28c(%rbp)
movq $0x0, -0x2b8(%rbp)
movl -0x13c(%rbp), %eax
cmpl -0x1d4(%rbp), %eax
jne 0x725d
cmpl $-0x1, -0x64(%rbp)
je 0x725d
cmpl $-0x1, -0x84(%rbp)
je 0x725d
movl -0x64(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movl -0x84(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movl -0x64(%rbp), %edi
movq -0x278(%rbp), %rsi
movslq -0x13c(%rbp), %rdx
callq 0x56b0
movq %rax, %rcx
movq %rcx, -0x2a0(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x2e1(%rbp)
jl 0x71f2
movl -0x84(%rbp), %edi
movq -0x280(%rbp), %rsi
movslq -0x1d4(%rbp), %rdx
callq 0x56b0
movq %rax, -0x2a8(%rbp)
cmpq $0x0, %rax
setge %al
movb %al, -0x2e1(%rbp)
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x71fe
jmp 0x725b
movq -0x2a0(%rbp), %rax
addq -0x2b8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movl $0x2, %edi
callq 0x53a0
movq -0x278(%rbp), %rdi
movq -0x280(%rbp), %rsi
callq 0x5670
cmpl $0x0, %eax
je 0x7237
jmp 0x725b
movq -0x2b8(%rbp), %rax
movslq -0x13c(%rbp), %rcx
cmpq %rcx, %rax
jne 0x7256
movl $0x1, -0x28c(%rbp)
jmp 0x725b
jmp 0x7197
jmp 0x725d
movq -0x278(%rbp), %rdi
movslq -0x13c(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
movq -0x280(%rbp), %rdi
movslq -0x1d4(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
cmpl $0x0, -0x28c(%rbp)
jne 0x73a3
movl -0x13c(%rbp), %eax
cmpl -0x26c(%rbp), %eax
jne 0x73a3
cmpl $-0x1, -0x64(%rbp)
je 0x73a3
cmpl $-0x1, -0xa4(%rbp)
je 0x73a3
movl -0x64(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movl -0xa4(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movq $0x0, -0x2b8(%rbp)
movl -0x64(%rbp), %edi
movq -0x278(%rbp), %rsi
movslq -0x13c(%rbp), %rdx
callq 0x56b0
movq %rax, %rcx
movq %rcx, -0x2a0(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x2e2(%rbp)
jl 0x7342
movl -0xa4(%rbp), %edi
movq -0x288(%rbp), %rsi
movslq -0x26c(%rbp), %rdx
callq 0x56b0
movq %rax, -0x2b0(%rbp)
cmpq $0x0, %rax
setge %al
movb %al, -0x2e2(%rbp)
movb -0x2e2(%rbp), %al
testb $0x1, %al
jne 0x734e
jmp 0x73a1
movq -0x2a0(%rbp), %rax
addq -0x2b8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x278(%rbp), %rdi
movq -0x288(%rbp), %rsi
callq 0x5670
cmpl $0x1, %eax
je 0x737d
jmp 0x73a1
movq -0x2b8(%rbp), %rax
movslq -0x13c(%rbp), %rcx
cmpq %rcx, %rax
jne 0x739c
movl $0x1, -0x290(%rbp)
jmp 0x73a1
jmp 0x72e7
jmp 0x73a3
movq -0x278(%rbp), %rdi
movslq -0x13c(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
movq -0x288(%rbp), %rdi
movslq -0x26c(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
cmpl $0x0, -0x28c(%rbp)
jne 0x7509
cmpl $0x0, -0x290(%rbp)
jne 0x7509
movl -0x1d4(%rbp), %eax
cmpl -0x26c(%rbp), %eax
jne 0x7509
cmpl $-0x1, -0x84(%rbp)
je 0x7509
cmpl $-0x1, -0xa4(%rbp)
je 0x7509
movl -0x84(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movl -0xa4(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movq $0x0, -0x2b8(%rbp)
movl -0x84(%rbp), %edi
movq -0x280(%rbp), %rsi
movslq -0x1d4(%rbp), %rdx
callq 0x56b0
movq %rax, %rcx
movq %rcx, -0x2a8(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x2e3(%rbp)
jl 0x749e
movl -0xa4(%rbp), %edi
movq -0x288(%rbp), %rsi
movslq -0x26c(%rbp), %rdx
callq 0x56b0
movq %rax, -0x2b0(%rbp)
cmpq $0x0, %rax
setge %al
movb %al, -0x2e3(%rbp)
movb -0x2e3(%rbp), %al
testb $0x1, %al
jne 0x74aa
jmp 0x7507
movq -0x2a8(%rbp), %rax
addq -0x2b8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movl $0x2, %edi
callq 0x53a0
movq -0x280(%rbp), %rdi
movq -0x288(%rbp), %rsi
callq 0x5670
cmpl $0x0, %eax
je 0x74e3
jmp 0x7507
movq -0x2b8(%rbp), %rax
movslq -0x1d4(%rbp), %rcx
cmpq %rcx, %rax
jne 0x7502
movl $0x1, -0x294(%rbp)
jmp 0x7507
jmp 0x7440
jmp 0x7509
movq -0x278(%rbp), %rdi
movslq -0x13c(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
movq -0x288(%rbp), %rdi
movslq -0x26c(%rbp), %rdx
xorl %esi, %esi
callq 0x5260
movl -0x64(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movl -0x84(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x5880
movq -0x278(%rbp), %rdi
callq 0x5560
movq -0x280(%rbp), %rdi
callq 0x5560
movq -0x288(%rbp), %rdi
callq 0x5560
movl -0xa4(%rbp), %edi
callq 0x58b0
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x2bc(%rbp)
movl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x2c0(%rbp)
cmpl $0x0, -0x2c0(%rbp)
je 0x75b1
cmpl $0x3, -0x2bc(%rbp)
jne 0x75cc
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movl -0x14(%rbp), %edi
callq 0x64a0
cmpl $0x2, -0x2bc(%rbp)
jl 0x75f0
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movl -0x14(%rbp), %edi
callq 0x5ec0
cmpl $0x2, -0x2c0(%rbp)
jne 0x761d
cmpl $0x1, -0x2bc(%rbp)
jne 0x761d
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movl -0x14(%rbp), %edi
callq 0x64a0
cmpl $0x1, -0x2c0(%rbp)
jne 0x764a
cmpl $0x1, -0x2bc(%rbp)
jne 0x764a
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movl -0x14(%rbp), %edi
callq 0x6470
cmpl $0x1, -0x28c(%rbp)
je 0x7660
cmpl $0x1, -0x290(%rbp)
jne 0x773d
movl -0x64(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x6700
movq $0x0, -0x2c8(%rbp)
movslq -0x13c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x5640
movq %rax, -0x2d0(%rbp)
movl -0x64(%rbp), %edi
movq -0x2d0(%rbp), %rsi
movl $0x8, %edx
callq 0x56b0
movq -0x48(%rbp), %rcx
movl %eax, (%rcx)
cmpl $0x0, %eax
je 0x76e7
movl -0x14(%rbp), %edi
movq -0x2d0(%rbp), %rsi
movq -0x48(%rbp), %rax
movslq (%rax), %rdx
callq 0x5170
addq -0x2c8(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0x2c8(%rbp), %rax
movslq -0x13c(%rbp), %rcx
cmpq %rcx, %rax
jne 0x76e5
jmp 0x76e7
jmp 0x768d
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movq -0x48(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x771c
movq -0x2d0(%rbp), %rdi
callq 0x5560
movq $0x0, -0x8(%rbp)
jmp 0x7838
movl -0x14(%rbp), %edi
callq 0x64a0
movq -0x2d0(%rbp), %rdi
callq 0x5560
movq $0x0, -0x8(%rbp)
jmp 0x7838
cmpl $0x1, -0x294(%rbp)
jne 0x7815
movl -0x84(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x6700
movslq -0x1d4(%rbp), %rdi
shlq $0x3, %rdi
callq 0x5640
movq %rax, -0x2e0(%rbp)
movl -0x84(%rbp), %edi
movq -0x2e0(%rbp), %rsi
movl $0x8, %edx
callq 0x56b0
movq -0x48(%rbp), %rcx
movl %eax, (%rcx)
cmpl $0x0, %eax
je 0x77c5
movl -0x14(%rbp), %edi
movq -0x2e0(%rbp), %rsi
movq -0x48(%rbp), %rax
movslq (%rax), %rdx
callq 0x5170
movq %rax, -0x2d8(%rbp)
movq -0x2d8(%rbp), %rax
movslq -0x1d4(%rbp), %rcx
cmpq %rcx, %rax
jne 0x77c3
jmp 0x77c5
jmp 0x776f
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movq -0x48(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x77f7
movq -0x2e0(%rbp), %rdi
callq 0x5560
movq $0x0, -0x8(%rbp)
jmp 0x7838
movl -0x14(%rbp), %edi
callq 0x64a0
movq -0x2e0(%rbp), %rdi
callq 0x5560
movq $0x0, -0x8(%rbp)
jmp 0x7838
movl -0x64(%rbp), %edi
callq 0x58b0
movl -0x84(%rbp), %edi
callq 0x58b0
movl -0x14(%rbp), %edi
callq 0x64a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
nopw %cs:(%rax,%rax)