// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: cram_compress_block
int cram_compress_block(cram_fd *fd, cram_block *b, cram_metrics *metrics,
			int method, int level) {

    char *comp = NULL;
    size_t comp_size = 0;
    int strat;

    if (b->method != RAW) {
        // Maybe already compressed if s->block[0] was compressed and
        // we have e.g. s->block[DS_BA] set to s->block[0] due to only
        // one base type present and hence using E_HUFFMAN on block 0.
        // A second explicit attempt to compress the same block then
        // occurs.
        return 0;
    }

    if (method == -1) {
	method = 1<<GZIP;
	if (fd->use_bz2)
	    method |= 1<<BZIP2;
	if (fd->use_lzma)
	    method |= 1<<LZMA;
    }

    if (level == -1)
	level = fd->level;

    //fprintf(stderr, "IN: block %d, sz %d\n", b->content_id, b->uncomp_size);

    if (method == RAW || level == 0 || b->uncomp_size == 0) {
	b->method = RAW;
	b->comp_size = b->uncomp_size;
	//fprintf(stderr, "Skip block id %d\n", b->content_id);
	return 0;
    }

    if (metrics) {
	pthread_mutex_lock(&fd->metrics_lock);
	if (metrics->trial > 0 || --metrics->next_trial <= 0) {
	    size_t sz_best = INT_MAX;
	    size_t sz_gz_rle = 0;
	    size_t sz_gz_def = 0;
	    size_t sz_rans0 = 0;
	    size_t sz_rans1 = 0;
	    size_t sz_bzip2 = 0;
	    size_t sz_lzma = 0;
	    int method_best = 0;
	    char *c_best = NULL, *c = NULL;

	    if (metrics->revised_method)
		method = metrics->revised_method;
	    else
		metrics->revised_method = method;

	    if (metrics->next_trial == 0) {
		metrics->next_trial = TRIAL_SPAN;
		metrics->trial = NTRIALS;
		metrics->sz_gz_rle /= 2;
		metrics->sz_gz_def /= 2;
		metrics->sz_rans0  /= 2;
		metrics->sz_rans1  /= 2;
		metrics->sz_bzip2  /= 2;
		metrics->sz_lzma   /= 2;
	    }

	    pthread_mutex_unlock(&fd->metrics_lock);
	    
	    if (method & (1<<GZIP_RLE)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_gz_rle, GZIP, 1, Z_RLE);
		if (c && sz_best > sz_gz_rle) {
		    sz_best = sz_gz_rle;
		    method_best = GZIP_RLE;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_gz_rle = b->uncomp_size*2+1000;
		}

		//fprintf(stderr, "Block %d; %d->%d\n", b->content_id, b->uncomp_size, sz_gz_rle);
	    }

	    if (method & (1<<GZIP)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_gz_def, GZIP, level,
					    Z_FILTERED);
		if (c && sz_best > sz_gz_def) {
		    sz_best = sz_gz_def;
		    method_best = GZIP;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_gz_def = b->uncomp_size*2+1000;
		}

		//fprintf(stderr, "Block %d; %d->%d\n", b->content_id, b->uncomp_size, sz_gz_def);
	    }

	    if (method & (1<<RANS0)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_rans0, RANS0, 0, 0);
		if (c && sz_best > sz_rans0) {
		    sz_best = sz_rans0;
		    method_best = RANS0;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_rans0 = b->uncomp_size*2+1000;
		}
	    }

	    if (method & (1<<RANS1)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_rans1, RANS1, 0, 0);
		if (c && sz_best > sz_rans1) {
		    sz_best = sz_rans1;
		    method_best = RANS1;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_rans1 = b->uncomp_size*2+1000;
		}
	    }

	    if (method & (1<<BZIP2)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_bzip2, BZIP2, level, 0);
		if (c && sz_best > sz_bzip2) {
		    sz_best = sz_bzip2;
		    method_best = BZIP2;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_bzip2 = b->uncomp_size*2+1000;
		}
	    }

	    if (method & (1<<LZMA)) {
		c = cram_compress_by_method((char *)b->data, b->uncomp_size,
					    &sz_lzma, LZMA, level, 0);
		if (c && sz_best > sz_lzma) {
		    sz_best = sz_lzma;
		    method_best = LZMA;
		    if (c_best)
			free(c_best);
		    c_best = c;
		} else if (c) {
		    free(c);
		} else {
		    sz_lzma = b->uncomp_size*2+1000;
		}
	    }

	    //fprintf(stderr, "sz_best = %d\n", sz_best);

	    free(b->data);
	    b->data = (unsigned char *)c_best;
	    //printf("method_best = %s\n", cram_block_method2str(method_best));
	    b->method = method_best == GZIP_RLE ? GZIP : method_best;
	    b->comp_size = sz_best;

	    pthread_mutex_lock(&fd->metrics_lock);
	    metrics->sz_gz_rle += sz_gz_rle;
	    metrics->sz_gz_def += sz_gz_def;
	    metrics->sz_rans0  += sz_rans0;
	    metrics->sz_rans1  += sz_rans1;
	    metrics->sz_bzip2  += sz_bzip2;
	    metrics->sz_lzma   += sz_lzma;
	    if (--metrics->trial == 0) {
		int best_method = RAW;
		int best_sz = INT_MAX;

		// Scale methods by cost
		if (fd->level <= 3) {
		    metrics->sz_rans1  *= 1.02;
		    metrics->sz_gz_def *= 1.04;
		    metrics->sz_bzip2  *= 1.08;
		    metrics->sz_lzma   *= 1.10;
		} else if (fd->level <= 6) {
		    metrics->sz_rans1  *= 1.01;
		    metrics->sz_gz_def *= 1.02;
		    metrics->sz_bzip2  *= 1.03;
		    metrics->sz_lzma   *= 1.05;
		}

		if (method & (1<<GZIP_RLE) && best_sz > metrics->sz_gz_rle)
		    best_sz = metrics->sz_gz_rle, best_method = GZIP_RLE;

		if (method & (1<<GZIP) && best_sz > metrics->sz_gz_def)
		    best_sz = metrics->sz_gz_def, best_method = GZIP;

		if (method & (1<<RANS0) && best_sz > metrics->sz_rans0)
		    best_sz = metrics->sz_rans0, best_method = RANS0;

		if (method & (1<<RANS1) && best_sz > metrics->sz_rans1)
		    best_sz = metrics->sz_rans1, best_method = RANS1;

		if (method & (1<<BZIP2) && best_sz > metrics->sz_bzip2)
		    best_sz = metrics->sz_bzip2, best_method = BZIP2;

		if (method & (1<<LZMA) && best_sz > metrics->sz_lzma)
		    best_sz = metrics->sz_lzma, best_method = LZMA;

		if (best_method == GZIP_RLE) {
		    metrics->method = GZIP;
		    metrics->strat  = Z_RLE;
		} else {
		    metrics->method = best_method;
		    metrics->strat  = Z_FILTERED;
		}

		// If we see at least MAXFAIL trials in a row for a specific
		// compression method with more than MAXDELTA aggregate
		// size then we drop this from the list of methods used
		// for this block type.
#define MAXDELTA 0.20
#define MAXFAILS 4
		if (best_method == GZIP_RLE) {
		    metrics->gz_rle_cnt = 0;
		    metrics->gz_rle_extra = 0;
		} else if (best_sz < metrics->sz_gz_rle) {
		    double r = (double)metrics->sz_gz_rle / best_sz - 1;
		    if (++metrics->gz_rle_cnt >= MAXFAILS && 
			(metrics->gz_rle_extra += r) >= MAXDELTA)
			method &= ~(1<<GZIP_RLE);
		}

		if (best_method == GZIP) {
		    metrics->gz_def_cnt = 0;
		    metrics->gz_def_extra = 0;
		} else if (best_sz < metrics->sz_gz_def) {
		    double r = (double)metrics->sz_gz_def / best_sz - 1;
		    if (++metrics->gz_def_cnt >= MAXFAILS &&
			(metrics->gz_def_extra += r) >= MAXDELTA)
			method &= ~(1<<GZIP);
		}

		if (best_method == RANS0) {
		    metrics->rans0_cnt = 0;
		    metrics->rans0_extra = 0;
		} else if (best_sz < metrics->sz_rans0) {
		    double r = (double)metrics->sz_rans0 / best_sz - 1;
		    if (++metrics->rans0_cnt >= MAXFAILS &&
			(metrics->rans0_extra += r) >= MAXDELTA)
			method &= ~(1<<RANS0);
		}

		if (best_method == RANS1) {
		    metrics->rans1_cnt = 0;
		    metrics->rans1_extra = 0;
		} else if (best_sz < metrics->sz_rans1) {
		    double r = (double)metrics->sz_rans1 / best_sz - 1;
		    if (++metrics->rans1_cnt >= MAXFAILS &&
			(metrics->rans1_extra += r) >= MAXDELTA)
			method &= ~(1<<RANS1);
		}

		if (best_method == BZIP2) {
		    metrics->bzip2_cnt = 0;
		    metrics->bzip2_extra = 0;
		} else if (best_sz < metrics->sz_bzip2) {
		    double r = (double)metrics->sz_bzip2 / best_sz - 1;
		    if (++metrics->bzip2_cnt >= MAXFAILS &&
			(metrics->bzip2_extra += r) >= MAXDELTA)
			method &= ~(1<<BZIP2);
		}

		if (best_method == LZMA) {
		    metrics->lzma_cnt = 0;
		    metrics->lzma_extra = 0;
		} else if (best_sz < metrics->sz_lzma) {
		    double r = (double)metrics->sz_lzma / best_sz - 1;
		    if (++metrics->lzma_cnt >= MAXFAILS &&
			(metrics->lzma_extra += r) >= MAXDELTA)
			method &= ~(1<<LZMA);
		}

		//if (method != metrics->revised_method)
		//    fprintf(stderr, "%d: method from %x to %x\n",
		//	    b->content_id, metrics->revised_method, method);
		metrics->revised_method = method;
	    }
	    pthread_mutex_unlock(&fd->metrics_lock);
	} else {
	    strat = metrics->strat;
	    method = metrics->method;

	    pthread_mutex_unlock(&fd->metrics_lock);
	    comp = cram_compress_by_method((char *)b->data, b->uncomp_size,
					   &comp_size, method,
					   level, strat);
	    if (!comp)
		return -1;
	    free(b->data);
	    b->data = (unsigned char *)comp;
	    b->comp_size = comp_size;
	    b->method = method;
	}

    } else {
	// no cached metrics, so just do zlib?
	comp = cram_compress_by_method((char *)b->data, b->uncomp_size,
				       &comp_size, GZIP, level, Z_FILTERED);
	if (!comp) {
	    fprintf(stderr, "Compression failed!\n");
	    return -1;
	}
	free(b->data);
	b->data = (unsigned char *)comp;
	b->comp_size = comp_size;
	b->method = GZIP;
    }

    if (fd->verbose)
	fprintf(stderr, "Compressed block ID %d from %d to %d by method %s\n",
		b->content_id, b->uncomp_size, b->comp_size,
		cram_block_method2str(b->method));

    if (b->method == RANS1)
	b->method = RANS0; // Spec just has RANS (not 0/1) with auto-sensing

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x47313
movl $0x0, -0x4(%rbp)
jmp 0x48252
cmpl $-0x1, -0x24(%rbp)
jne 0x4734e
movl $0x2, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x214(%rax)
je 0x47336
movl -0x24(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x21c(%rax)
je 0x4734c
movl -0x24(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x24(%rbp)
jmp 0x4734e
cmpl $-0x1, -0x28(%rbp)
jne 0x4735e
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x47374
cmpl $0x0, -0x28(%rbp)
je 0x47374
movq -0x18(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x47398
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x48252
cmpq $0x0, -0x20(%rbp)
je 0x48138
movq -0x10(%rbp), %rdi
addq $0x8870, %rdi           # imm = 0x8870
callq 0x4880
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jg 0x473d2
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x4(%rcx)
cmpl $0x0, %eax
jg 0x480a5
movq $0x7fffffff, -0x48(%rbp) # imm = 0x7FFFFFFF
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x4743d
movq -0x20(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x47447
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x47536
movq -0x20(%rbp), %rax
movl $0x32, 0x4(%rax)
movq -0x20(%rbp), %rax
movl $0x3, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl 0x8(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl 0xc(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xf0(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl 0x10(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl 0x14(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl 0x1c(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd0(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rdi
addq $0x8870, %rdi           # imm = 0x8870
callq 0x4420
movl -0x24(%rbp), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x475ff
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
leaq -0x50(%rbp), %rdx
movl $0x1, %r8d
movl $0x3, %r9d
movl %r8d, %ecx
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x475cf
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x475cf
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xb, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x475bf
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x475fd
cmpq $0x0, -0x90(%rbp)
je 0x475e7
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x475fb
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x50(%rbp)
jmp 0x475fd
jmp 0x475ff
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x476b4
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
movl -0x28(%rbp), %r8d
leaq -0x58(%rbp), %rdx
movl $0x1, %r9d
movl %r9d, %ecx
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x47684
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jbe 0x47684
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x1, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x47674
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x476b2
cmpq $0x0, -0x90(%rbp)
je 0x4769c
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x476b0
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x58(%rbp)
jmp 0x476b2
jmp 0x476b4
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x47767
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
leaq -0x60(%rbp), %rdx
movl $0x4, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x47737
movq -0x48(%rbp), %rax
cmpq -0x60(%rbp), %rax
jbe 0x47737
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x4, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x47727
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x47765
cmpq $0x0, -0x90(%rbp)
je 0x4774f
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x47763
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x60(%rbp)
jmp 0x47765
jmp 0x47767
movl -0x24(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x4781c
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
leaq -0x68(%rbp), %rdx
movl $0xa, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x477ec
movq -0x48(%rbp), %rax
cmpq -0x68(%rbp), %rax
jbe 0x477ec
movq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xa, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x477dc
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x4781a
cmpq $0x0, -0x90(%rbp)
je 0x47804
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x47818
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x68(%rbp)
jmp 0x4781a
jmp 0x4781c
movl -0x24(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x478d0
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
movl -0x28(%rbp), %r8d
leaq -0x70(%rbp), %rdx
movl $0x2, %ecx
xorl %r9d, %r9d
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x478a0
movq -0x48(%rbp), %rax
cmpq -0x70(%rbp), %rax
jbe 0x478a0
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x2, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x47890
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x478ce
cmpq $0x0, -0x90(%rbp)
je 0x478b8
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x478cc
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x70(%rbp)
jmp 0x478ce
jmp 0x478d0
movl -0x24(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x47984
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
movl -0x28(%rbp), %r8d
leaq -0x78(%rbp), %rdx
movl $0x3, %ecx
xorl %r9d, %r9d
callq 0x48260
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x47954
movq -0x48(%rbp), %rax
cmpq -0x78(%rbp), %rax
jbe 0x47954
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x3, -0x7c(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x47944
movq -0x88(%rbp), %rdi
callq 0x46a0
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x47982
cmpq $0x0, -0x90(%rbp)
je 0x4796c
movq -0x90(%rbp), %rdi
callq 0x46a0
jmp 0x47980
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll %eax
addl $0x3e8, %eax            # imm = 0x3E8
cltq
movq %rax, -0x78(%rbp)
jmp 0x47982
jmp 0x47984
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x46a0
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpl $0xb, -0x7c(%rbp)
jne 0x479b3
movl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x479bc
movl -0x7c(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0x8870, %rdi           # imm = 0x8870
callq 0x4880
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0xc(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x10(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x10(%rax)
movq -0x68(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x14(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x14(%rax)
movq -0x70(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x18(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x18(%rax)
movq -0x78(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x1c(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1c(%rax)
movq -0x20(%rbp), %rcx
movl (%rcx), %eax
addl $-0x1, %eax
movl %eax, (%rcx)
cmpl $0x0, %eax
jne 0x48090
movl $0x0, -0x94(%rbp)
movl $0x7fffffff, -0x98(%rbp) # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rax
cmpl $0x3, 0x78(%rax)
jg 0x47af5
movq -0x20(%rbp), %rax
cvtsi2sdl 0x14(%rax), %xmm0
movsd 0x3521c(%rip), %xmm1    # 0x7ccb0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
movsd 0x35220(%rip), %xmm1    # 0x7ccd0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
movsd 0x351fc(%rip), %xmm1    # 0x7ccc8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0x1c(%rax), %xmm0
movsd 0x351d8(%rip), %xmm1    # 0x7ccc0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x47b71
movq -0x10(%rbp), %rax
cmpl $0x6, 0x78(%rax)
jg 0x47b6f
movq -0x20(%rbp), %rax
cvtsi2sdl 0x14(%rax), %xmm0
movsd 0x351a8(%rip), %xmm1    # 0x7ccb8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
movsd 0x35184(%rip), %xmm1    # 0x7ccb0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
movsd 0x35160(%rip), %xmm1    # 0x7cca8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
cvtsi2sdl 0x1c(%rax), %xmm0
movsd 0x3513c(%rip), %xmm1    # 0x7cca0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x47b71
movl -0x24(%rbp), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x47ba4
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x47ba4
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0xb, -0x94(%rbp)
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x47bd5
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jle 0x47bd5
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0x1, -0x94(%rbp)
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x47c06
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0x47c06
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0x4, -0x94(%rbp)
movl -0x24(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x47c39
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jle 0x47c39
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0xa, -0x94(%rbp)
movl -0x24(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x47c6a
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x47c6a
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0x2, -0x94(%rbp)
movl -0x24(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x47c9b
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jle 0x47c9b
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x98(%rbp)
movl $0x3, -0x94(%rbp)
cmpl $0xb, -0x94(%rbp)
jne 0x47cbc
movq -0x20(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x20(%rbp), %rax
movl $0x3, 0x24(%rax)
jmp 0x47cd4
movl -0x94(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x24(%rax)
cmpl $0xb, -0x94(%rbp)
jne 0x47cf6
movq -0x20(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rax)
jmp 0x47d73
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x47d71
movq -0x20(%rbp), %rax
cvtsi2sdl 0x8(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x30366(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x20(%rbp), %rcx
movl 0x28(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x28(%rcx)
cmpl $0x4, %eax
jl 0x47d6f
movsd -0xa0(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x48(%rax), %xmm0
movsd %xmm0, 0x48(%rax)
movsd 0x34f7a(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x47d6f
movl -0x24(%rbp), %eax
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %eax, -0x24(%rbp)
jmp 0x47d71
jmp 0x47d73
cmpl $0x1, -0x94(%rbp)
jne 0x47d95
movq -0x20(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rax)
jmp 0x47e10
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x47e0e
movq -0x20(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x302c7(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x20(%rbp), %rcx
movl 0x2c(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rcx)
cmpl $0x4, %eax
jl 0x47e0c
movsd -0xa8(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x50(%rax), %xmm0
movsd %xmm0, 0x50(%rax)
movsd 0x34edb(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x47e0c
movl -0x24(%rbp), %eax
andl $-0x3, %eax
movl %eax, -0x24(%rbp)
jmp 0x47e0e
jmp 0x47e10
cmpl $0x4, -0x94(%rbp)
jne 0x47e32
movq -0x20(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rax)
jmp 0x47ead
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x47eab
movq -0x20(%rbp), %rax
cvtsi2sdl 0x10(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x3022a(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x20(%rbp), %rcx
movl 0x30(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x30(%rcx)
cmpl $0x4, %eax
jl 0x47ea9
movsd -0xb0(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x58(%rax), %xmm0
movsd %xmm0, 0x58(%rax)
movsd 0x34e3e(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x47ea9
movl -0x24(%rbp), %eax
andl $-0x11, %eax
movl %eax, -0x24(%rbp)
jmp 0x47eab
jmp 0x47ead
cmpl $0xa, -0x94(%rbp)
jne 0x47ecf
movq -0x20(%rbp), %rax
movl $0x0, 0x34(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rax)
jmp 0x47f4c
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x47f4a
movq -0x20(%rbp), %rax
cvtsi2sdl 0x14(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x3018d(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x20(%rbp), %rcx
movl 0x34(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x34(%rcx)
cmpl $0x4, %eax
jl 0x47f48
movsd -0xb8(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x60(%rax), %xmm0
movsd %xmm0, 0x60(%rax)
movsd 0x34da1(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x47f48
movl -0x24(%rbp), %eax
andl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
movl %eax, -0x24(%rbp)
jmp 0x47f4a
jmp 0x47f4c
cmpl $0x2, -0x94(%rbp)
jne 0x47f6e
movq -0x20(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rax)
jmp 0x47fe9
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x47fe7
movq -0x20(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x300ee(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x20(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x4, %eax
jl 0x47fe5
movsd -0xc0(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x68(%rax), %xmm0
movsd %xmm0, 0x68(%rax)
movsd 0x34d02(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x47fe5
movl -0x24(%rbp), %eax
andl $-0x5, %eax
movl %eax, -0x24(%rbp)
jmp 0x47fe7
jmp 0x47fe9
cmpl $0x3, -0x94(%rbp)
jne 0x4800b
movq -0x20(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rax)
jmp 0x48086
movl -0x98(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x48084
movq -0x20(%rbp), %rax
cvtsi2sdl 0x1c(%rax), %xmm0
cvtsi2sdl -0x98(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x30051(%rip), %xmm1    # 0x78088
subsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x20(%rbp), %rcx
movl 0x3c(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rcx)
cmpl $0x4, %eax
jl 0x48082
movsd -0xc8(%rbp), %xmm0
movq -0x20(%rbp), %rax
addsd 0x70(%rax), %xmm0
movsd %xmm0, 0x70(%rax)
movsd 0x34c65(%rip), %xmm1    # 0x7ccd8
ucomisd %xmm1, %xmm0
jb 0x48082
movl -0x24(%rbp), %eax
andl $-0x9, %eax
movl %eax, -0x24(%rbp)
jmp 0x48084
jmp 0x48086
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rdi
addq $0x8870, %rdi           # imm = 0x8870
callq 0x4420
jmp 0x48133
movq -0x20(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8870, %rdi           # imm = 0x8870
callq 0x4420
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
movl -0x3c(%rbp), %r9d
leaq -0x38(%rbp), %rdx
callq 0x48260
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x48104
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x48252
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x46a0
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x481bd
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rsi
movl -0x28(%rbp), %r8d
leaq -0x38(%rbp), %rdx
movl $0x1, %r9d
movl %r9d, %ecx
callq 0x48260
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x4818d
movq 0x41e60(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
leaq 0x34cd0(%rip), %rsi     # 0x7ce4a
movb $0x0, %al
callq 0x4830
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x48252
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x46a0
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1fc(%rax)
je 0x48238
movq 0x41dff(%rip), %rax     # 0x89fd0
movq (%rax), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x108(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x104(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x100(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %edi
callq 0x48360
movq -0x110(%rbp), %rdi
movl -0x108(%rbp), %edx
movl -0x104(%rbp), %ecx
movl -0x100(%rbp), %r8d
movq %rax, %r9
leaq 0x34c2e(%rip), %rsi     # 0x7ce5f
movb $0x0, %al
callq 0x4830
movq -0x18(%rbp), %rax
cmpl $0xa, (%rax)
jne 0x4824b
movq -0x18(%rbp), %rax
movl $0x4, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nop