// File: myudelson[P]hmm-scalable/utils.cpp
// Function: projectsimplexbounded(double*, double*, double*, signed char)
void projectsimplexbounded(NUMBER* ar, NUMBER *lb, NUMBER *ub, NPAR size) {
	NPAR i, num_at_hi, num_at_lo; // number of elements at lower,upper boundary
	NPAR *at_hi = Calloc(NPAR, (size_t)size);
	NPAR *at_lo = Calloc(NPAR, (size_t)size);
	NUMBER err, lambda, v;
    NUMBER* ar_copy = Calloc(NUMBER, (size_t)size);
    memcpy(ar_copy, ar, sizeof(NUMBER)*(size_t)size);
    int iter = 0;
    for(i=0; i<size; i++)
        if(ar[i]!=ar[i]) {
            fprintf(stderr,"WARNING! NaN detected!\n");
        }
    bool doexit = false;
	while( !issimplexbounded(ar, lb, ub, size) && !doexit ) {
        lambda = 0;
		num_at_hi = 0;
		num_at_lo = 0;
		err = -1;
		// threshold
		for(i=0; i<size; i++) {
			at_lo[i] = (ar[i]<=lb[i])?1:0;
            
            v = (at_lo[i]==1)?lb[i]:ar[i];
            if(v!=v) {
                fprintf(stderr,"WARNING! NaN to be set!\n");
            }
			
            ar[i] = (at_lo[i]==1)?lb[i]:ar[i];
			num_at_lo = (NPAR)( num_at_lo + at_lo[i] );
			
			at_hi[i] = (ar[i]>=ub[i])?1:0;
            
            v = (at_hi[i]==1)?ub[i]:ar[i];
            if(v!=v) {
                fprintf(stderr,"WARNING! NaN to be set!\n");
            }
            
			ar[i] = (at_hi[i]==1)?ub[i]:ar[i];
			num_at_hi = (NPAR)( num_at_hi + at_hi[i] );
			
			err += ar[i];
		}
        if ( err > 0 && size > num_at_lo )
            lambda = err / (size - num_at_lo);
        else if ( err < 0 && size > num_at_hi )
            lambda = err / (size - num_at_hi);

        int will_suffer_from_lambda = 0; // those values that, if lessened by lambda, will be below 0 or over 1
        NUMBER err2 = 0.0, lambda2 = 0.0;
        for(i=0; i<size; i++) {
            if( (at_lo[i]==0 && at_hi[i]==0) ) {
                if( ar[i] < lambda ) {
                    will_suffer_from_lambda++;
                    err2 += ar[i];
                }
            }
        }
        
        if( will_suffer_from_lambda == 0 ) {
            for(i=0; i<size; i++) {

                v = ar[i] - ((at_lo[i]==0 && err>0)?lambda:0);
                if(v!=v) {
                    fprintf(stderr,"WARNING! NaN to be set!\n");
                }

                ar[i] -= (at_lo[i]==0 && err>0)?lambda:0;

                v = ar[i] - ((at_hi[i]==0 && err<0)?lambda:0);
                if(v!=v) {
                    fprintf(stderr,"WARNING! NaN to be set!\n");
                }

                ar[i] -= (at_hi[i]==0 && err<0)?lambda:0;
            }
        } else {
            lambda2 = (err-err2) / ( size - (num_at_hi + num_at_lo) - will_suffer_from_lambda );
            for(i=0; i<size; i++) {
                if( at_lo[i]==0 && at_hi[i]==0 ) {

                    v = (ar[i]<lambda)?0:(ar[i]-lambda2);
                    if(v!=v) {
                        fprintf(stderr,"WARNING! NaN to be set!\n");
                    }
                    
                    ar[i] = (ar[i]<lambda)?0:(ar[i]-lambda2);
                }
            }
        }
        iter++;
        if(iter==100) {
            string ar_was = "";
            for(int i=0; i<size; i++) ar_was = ar_was + std::to_string(ar_copy[i]).substr(0,5) + std::to_string((i<(size-1))?',':' ');
            string ar_is = "";
            for(int i=0; i<size; i++) ar_is = ar_is + std::to_string(ar[i]).substr(0,5) + std::to_string((i<(size-1))?',':' ');
            fprintf(stderr,"WARNING! Stuck in projectsimplexbounded()! ar was %s and now is %s.\n",ar_was.c_str(),ar_is.c_str());
//            doexit = true;
            break;//exit(1);
        }
	} // until satisfied
    // force last to be 1 - sum of all but last -- this code, actually breaks things
//    err = 0;
//    for(i=0; i<(size); i++) {
//        err += ar[i];
//    }
//    err = 1;
//    for(i=0; i<(size-1); i++) {
//        err -= ar[i];
//    }
//    ar[size-1] = err;
//    err = 1;
//    for(i=1; i<(size-0); i++) {
//        err -= ar[i];
//    }
//    ar[0] = err;
    
    NUMBER sum = 0.0;
    for(i=0; i<size; i++) {
        sum += ar[i];
        if(ar[i]<0 || ar[i] >1) {
            string ar_was = "";
            for(int i=0; i<size; i++) ar_was = ar_was + std::to_string(ar_copy[i]).substr(0,5) + std::to_string((i<(size-1))?',':' ');
            string ar_is = "";
            for(int i=0; i<size; i++) ar_is = ar_is + std::to_string(ar[i]).substr(0,5) + std::to_string((i<(size-1))?',':' ');
            fprintf(stderr, "ERROR! projected value is not within [0, 1] range! ar was %s and now is %s.\n",ar_was.c_str(),ar_is.c_str());
        }
    }
//    if( fabs(sum-1)>SAFETY) {
//        fprintf(stderr, "ERROR! projected simplex does not sum to 1!\n");
//    }
	
	free(at_hi);
	free(at_lo);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movsbq -0x19(%rbp), %rdi
movl $0x1, %esi
callq 0x5180
movq %rax, -0x28(%rbp)
movsbq -0x19(%rbp), %rdi
movl $0x1, %esi
callq 0x5180
movq %rax, -0x30(%rbp)
movsbq -0x19(%rbp), %rdi
movl $0x8, %esi
callq 0x5180
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rsi
movsbq -0x19(%rbp), %rdx
shlq $0x3, %rdx
callq 0x5250
movl $0x0, -0x54(%rbp)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x88a8
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jne 0x8884
jp 0x8884
jmp 0x889c
movq 0x5274d(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x47296(%rip), %rsi     # 0x4fb2b
movb $0x0, %al
callq 0x5440
jmp 0x889e
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x8856
movb $0x0, -0x55(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsbl -0x19(%rbp), %ecx
callq 0x7580
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3a9(%rbp)
jne 0x88db
movb -0x55(%rbp), %al
xorb $-0x1, %al
movb %al, -0x3a9(%rbp)
movb -0x3a9(%rbp), %al
testb $0x1, %al
jne 0x88ea
jmp 0x9480
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movb $0x0, -0x1b(%rbp)
movb $0x0, -0x1c(%rbp)
movsd 0x47116(%rip), %xmm0    # 0x4fa18
movsd %xmm0, -0x38(%rbp)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8b72
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorl %eax, %eax
movl $0x1, %ecx
ucomisd %xmm1, %xmm0
cmovael %ecx, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x897d
movq -0x10(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3b8(%rbp)
jmp 0x8993
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3b8(%rbp)
movsd -0x3b8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x89b0
jp 0x89b0
jmp 0x89c8
movq 0x52621(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x47182(%rip), %rsi     # 0x4fb43
movb $0x0, %al
callq 0x5440
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x89f2
movq -0x10(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3c0(%rbp)
jmp 0x8a08
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3c0(%rbp)
movsd -0x3c0(%rbp), %xmm0
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsbl -0x1c(%rbp), %eax
movq -0x30(%rbp), %rcx
movsbq -0x1a(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movb %al, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
xorl %eax, %eax
movl $0x1, %ecx
ucomisd %xmm1, %xmm0
cmovael %ecx, %eax
movb %al, %dl
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x8a96
movq -0x18(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3c8(%rbp)
jmp 0x8aac
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3c8(%rbp)
movsd -0x3c8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x8ac9
jp 0x8ac9
jmp 0x8ae1
movq 0x52508(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x47069(%rip), %rsi     # 0x4fb43
movb $0x0, %al
callq 0x5440
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x8b0b
movq -0x18(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3d0(%rbp)
jmp 0x8b21
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3d0(%rbp)
movsd -0x3d0(%rbp), %xmm0
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsbl -0x1b(%rbp), %eax
movq -0x28(%rbp), %rcx
movsbq -0x1a(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movb %al, -0x1b(%rbp)
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x890b
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8baa
movsbl -0x19(%rbp), %eax
movsbl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x8baa
movsd -0x38(%rbp), %xmm0
movsbl -0x19(%rbp), %eax
movsbl -0x1c(%rbp), %ecx
subl %ecx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x8bde
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x8bdc
movsbl -0x19(%rbp), %eax
movsbl -0x1b(%rbp), %ecx
cmpl %ecx, %eax
jle 0x8bdc
movsd -0x38(%rbp), %xmm0
movsbl -0x19(%rbp), %eax
movsbl -0x1b(%rbp), %ecx
subl %ecx, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x8bde
movl $0x0, -0x5c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8c71
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8c65
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8c65
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8c63
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x8c65
jmp 0x8c67
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x8bf9
cmpl $0x0, -0x5c(%rbp)
jne 0x8e75
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8e70
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3d8(%rbp)
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8cd4
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8cd4
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x3e0(%rbp)
jmp 0x8ce1
xorps %xmm0, %xmm0
movsd %xmm0, -0x3e0(%rbp)
jmp 0x8ce1
movsd -0x3d8(%rbp), %xmm0
movsd -0x3e0(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x8d0a
jp 0x8d0a
jmp 0x8d22
movq 0x522c7(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x46e28(%rip), %rsi     # 0x4fb43
movb $0x0, %al
callq 0x5440
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8d51
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8d51
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x3e8(%rbp)
jmp 0x8d5e
xorps %xmm0, %xmm0
movsd %xmm0, -0x3e8(%rbp)
jmp 0x8d5e
movsd -0x3e8(%rbp), %xmm1
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x3f0(%rbp)
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8dbe
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x8dbe
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x3f8(%rbp)
jmp 0x8dcb
xorps %xmm0, %xmm0
movsd %xmm0, -0x3f8(%rbp)
jmp 0x8dcb
movsd -0x3f0(%rbp), %xmm0
movsd -0x3f8(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x8df4
jp 0x8df4
jmp 0x8e0c
movq 0x521dd(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x46d3e(%rip), %rsi     # 0x4fb43
movb $0x0, %al
callq 0x5440
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8e37
xorps %xmm0, %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x8e37
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x400(%rbp)
jmp 0x8e44
xorps %xmm0, %xmm0
movsd %xmm0, -0x400(%rbp)
jmp 0x8e44
movsd -0x400(%rbp), %xmm1
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x8c7f
jmp 0x8fbd
movsd -0x38(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsbl -0x19(%rbp), %eax
movsbl -0x1b(%rbp), %ecx
movsbl -0x1c(%rbp), %edx
addl %edx, %ecx
subl %ecx, %eax
subl -0x5c(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8fbb
movq -0x30(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8fac
movq -0x28(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x8fac
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8f05
xorps %xmm0, %xmm0
movsd %xmm0, -0x408(%rbp)
jmp 0x8f20
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x408(%rbp)
movsd -0x408(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x8f3d
jp 0x8f3d
jmp 0x8f55
movq 0x52094(%rip), %rax     # 0x5afd8
movq (%rax), %rdi
leaq 0x46bf5(%rip), %rsi     # 0x4fb43
movb $0x0, %al
callq 0x5440
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8f7b
xorps %xmm0, %xmm0
movsd %xmm0, -0x410(%rbp)
jmp 0x8f96
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x410(%rbp)
movsd -0x410(%rbp), %xmm0
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x8fae
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x8ea3
jmp 0x8fbd
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x64, -0x54(%rbp)
jne 0x947b
leaq -0x91(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0x5550
movq -0x418(%rbp), %rdx
leaq 0x47c8a(%rip), %rsi     # 0x50c7b
leaq -0x90(%rbp), %rdi
callq 0xc470
jmp 0x8fff
leaq -0x91(%rbp), %rdi
callq 0x5320
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x91e4
movq -0x50(%rbp), %rax
movslq -0xa8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0x128(%rbp), %rdi
callq 0xc640
jmp 0x9045
xorl %eax, %eax
movl %eax, %edx
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
movl $0x5, %ecx
callq 0x52f0
jmp 0x9063
leaq -0xe8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0xc5f0
jmp 0x907f
movl -0xa8(%rbp), %eax
movsbl -0x19(%rbp), %ecx
decl %ecx
subl %ecx, %eax
movl $0x2c, %eax
movl $0x20, %esi
cmovll %eax, %esi
leaq -0x148(%rbp), %rdi
callq 0xc690
jmp 0x90a8
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0xc520
jmp 0x90c4
leaq -0x90(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x53a0
leaq -0xc8(%rbp), %rdi
callq 0x5170
leaq -0x148(%rbp), %rdi
callq 0x5170
leaq -0xe8(%rbp), %rdi
callq 0x5170
leaq -0x108(%rbp), %rdi
callq 0x5170
leaq -0x128(%rbp), %rdi
callq 0x5170
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x9015
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x5320
jmp 0x99c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x946a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x91d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x91c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x91bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x5170
leaq -0xe8(%rbp), %rdi
callq 0x5170
leaq -0x108(%rbp), %rdi
callq 0x5170
leaq -0x128(%rbp), %rdi
callq 0x5170
jmp 0x946a
leaq -0x169(%rbp), %rdi
movq %rdi, -0x420(%rbp)
callq 0x5550
movq -0x420(%rbp), %rdx
leaq 0x47a76(%rip), %rsi     # 0x50c7b
leaq -0x168(%rbp), %rdi
callq 0xc470
jmp 0x9213
leaq -0x169(%rbp), %rdi
callq 0x5320
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x93f5
movq -0x8(%rbp), %rax
movslq -0x170(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0x1f0(%rbp), %rdi
callq 0xc640
jmp 0x9259
xorl %eax, %eax
movl %eax, %edx
leaq -0x1d0(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
movl $0x5, %ecx
callq 0x52f0
jmp 0x9277
leaq -0x1b0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x1d0(%rbp), %rdx
callq 0xc5f0
jmp 0x9293
movl -0x170(%rbp), %eax
movsbl -0x19(%rbp), %ecx
decl %ecx
subl %ecx, %eax
movl $0x2c, %eax
movl $0x20, %esi
cmovll %eax, %esi
leaq -0x210(%rbp), %rdi
callq 0xc690
jmp 0x92bc
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0xc520
jmp 0x92d8
leaq -0x168(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x53a0
leaq -0x190(%rbp), %rdi
callq 0x5170
leaq -0x210(%rbp), %rdi
callq 0x5170
leaq -0x1b0(%rbp), %rdi
callq 0x5170
leaq -0x1d0(%rbp), %rdi
callq 0x5170
leaq -0x1f0(%rbp), %rdi
callq 0x5170
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x9229
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x169(%rbp), %rdi
callq 0x5320
jmp 0x946a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x945e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x93e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x93db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x93cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x5170
leaq -0x1b0(%rbp), %rdi
callq 0x5170
leaq -0x1d0(%rbp), %rdi
callq 0x5170
leaq -0x1f0(%rbp), %rdi
callq 0x5170
jmp 0x945e
movq 0x51bdc(%rip), %rax     # 0x5afd8
movq (%rax), %rax
movq %rax, -0x430(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5110
movq %rax, -0x428(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x5110
movq -0x430(%rbp), %rdi
movq -0x428(%rbp), %rdx
movq %rax, %rcx
leaq 0x4671f(%rip), %rsi     # 0x4fb5c
movb $0x0, %al
callq 0x5440
leaq -0x168(%rbp), %rdi
callq 0x5170
leaq -0x90(%rbp), %rdi
callq 0x5170
jmp 0x9480
leaq -0x168(%rbp), %rdi
callq 0x5170
leaq -0x90(%rbp), %rdi
callq 0x5170
jmp 0x99c2
jmp 0x88ac
xorps %xmm0, %xmm0
movsd %xmm0, -0x218(%rbp)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x99a7
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x218(%rbp), %xmm0
movsd %xmm0, -0x218(%rbp)
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
xorps %xmm0, %xmm0
ucomisd (%rax,%rcx,8), %xmm0
ja 0x94f0
movq -0x8(%rbp), %rax
movsbq -0x1a(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x46522(%rip), %xmm1    # 0x4fa08
ucomisd %xmm1, %xmm0
jbe 0x9998
leaq -0x239(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x5550
movq -0x438(%rbp), %rdx
leaq 0x4776a(%rip), %rsi     # 0x50c7b
leaq -0x238(%rbp), %rdi
callq 0xc470
jmp 0x951f
leaq -0x239(%rbp), %rdi
callq 0x5320
movl $0x0, -0x240(%rbp)
movl -0x240(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9704
movq -0x50(%rbp), %rax
movslq -0x240(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0x2c0(%rbp), %rdi
callq 0xc640
jmp 0x9565
xorl %eax, %eax
movl %eax, %edx
leaq -0x2a0(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
movl $0x5, %ecx
callq 0x52f0
jmp 0x9583
leaq -0x280(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0x2a0(%rbp), %rdx
callq 0xc5f0
jmp 0x959f
movl -0x240(%rbp), %eax
movsbl -0x19(%rbp), %ecx
decl %ecx
subl %ecx, %eax
movl $0x2c, %eax
movl $0x20, %esi
cmovll %eax, %esi
leaq -0x2e0(%rbp), %rdi
callq 0xc690
jmp 0x95c8
leaq -0x260(%rbp), %rdi
leaq -0x280(%rbp), %rsi
leaq -0x2e0(%rbp), %rdx
callq 0xc520
jmp 0x95e4
leaq -0x238(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x53a0
leaq -0x260(%rbp), %rdi
callq 0x5170
leaq -0x2e0(%rbp), %rdi
callq 0x5170
leaq -0x280(%rbp), %rdi
callq 0x5170
leaq -0x2a0(%rbp), %rdi
callq 0x5170
leaq -0x2c0(%rbp), %rdi
callq 0x5170
movl -0x240(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x240(%rbp)
jmp 0x9535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x239(%rbp), %rdi
callq 0x5320
jmp 0x99c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x998a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x96f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x96e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x96db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x5170
leaq -0x280(%rbp), %rdi
callq 0x5170
leaq -0x2a0(%rbp), %rdi
callq 0x5170
leaq -0x2c0(%rbp), %rdi
callq 0x5170
jmp 0x998a
leaq -0x301(%rbp), %rdi
movq %rdi, -0x440(%rbp)
callq 0x5550
movq -0x440(%rbp), %rdx
leaq 0x47556(%rip), %rsi     # 0x50c7b
leaq -0x300(%rbp), %rdi
callq 0xc470
jmp 0x9733
leaq -0x301(%rbp), %rdi
callq 0x5320
movl $0x0, -0x308(%rbp)
movl -0x308(%rbp), %eax
movsbl -0x19(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9915
movq -0x8(%rbp), %rax
movslq -0x308(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq -0x388(%rbp), %rdi
callq 0xc640
jmp 0x9779
xorl %eax, %eax
movl %eax, %edx
leaq -0x368(%rbp), %rdi
leaq -0x388(%rbp), %rsi
movl $0x5, %ecx
callq 0x52f0
jmp 0x9797
leaq -0x348(%rbp), %rdi
leaq -0x300(%rbp), %rsi
leaq -0x368(%rbp), %rdx
callq 0xc5f0
jmp 0x97b3
movl -0x308(%rbp), %eax
movsbl -0x19(%rbp), %ecx
decl %ecx
subl %ecx, %eax
movl $0x2c, %eax
movl $0x20, %esi
cmovll %eax, %esi
leaq -0x3a8(%rbp), %rdi
callq 0xc690
jmp 0x97dc
leaq -0x328(%rbp), %rdi
leaq -0x348(%rbp), %rsi
leaq -0x3a8(%rbp), %rdx
callq 0xc520
jmp 0x97f8
leaq -0x300(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x53a0
leaq -0x328(%rbp), %rdi
callq 0x5170
leaq -0x3a8(%rbp), %rdi
callq 0x5170
leaq -0x348(%rbp), %rdi
callq 0x5170
leaq -0x368(%rbp), %rdi
callq 0x5170
leaq -0x388(%rbp), %rdi
callq 0x5170
movl -0x308(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x308(%rbp)
jmp 0x9749
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x301(%rbp), %rdi
callq 0x5320
jmp 0x998a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x997e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x9907
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x98fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x98ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x5170
leaq -0x348(%rbp), %rdi
callq 0x5170
leaq -0x368(%rbp), %rdi
callq 0x5170
leaq -0x388(%rbp), %rdi
callq 0x5170
jmp 0x997e
movq 0x516bc(%rip), %rax     # 0x5afd8
movq (%rax), %rax
movq %rax, -0x450(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x5110
movq %rax, -0x448(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x5110
movq -0x450(%rbp), %rdi
movq -0x448(%rbp), %rdx
movq %rax, %rcx
leaq 0x46181(%rip), %rsi     # 0x4fade
movb $0x0, %al
callq 0x5440
leaq -0x300(%rbp), %rdi
callq 0x5170
leaq -0x238(%rbp), %rdi
callq 0x5170
jmp 0x9998
leaq -0x300(%rbp), %rdi
callq 0x5170
leaq -0x238(%rbp), %rdi
callq 0x5170
jmp 0x99c2
jmp 0x999a
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x948f
movq -0x28(%rbp), %rdi
callq 0x5380
movq -0x30(%rbp), %rdi
callq 0x5380
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x5540
nop