// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r13
movslq %ecx, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x4130
movq %rax, 0x78(%rsp)
movl $0x1, %esi
movq %rbx, %rdi
callq 0x4130
movq %rax, 0x70(%rsp)
movl $0x8, %esi
movq %rbx, %rdi
callq 0x4130
shlq $0x3, %rbx
movq %rax, 0x160(%rsp)
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x41c0
movzbl %bpl, %r8d
movl %ebp, %r12d
testb %bpl, %bpl
movq %r8, 0x80(%rsp)
jle 0x7a9b
xorl %ebx, %ebx
movsd (%r13,%rbx,8), %xmm0
ucomisd %xmm0, %xmm0
jp 0x7a8c
incq %rbx
cmpq %rbx, %r8
jne 0x7a75
jmp 0x7a9b
callq 0x4680
movq 0x80(%rsp), %r8
jmp 0x7a82
movq %r15, 0x150(%rsp)
movq %r14, 0x148(%rsp)
movsbl %r8b, %eax
testb %r8b, %r8b
setle 0xe(%rsp)
movq %rax, 0x90(%rsp)
decl %eax
leaq 0xb0(%rsp), %r15
cltq
movq %rax, 0x158(%rsp)
movl $0x0, 0x9c(%rsp)
movq %r13, 0x140(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl %r12d, %ebp
movl %r12d, 0x98(%rsp)
movb 0xe(%rsp), %al
movsd 0x2cde9(%rip), %xmm0    # 0x348f0
testb %bpl, %bpl
jle 0x7b78
movsd (%r13), %xmm1
movsd 0x2cdd6(%rip), %xmm0    # 0x348f0
subsd %xmm1, %xmm0
movq 0x150(%rsp), %r9
movsd (%r9), %xmm2
ucomisd %xmm1, %xmm2
ja 0x7b3f
movq 0x148(%rsp), %rdx
ucomisd (%rdx), %xmm1
jbe 0x7b43
xorl %eax, %eax
jmp 0x7b78
movl $0x1, %ecx
movq %rcx, %rax
cmpq %rcx, %r8
je 0x7b72
movsd (%r13,%rax,8), %xmm1
subsd %xmm1, %xmm0
movsd (%r9,%rax,8), %xmm2
ucomisd %xmm1, %xmm2
ja 0x7b72
leaq 0x1(%rax), %rcx
ucomisd (%rdx,%rax,8), %xmm1
jbe 0x7b48
cmpq %r8, %rax
setae %al
testb %al, %al
je 0x7b96
andpd 0x2cdac(%rip), %xmm0    # 0x34930
movsd 0x2cd6c(%rip), %xmm1    # 0x348f8
ucomisd %xmm0, %xmm1
ja 0x8565
testb %bpl, %bpl
jle 0x7cde
xorl %r12d, %r12d
movq 0x148(%rsp), %rbx
movq 0x150(%rsp), %r15
movq %r13, %r14
xorl %r10d, %r10d
movsd 0x2cd28(%rip), %xmm2    # 0x348e8
xorl %r13d, %r13d
movsd (%r15), %xmm0
ucomisd (%r14), %xmm0
setae %al
setae (%rsi,%r12)
movq %r15, %rbp
jae 0x7bdd
movq %r14, %rbp
movsd (%rbp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x7c3e
movsd (%rbp), %xmm0
movsd %xmm0, (%r14)
ucomisd (%rbx), %xmm0
setae %cl
setae (%rdi,%r12)
movq %rbx, %rbp
jae 0x7c06
movq %r14, %rbp
movsd (%rbp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x7c8a
addb %al, %r13b
movsd (%rbp), %xmm0
movsd %xmm0, (%r14)
addb %cl, %r10b
addsd %xmm0, %xmm2
incq %r12
addq $0x8, %r14
addq $0x8, %r15
addq $0x8, %rbx
cmpq %r12, %r8
jne 0x7bc3
jmp 0x7cec
movsd %xmm2, 0x88(%rsp)
movl %r10d, 0x120(%rsp)
movb %al, 0x130(%rsp)
callq 0x469c
movb 0x130(%rsp), %al
movl 0x120(%rsp), %r10d
movsd 0x88(%rsp), %xmm2
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
jmp 0x7be8
movsd %xmm2, 0x88(%rsp)
movl %r10d, 0x120(%rsp)
movb %al, 0x130(%rsp)
movb %cl, 0xf(%rsp)
callq 0x46be
movb 0xf(%rsp), %cl
movb 0x130(%rsp), %al
movl 0x120(%rsp), %r10d
movsd 0x88(%rsp), %xmm2
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
jmp 0x7c11
xorl %r13d, %r13d
movsd 0x2cbff(%rip), %xmm2    # 0x348e8
xorl %r10d, %r10d
ucomisd 0x2cc0c(%rip), %xmm2    # 0x34900
movsbl %r13b, %eax
movl 0x98(%rsp), %r9d
jbe 0x7d2f
cmpb %r9b, %r13b
jge 0x7d2f
movq 0x90(%rsp), %rcx
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movapd %xmm2, %xmm3
divsd %xmm0, %xmm3
leaq 0xb0(%rsp), %r15
leaq 0x60(%rsp), %r12
jmp 0x7d71
xorpd %xmm3, %xmm3
ucomisd %xmm2, %xmm3
seta %cl
cmpb %r9b, %r10b
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
leaq 0xb0(%rsp), %r15
leaq 0x60(%rsp), %r12
jne 0x7d71
movsbl %r10b, %ecx
movq 0x90(%rsp), %rdx
subl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movapd %xmm2, %xmm3
divsd %xmm0, %xmm3
testb %r9b, %r9b
movq 0x140(%rsp), %r13
jle 0x7daf
xorl %edx, %edx
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
cmpb $0x0, (%rsi,%rdx)
jne 0x7da5
cmpb $0x0, (%rdi,%rdx)
jne 0x7da5
movsd (%r13,%rdx,8), %xmm1
ucomisd %xmm1, %xmm3
jbe 0x7da5
incl %ecx
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %r8
jne 0x7d86
jmp 0x7db5
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movl %r9d, %ebp
testl %ecx, %ecx
je 0x7e78
testb %r9b, %r9b
jle 0x7f97
movsbl %r10b, %edx
addl %edx, %eax
addl %ecx, %eax
movq 0x90(%rsp), %rcx
subl %eax, %ecx
subsd %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd %xmm0, %xmm2
xorl %ebx, %ebx
cmpb $0x0, (%rsi,%rbx)
jne 0x7e2e
cmpb $0x0, (%rdi,%rbx)
jne 0x7e2e
movsd (%r13,%rbx,8), %xmm0
ucomisd %xmm0, %xmm3
ja 0x7e0f
subsd %xmm2, %xmm0
ucomisd %xmm0, %xmm0
jp 0x7e3b
movsd (%r13,%rbx,8), %xmm0
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
cmpltsd %xmm3, %xmm0
andnpd %xmm1, %xmm0
movlpd %xmm0, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %r8
jne 0x7dec
jmp 0x7f97
movsd %xmm2, 0x88(%rsp)
movapd %xmm3, 0x120(%rsp)
callq 0x46e0
movapd 0x120(%rsp), %xmm3
movsd 0x88(%rsp), %xmm2
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
jmp 0x7e0f
testb %r9b, %r9b
jle 0x7f97
xorl %ebx, %ebx
movsd %xmm2, 0x88(%rsp)
movapd %xmm3, 0x120(%rsp)
cmpb $0x0, (%rsi,%rbx)
xorpd %xmm4, %xmm4
movapd %xmm3, %xmm0
je 0x7ea7
xorpd %xmm0, %xmm0
movsd (%r13,%rbx,8), %xmm1
cmpltsd %xmm2, %xmm4
andpd %xmm0, %xmm4
subsd %xmm4, %xmm1
ucomisd %xmm1, %xmm1
jp 0x7f17
movsd (%r13,%rbx,8), %xmm0
subsd %xmm4, %xmm0
movsd %xmm0, (%r13,%rbx,8)
cmpb $0x0, (%rdi,%rbx)
xorpd %xmm4, %xmm4
jne 0x7eee
movapd %xmm2, %xmm1
cmpltsd %xmm4, %xmm1
andpd %xmm3, %xmm1
movapd %xmm1, %xmm4
subsd %xmm4, %xmm0
ucomisd %xmm0, %xmm0
jp 0x7f57
movsd (%r13,%rbx,8), %xmm0
subsd %xmm4, %xmm0
movsd %xmm0, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %r8
jne 0x7e95
jmp 0x7f97
movapd %xmm4, 0x130(%rsp)
callq 0x4702
movapd 0x130(%rsp), %xmm4
movapd 0x120(%rsp), %xmm3
movsd 0x88(%rsp), %xmm2
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
jmp 0x7ec1
movsd %xmm4, 0x130(%rsp)
callq 0x4724
movsd 0x130(%rsp), %xmm4
movapd 0x120(%rsp), %xmm3
movsd 0x88(%rsp), %xmm2
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
jmp 0x7ef8
movl 0x9c(%rsp), %eax
incl %eax
movl %eax, 0x9c(%rsp)
cmpl $0x64, %eax
jne 0x7afb
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x2dbd8(%rip), %rdx     # 0x35ba7
movq %rdx, %rsi
callq 0xa7c0
testb %bpl, %bpl
jle 0x8235
xorl %ebx, %ebx
movq 0x160(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movl $0x148, %edx            # imm = 0x148
leaq 0xe0(%rsp), %rbp
movq %rbp, %rdi
movq 0x37fba(%rip), %rsi     # 0x3ffc0
leaq 0x2cb25(%rip), %rcx     # 0x34b32
movb $0x1, %al
callq 0xa610
movl $0x5, %ecx
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4230
movq 0x100(%rsp), %rcx
movq 0x108(%rsp), %r8
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8072
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x807a
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
leaq 0x30(%rsp), %rdi
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x2, %esi
movl $0x2d, %edx
callq 0x4280
cmpq 0x158(%rsp), %rbx
movl $0x20, %edx
movl $0x2c, %eax
cmovll %eax, %edx
movq 0x30(%rsp), %rdi
movl $0x2, %esi
callq 0xa752
movq 0x10(%rsp), %rcx
movl $0xf, %esi
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0x80ed
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x811b
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0x8116
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x812c
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x40d0
jmp 0x813a
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
movq %r12, 0x50(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x815a
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x8164
movupd (%rcx), %xmm0
movupd %xmm0, (%r12)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x100(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x42c0
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x81aa
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x81c6
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x81e2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x81ff
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8224
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
incq %rbx
cmpq %rbx, 0x90(%rsp)
jne 0x7fe2
movq %r12, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x2d961(%rip), %rdx     # 0x35ba7
movq %rdx, %rsi
callq 0xa7c0
cmpb $0x0, 0x98(%rsp)
jle 0x84dd
xorl %ebx, %ebx
movsd (%r13,%rbx,8), %xmm0
movl $0x148, %edx            # imm = 0x148
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq 0x37d47(%rip), %rsi     # 0x3ffc0
leaq 0x2c8b2(%rip), %rcx     # 0x34b32
movb $0x1, %al
callq 0xa610
movl $0x5, %ecx
leaq 0xe0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4230
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
movq %r15, 0xa0(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x82e3
movq %rdx, 0xa0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb0(%rsp)
jmp 0x82ec
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0xa8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x2, %esi
leaq 0xc0(%rsp), %rdi
movl $0x2d, %edx
callq 0x4280
cmpq 0x158(%rsp), %rbx
movl $0x20, %edx
movl $0x2c, %eax
cmovll %eax, %edx
movq 0xc0(%rsp), %rdi
movl $0x2, %esi
callq 0xa752
movq 0xa0(%rsp), %rcx
movl $0xf, %esi
cmpq %r15, %rcx
je 0x836f
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %r8
movq 0xc8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x83ac
movl $0xf, %esi
leaq 0xd0(%rsp), %rdi
cmpq %rdi, 0xc0(%rsp)
je 0x83a7
movq 0xd0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x83c3
movq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x40d0
jmp 0x83d4
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x83f9
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8401
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x42c0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8449
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x846e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x848b
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x84b0
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x84cc
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
incq %rbx
cmpq %rbx, 0x90(%rsp)
jne 0x825e
movq 0x37af4(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
movq 0x100(%rsp), %rdx
movq 0x50(%rsp), %rcx
leaq 0x2c511(%rip), %rsi     # 0x34a0c
xorl %eax, %eax
callq 0x4330
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x8519
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x853e
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4220
cmpl $0x64, 0x9c(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x80(%rsp), %r8
movl 0x98(%rsp), %ebp
jne 0x7afb
testb %bpl, %bpl
jle 0x8aec
movq 0x90(%rsp), %rax
decl %eax
movslq %eax, %rbx
xorl %r14d, %r14d
xorpd %xmm1, %xmm1
leaq 0xe0(%rsp), %rbp
leaq 0xa0(%rsp), %r12
movsd 0x2c356(%rip), %xmm2    # 0x348f0
movsd (%r13,%r14,8), %xmm0
ucomisd %xmm0, %xmm1
ja 0x85ba
ucomisd %xmm2, %xmm0
ja 0x85ba
incq %r14
cmpq %r8, %r14
jne 0x859a
jmp 0x8aec
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x2d5ce(%rip), %rdx     # 0x35ba7
movq %rdx, %rsi
callq 0xa7c0
xorl %r13d, %r13d
movq 0x160(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
movl $0x148, %edx            # imm = 0x148
movq %rbp, %rdi
movq 0x379bf(%rip), %rsi     # 0x3ffc0
leaq 0x2c52a(%rip), %rcx     # 0x34b32
movb $0x1, %al
callq 0xa610
movl $0x5, %ecx
movq %r12, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4230
movq 0x100(%rsp), %rcx
movq 0x108(%rsp), %r8
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8665
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x866d
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x2, %esi
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x4280
cmpq %rbx, %r13
movl $0x20, %edx
movl $0x2c, %eax
cmovll %eax, %edx
movq 0x30(%rsp), %rdi
movl $0x2, %esi
callq 0xa752
movq 0x10(%rsp), %rcx
movl $0xf, %esi
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0x86db
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x8709
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0x8704
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x871a
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x40d0
jmp 0x8728
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x874d
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x8755
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x100(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x42c0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x87a0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x87bc
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x87d8
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x87f5
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x881a
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
incq %r13
cmpq %r13, 0x90(%rsp)
jne 0x85e4
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x2d35d(%rip), %rdx     # 0x35ba7
movq %rdx, %rsi
callq 0xa7c0
xorl %r13d, %r13d
movq 0x140(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
movl $0x148, %edx            # imm = 0x148
movq %rbp, %rdi
movq 0x3774e(%rip), %rsi     # 0x3ffc0
leaq 0x2c2b9(%rip), %rcx     # 0x34b32
movb $0x1, %al
callq 0xa610
movl $0x5, %ecx
movq %r12, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4230
movq 0xc0(%rsp), %rcx
movq 0xc8(%rsp), %r8
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x88d6
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x88de
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x2, %esi
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x4280
cmpq %rbx, %r13
movl $0x20, %edx
movl $0x2c, %eax
cmovll %eax, %edx
movq 0x30(%rsp), %rdi
movl $0x2, %esi
callq 0xa752
movq 0x10(%rsp), %rcx
movl $0xf, %esi
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0x894c
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x897a
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0x8975
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x898b
movq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x40d0
jmp 0x8999
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4260
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x89be
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x89c6
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xc0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x42c0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8a11
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8a2d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8a49
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8a66
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8a8b
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
incq %r13
cmpq %r13, 0x90(%rsp)
jne 0x8855
leaq 0x100(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
leaq 0x110(%rsp), %rcx
callq 0x4746
movq 0x140(%rsp), %r13
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x80(%rsp), %r8
xorpd %xmm1, %xmm1
movsd 0x2be09(%rip), %xmm2    # 0x348f0
jmp 0x85ad
movq %rsi, %rbx
callq 0x42a0
movq %rbx, %rdi
callq 0x42a0
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8d08
jmp 0x8b1a
jmp 0x8d08
movq %rax, %rbx
jmp 0x8d5a
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x8b54
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8b54
movq %rax, %rbx
jmp 0x8b71
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8b71
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8b9b
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8b9b
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8bbc
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8bbc
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x8d35
movq 0x60(%rsp), %rsi
jmp 0x8d2d
jmp 0x8ca4
jmp 0x8cca
jmp 0x8cc5
jmp 0x8d08
jmp 0x8d0d
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8c11
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8c11
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8c32
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8c32
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8c59
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8c59
movq %rax, %rbx
jmp 0x8c7e
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8c7e
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x8d35
movq 0xd0(%rsp), %rsi
jmp 0x8d2d
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8ccd
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8ccd
movq %rax, %rbx
jmp 0x8ce9
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8ce9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x8d10
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0x8d10
movq %rax, %rbx
jmp 0x8d35
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x8d35
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4220
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x8d5a
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4220
movq %rbx, %rdi
callq 0x4430