// File: karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: cram_write_SAM_hdr
int cram_write_SAM_hdr(cram_fd *fd, SAM_hdr *hdr) {
    int header_len;
    int blank_block = (CRAM_MAJOR_VERS(fd->version) >= 3);

    /* Write CRAM MAGIC if not yet written. */
    if (fd->file_def->major_version == 0) {
	fd->file_def->major_version = CRAM_MAJOR_VERS(fd->version);
	fd->file_def->minor_version = CRAM_MINOR_VERS(fd->version);
	if (0 != cram_write_file_def(fd, fd->file_def))
	    return -1;
    }

    /* 1.0 requires an UNKNOWN read-group */
    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	if (!sam_hdr_find_rg(hdr, "UNKNOWN"))
	    if (sam_hdr_add(hdr, "RG",
			    "ID", "UNKNOWN", "SM", "UNKNOWN", NULL))
		return -1;
    }

    /* Fix M5 strings */
    if (fd->refs && !fd->no_ref) {
	int i;
	for (i = 0; i < hdr->nref; i++) {
	    SAM_hdr_type *ty;
	    char *ref;

	    if (!(ty = sam_hdr_find(hdr, "SQ", "SN", hdr->ref[i].name)))
		return -1;

	    if (!sam_hdr_find_key(hdr, ty, "M5", NULL)) {
		char unsigned buf[16];
		char buf2[33];
		int rlen;
		hts_md5_context *md5;

		if (!fd->refs ||
		    !fd->refs->ref_id ||
		    !fd->refs->ref_id[i]) {
		    return -1;
		}
		rlen = fd->refs->ref_id[i]->length;
		if (!(md5 = hts_md5_init()))
		    return -1;
		ref = cram_get_ref(fd, i, 1, rlen);
		if (NULL == ref) return -1;
		rlen = fd->refs->ref_id[i]->length; /* In case it just loaded */
		hts_md5_update(md5, ref, rlen);
		hts_md5_final(buf, md5);
		hts_md5_destroy(md5);
		cram_ref_decr(fd->refs, i);

		hts_md5_hex(buf2, buf);
		if (sam_hdr_update(hdr, ty, "M5", buf2, NULL))
		    return -1;
	    }

	    if (fd->ref_fn) {
		char ref_fn[PATH_MAX];
		full_path(ref_fn, fd->ref_fn);
		if (sam_hdr_update(hdr, ty, "UR", ref_fn, NULL))
		    return -1;
	    }
	}
    }

    if (sam_hdr_rebuild(hdr))
	return -1;

    /* Length */
    header_len = sam_hdr_length(hdr);
    if (CRAM_MAJOR_VERS(fd->version) == 1) {
	if (-1 == int32_encode(fd, header_len))
	    return -1;

	/* Text data */
	if (header_len != hwrite(fd->fp, sam_hdr_str(hdr), header_len))
	    return -1;
    } else {
	/* Create block(s) inside a container */
	cram_block *b = cram_new_block(FILE_HEADER, 0);
	cram_container *c = cram_new_container(0, 0);
	int padded_length;
	char *pads;
	int is_cram_3 = (CRAM_MAJOR_VERS(fd->version) >= 3);

	if (!b || !c) {
	    if (b) cram_free_block(b);
	    if (c) cram_free_container(c);
	    return -1;
	}

	int32_put_blk(b, header_len);
	BLOCK_APPEND(b, sam_hdr_str(hdr), header_len);
	BLOCK_UPLEN(b);

	// Compress header block if V3.0 and above
	if (CRAM_MAJOR_VERS(fd->version) >= 3)
	    cram_compress_block(fd, b, NULL, -1, -1);

	if (blank_block) {
	    c->length = b->comp_size + 2 + 4*is_cram_3 +
		itf8_size(b->content_id)   + 
		itf8_size(b->uncomp_size)  +
		itf8_size(b->comp_size);

	    c->num_blocks = 2;
	    c->num_landmarks = 2;
	    if (!(c->landmark = malloc(2*sizeof(*c->landmark)))) {
		cram_free_block(b);
		cram_free_container(c);
		return -1;
	    }
	    c->landmark[0] = 0;
	    c->landmark[1] = c->length;

	    // Plus extra storage for uncompressed secondary blank block
	    padded_length = MIN(c->length*.5, 10000);
	    c->length += padded_length + 2 + 4*is_cram_3 +
		itf8_size(b->content_id) + 
		itf8_size(padded_length)*2;
	} else {
	    // Pad the block instead.
	    c->num_blocks = 1;
	    c->num_landmarks = 1;
	    if (!(c->landmark = malloc(sizeof(*c->landmark))))
		return -1;
	    c->landmark[0] = 0;

	    padded_length = MAX(c->length*1.5, 10000) - c->length;

	    c->length = b->comp_size + padded_length +
		2 + 4*is_cram_3 +
		itf8_size(b->content_id)   + 
		itf8_size(b->uncomp_size)  +
		itf8_size(b->comp_size);

	    if (NULL == (pads = calloc(1, padded_length))) {
		cram_free_block(b);
		cram_free_container(c);
		return -1;
	    }
	    BLOCK_APPEND(b, pads, padded_length);
	    BLOCK_UPLEN(b);
	    free(pads);
	}

	if (-1 == cram_write_container(fd, c)) {
	    cram_free_block(b);
	    cram_free_container(c);
	    return -1;
	}

	if (-1 == cram_write_block(fd, b)) {
	    cram_free_block(b);
	    cram_free_container(c);
	    return -1;
	}

	if (blank_block) {
	    BLOCK_RESIZE(b, padded_length);
	    memset(BLOCK_DATA(b), 0, padded_length);
	    BLOCK_SIZE(b) = padded_length;
	    BLOCK_UPLEN(b);
	    b->method = RAW;
	    if (-1 == cram_write_block(fd, b)) {
		cram_free_block(b);
		cram_free_container(c);
		return -1;
	    }
	}

	cram_free_block(b);
	cram_free_container(c);
    }

    if (-1 == refs_from_header(fd->refs, fd, fd->header))
	return -1;
    if (-1 == refs2id(fd->refs, fd->header))
	return -1;

    if (0 != hflush(fd->fp))
	return -1;

    RP("=== Finishing saving header ===\n");

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1180, %rsp           # imm = 0x1180
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0x50673
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movb %cl, 0x4(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movb %cl, 0x5(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4fe00
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x50671
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x50673
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x506e1
movq -0x18(%rbp), %rdi
leaq 0x2b58e(%rip), %rsi     # 0x7bc1b
callq 0x5ebc0
cmpq $0x0, %rax
jne 0x506df
movq -0x18(%rbp), %rdi
leaq 0x2bd83(%rip), %rsi     # 0x7c426
leaq 0x2c9df(%rip), %rdx     # 0x7d089
leaq 0x2b56a(%rip), %r9      # 0x7bc1b
leaq 0x2b51d(%rip), %r8      # 0x7bbd5
xorl %eax, %eax
movq %r9, %rcx
movq $0x0, (%rsp)
movb $0x0, %al
callq 0x5c890
cmpl $0x0, %eax
je 0x506dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x506df
jmp 0x506e1
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x5092b
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20c(%rax)
jne 0x5092b
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0x50929
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0x2ad21(%rip), %rsi     # 0x7b45a
leaq 0x2c94c(%rip), %rdx     # 0x7d08c
callq 0x5d1a0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x5075b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x2c925(%rip), %rdx     # 0x7d08f
xorl %eax, %eax
movl %eax, %ecx
callq 0x5d910
cmpq $0x0, %rax
jne 0x508c5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x507ae
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x507ae
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x507ba
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movl %eax, -0x84(%rbp)
callq 0x6dc50
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
jne 0x507f6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x84(%rbp), %ecx
movl $0x1, %edx
callq 0x497b0
movq %rax, -0x38(%rbp)
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
jne 0x50825
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movl %eax, -0x84(%rbp)
movq -0x90(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x84(%rbp), %rdx
callq 0x6c860
leaq -0x50(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x6d9c0
movq -0x90(%rbp), %rdi
callq 0x6dca0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x24(%rbp), %esi
callq 0x49010
leaq -0x80(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x6dcd0
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x80(%rbp), %rcx
leaq 0x2c7e9(%rip), %rdx     # 0x7d08f
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x5d9c0
cmpl $0x0, %eax
je 0x508c3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x508c5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x50919
leaq -0x1090(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rsi
callq 0x51870
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x1090(%rbp), %rcx
leaq 0x2c798(%rip), %rdx     # 0x7d092
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x5d9c0
cmpl $0x0, %eax
je 0x50917
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x50919
jmp 0x5091b
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x50708
jmp 0x5092b
movq -0x18(%rbp), %rdi
callq 0x5dc70
cmpl $0x0, %eax
je 0x50945
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x18(%rbp), %rdi
callq 0x5eab0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x1, %eax
jne 0x509d8
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x455e0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x50983
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movslq -0x1c(%rbp), %rax
movq %rax, -0x10c0(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10c8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5ea90
movq -0x10c8(%rbp), %rdi
movq %rax, %rsi
movslq -0x1c(%rbp), %rdx
callq 0x43620
movq %rax, %rcx
movq -0x10c0(%rbp), %rax
cmpq %rcx, %rax
je 0x509d3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x517e1
xorl %esi, %esi
movl %esi, %edi
callq 0x45b10
movq %rax, -0x1098(%rbp)
xorl %esi, %esi
movl %esi, %edi
callq 0x4b310
movq %rax, -0x10a0(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x10b4(%rbp)
cmpq $0x0, -0x1098(%rbp)
je 0x50a27
cmpq $0x0, -0x10a0(%rbp)
jne 0x50a5f
cmpq $0x0, -0x1098(%rbp)
je 0x50a3d
movq -0x1098(%rbp), %rdi
callq 0x470c0
cmpq $0x0, -0x10a0(%rbp)
je 0x50a53
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x1098(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x456e0
jmp 0x50a70
jmp 0x50a72
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x1098(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
ja 0x50b63
movq -0x1098(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x50aea
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %xmm0
movaps 0x2a027(%rip), %xmm1    # 0x7aae0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2a02b(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x2affc(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x10d0(%rbp)
jmp 0x50afc
movsd 0x2afde(%rip), %xmm0    # 0x7bad0
movsd %xmm0, -0x10d0(%rbp)
jmp 0x50afc
movsd -0x10d0(%rbp), %xmm0
movsd 0x29fb4(%rip), %xmm2    # 0x7aac0
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x50a72
jmp 0x50b65
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x1098(%rbp), %rcx
addq 0x30(%rcx), %rax
movq %rax, -0x10d8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5ea90
movq -0x10d8(%rbp), %rdi
movq %rax, %rsi
movslq -0x1c(%rbp), %rdx
callq 0x4460
movslq -0x1c(%rbp), %rcx
movq -0x1098(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x1098(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x1098(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x1098(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
sarl $0x8, %eax
cmpl $0x3, %eax
jl 0x50bfe
movq -0x10(%rbp), %rdi
movq -0x1098(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %r8d, %ecx
callq 0x472d0
cmpl $0x0, -0x20(%rbp)
je 0x510df
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x2, %eax
movl -0x10b4(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x10dc(%rbp)
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x50c48
movl $0x1, %eax
movl %eax, -0x10e0(%rbp)
jmp 0x50cd0
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x50c69
movl $0x2, %eax
movl %eax, -0x10e4(%rbp)
jmp 0x50cc4
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x50c8a
movl $0x3, %eax
movl %eax, -0x10e8(%rbp)
jmp 0x50cb8
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x10e8(%rbp)
movl -0x10e8(%rbp), %eax
movl %eax, -0x10e4(%rbp)
movl -0x10e4(%rbp), %eax
movl %eax, -0x10e0(%rbp)
movl -0x10dc(%rbp), %eax
movl -0x10e0(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x10ec(%rbp)
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x50d06
movl $0x1, %eax
movl %eax, -0x10f0(%rbp)
jmp 0x50d8e
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x50d27
movl $0x2, %eax
movl %eax, -0x10f4(%rbp)
jmp 0x50d82
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x50d48
movl $0x3, %eax
movl %eax, -0x10f8(%rbp)
jmp 0x50d76
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x10f8(%rbp)
movl -0x10f8(%rbp), %eax
movl %eax, -0x10f4(%rbp)
movl -0x10f4(%rbp), %eax
movl %eax, -0x10f0(%rbp)
movl -0x10ec(%rbp), %eax
movl -0x10f0(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x10fc(%rbp)
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x50dc4
movl $0x1, %eax
movl %eax, -0x1100(%rbp)
jmp 0x50e4c
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x50de5
movl $0x2, %eax
movl %eax, -0x1104(%rbp)
jmp 0x50e40
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x50e06
movl $0x3, %eax
movl %eax, -0x1108(%rbp)
jmp 0x50e34
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1108(%rbp)
movl -0x1108(%rbp), %eax
movl %eax, -0x1104(%rbp)
movl -0x1104(%rbp), %eax
movl %eax, -0x1100(%rbp)
movl -0x10fc(%rbp), %ecx
movl -0x1100(%rbp), %eax
addl %eax, %ecx
movq -0x10a0(%rbp), %rax
movl %ecx, (%rax)
movq -0x10a0(%rbp), %rax
movl $0x2, 0x24(%rax)
movq -0x10a0(%rbp), %rax
movl $0x2, 0x28(%rax)
movl $0x8, %edi
callq 0x47a0
movq -0x10a0(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x50ebe
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10a0(%rbp), %rax
movq 0x30(%rax), %rax
movl $0x0, (%rax)
movq -0x10a0(%rbp), %rax
movl (%rax), %ecx
movq -0x10a0(%rbp), %rax
movq 0x30(%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
movsd 0x29bb7(%rip), %xmm0    # 0x7aab0
mulsd %xmm0, %xmm1
movsd 0x2bddb(%rip), %xmm0    # 0x7cce0
ucomisd %xmm1, %xmm0
jbe 0x50f2c
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
movsd 0x29b92(%rip), %xmm1    # 0x7aab0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1110(%rbp)
jmp 0x50f3e
movsd 0x2bdac(%rip), %xmm0    # 0x7cce0
movsd %xmm0, -0x1110(%rbp)
jmp 0x50f3e
movsd -0x1110(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x10a4(%rbp)
movl -0x10a4(%rbp), %eax
addl $0x2, %eax
movl -0x10b4(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x1114(%rbp)
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x50f8c
movl $0x1, %eax
movl %eax, -0x1118(%rbp)
jmp 0x51014
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x50fad
movl $0x2, %eax
movl %eax, -0x111c(%rbp)
jmp 0x51008
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x50fce
movl $0x3, %eax
movl %eax, -0x1120(%rbp)
jmp 0x50ffc
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1120(%rbp)
movl -0x1120(%rbp), %eax
movl %eax, -0x111c(%rbp)
movl -0x111c(%rbp), %eax
movl %eax, -0x1118(%rbp)
movl -0x1114(%rbp), %eax
movl -0x1118(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x1124(%rbp)
movl -0x10a4(%rbp), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x51043
movl $0x1, %eax
movl %eax, -0x1128(%rbp)
jmp 0x510bf
movl -0x10a4(%rbp), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x51060
movl $0x2, %eax
movl %eax, -0x112c(%rbp)
jmp 0x510b3
movl -0x10a4(%rbp), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x5107d
movl $0x3, %eax
movl %eax, -0x1130(%rbp)
jmp 0x510a7
movl -0x10a4(%rbp), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1130(%rbp)
movl -0x1130(%rbp), %eax
movl %eax, -0x112c(%rbp)
movl -0x112c(%rbp), %eax
movl %eax, -0x1128(%rbp)
movl -0x1124(%rbp), %ecx
movl -0x1128(%rbp), %eax
shll %eax
addl %eax, %ecx
movq -0x10a0(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x515bb
movq -0x10a0(%rbp), %rax
movl $0x1, 0x24(%rax)
movq -0x10a0(%rbp), %rax
movl $0x1, 0x28(%rax)
movl $0x4, %edi
callq 0x47a0
movq -0x10a0(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x51122
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10a0(%rbp), %rax
movq 0x30(%rax), %rax
movl $0x0, (%rax)
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
movsd 0x2a992(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd 0x2bb8e(%rip), %xmm1    # 0x7cce0
ucomisd %xmm1, %xmm0
jbe 0x51179
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
movsd 0x2a96d(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1138(%rbp)
jmp 0x5118b
movsd 0x2bb5f(%rip), %xmm0    # 0x7cce0
movsd %xmm0, -0x1138(%rbp)
jmp 0x5118b
movsd -0x1138(%rbp), %xmm0
movq -0x10a0(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x10a4(%rbp)
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
addl -0x10a4(%rbp), %eax
addl $0x2, %eax
movl -0x10b4(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x113c(%rbp)
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x511f2
movl $0x1, %eax
movl %eax, -0x1140(%rbp)
jmp 0x5127a
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x51213
movl $0x2, %eax
movl %eax, -0x1144(%rbp)
jmp 0x5126e
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x51234
movl $0x3, %eax
movl %eax, -0x1148(%rbp)
jmp 0x51262
movq -0x1098(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1148(%rbp)
movl -0x1148(%rbp), %eax
movl %eax, -0x1144(%rbp)
movl -0x1144(%rbp), %eax
movl %eax, -0x1140(%rbp)
movl -0x113c(%rbp), %eax
movl -0x1140(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x114c(%rbp)
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x512b0
movl $0x1, %eax
movl %eax, -0x1150(%rbp)
jmp 0x51338
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x512d1
movl $0x2, %eax
movl %eax, -0x1154(%rbp)
jmp 0x5132c
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x512f2
movl $0x3, %eax
movl %eax, -0x1158(%rbp)
jmp 0x51320
movq -0x1098(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1158(%rbp)
movl -0x1158(%rbp), %eax
movl %eax, -0x1154(%rbp)
movl -0x1154(%rbp), %eax
movl %eax, -0x1150(%rbp)
movl -0x114c(%rbp), %eax
movl -0x1150(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x115c(%rbp)
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $-0x80, %eax
cmpl $0x0, %eax
jne 0x5136e
movl $0x1, %eax
movl %eax, -0x1160(%rbp)
jmp 0x513f6
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffffc000, %eax       # imm = 0xFFFFC000
cmpl $0x0, %eax
jne 0x5138f
movl $0x2, %eax
movl %eax, -0x1164(%rbp)
jmp 0x513ea
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffe00000, %eax       # imm = 0xFFE00000
cmpl $0x0, %eax
jne 0x513b0
movl $0x3, %eax
movl %eax, -0x1168(%rbp)
jmp 0x513de
movq -0x1098(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xf0000000, %eax       # imm = 0xF0000000
cmpl $0x0, %eax
setne %dl
xorb $-0x1, %dl
movl $0x5, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1168(%rbp)
movl -0x1168(%rbp), %eax
movl %eax, -0x1164(%rbp)
movl -0x1164(%rbp), %eax
movl %eax, -0x1160(%rbp)
movl -0x115c(%rbp), %ecx
movl -0x1160(%rbp), %eax
addl %eax, %ecx
movq -0x10a0(%rbp), %rax
movl %ecx, (%rax)
movslq -0x10a4(%rbp), %rsi
movl $0x1, %edi
callq 0x4370
movq %rax, %rcx
movq %rcx, -0x10b0(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x51453
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x51455
jmp 0x51457
jmp 0x51459
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x1098(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x10a4(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
ja 0x5154d
movq -0x1098(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x514d4
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %xmm0
movaps 0x2963d(%rip), %xmm1    # 0x7aae0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x29641(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x2a612(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1170(%rbp)
jmp 0x514e6
movsd 0x2a5f4(%rip), %xmm0    # 0x7bad0
movsd %xmm0, -0x1170(%rbp)
jmp 0x514e6
movsd -0x1170(%rbp), %xmm0
movsd 0x295ca(%rip), %xmm2    # 0x7aac0
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x51459
jmp 0x5154f
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x1098(%rbp), %rax
addq 0x30(%rax), %rdi
movq -0x10b0(%rbp), %rsi
movslq -0x10a4(%rbp), %rdx
callq 0x4460
movslq -0x10a4(%rbp), %rcx
movq -0x1098(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x1098(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x1098(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x1098(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10b0(%rbp), %rdi
callq 0x46a0
movq -0x10(%rbp), %rdi
movq -0x10a0(%rbp), %rsi
callq 0x4d8d0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x515fa
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rdi
movq -0x1098(%rbp), %rsi
callq 0x46670
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x51639
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
cmpl $0x0, -0x20(%rbp)
je 0x517c9
jmp 0x51645
jmp 0x51647
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x10a4(%rbp), %rcx
cmpq %rcx, %rax
ja 0x5172d
movq -0x1098(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x516b4
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %xmm0
movaps 0x2945d(%rip), %xmm1    # 0x7aae0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x29461(%rip), %xmm1    # 0x7aaf0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x2a432(%rip), %xmm1    # 0x7bad8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x1178(%rbp)
jmp 0x516c6
movsd 0x2a414(%rip), %xmm0    # 0x7bad0
movsd %xmm0, -0x1178(%rbp)
jmp 0x516c6
movsd -0x1178(%rbp), %xmm0
movsd 0x293ea(%rip), %xmm2    # 0x7aac0
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rdx, %rax
orq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x1098(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x51647
jmp 0x5172f
movq -0x1098(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0x10a4(%rbp), %rdx
xorl %esi, %esi
callq 0x42d0
movslq -0x10a4(%rbp), %rcx
movq -0x1098(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x1098(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x1098(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x1098(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x1098(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x1098(%rbp), %rsi
callq 0x46670
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x517c7
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
jmp 0x517c9
movq -0x1098(%rbp), %rdi
callq 0x470c0
movq -0x10a0(%rbp), %rdi
callq 0x4b5e0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x489e0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x5180e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x48700
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x51837
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x6a8e0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x51854
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5185b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1180, %rsp           # imm = 0x1180
popq %rbp
retq
nopw (%rax,%rax)