// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
movl 0xc(%rdi), %eax
movl %eax, %ebp
sarl $0x8, %ebp
movq 0x10(%rdi), %rsi
cmpb $0x0, 0x4(%rsi)
je 0x382b2
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x381ed
leaq 0x1b971(%rip), %rsi     # 0x53b4b
movq 0x10(%rsp), %rdi
callq 0x410b1
testq %rax, %rax
je 0x38525
cmpq $0x0, 0x48(%r12)
movq 0x10(%rsp), %r14
je 0x38209
cmpl $0x0, 0x20c(%r12)
je 0x382d3
movq %r14, %rdi
callq 0x40135
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x38bb5
movq %r14, %rdi
callq 0x40f8c
movl %eax, %r13d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x3856a
movq %r12, %rdi
movl %r13d, %esi
callq 0x322ae
cmpl $-0x1, %eax
je 0x38bb0
movq %r14, %rdi
movslq %r13d, %r14
movq %r12, %rbp
movq (%r12), %r15
callq 0x40f87
movq %rax, %r13
movq 0x8(%r15), %rdi
movq 0x18(%r15), %rbx
subq %rdi, %rbx
cmpq %r14, %rbx
movq %r14, %r12
cmovbq %rbx, %r12
movq %rax, %rsi
movq %r12, %rdx
callq 0x4420
addq %r12, 0x8(%r15)
cmpq %r14, %rbx
jae 0x382a4
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x48356
movq %rax, %r12
cmpq %r14, %r12
je 0x38b66
jmp 0x38bb0
movb %bpl, 0x4(%rsi)
movb %al, 0x5(%rsi)
movq %r12, %rdi
callq 0x37d13
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x38bb5
jmp 0x381c2
cmpl $0x0, 0x38(%r14)
jle 0x38209
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %r12, 0x20(%rsp)
movl %ebp, 0xc(%rsp)
movq 0x40(%r14), %rax
movq (%rax,%rbx), %rcx
movq %r14, %rdi
leaq 0x1b09a(%rip), %rsi     # 0x53398
leaq 0x1c99c(%rip), %rdx     # 0x54ca1
callq 0x3f792
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x38bb5
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
leaq 0x1c97c(%rip), %rdx     # 0x54ca4
xorl %ecx, %ecx
callq 0x3ff24
testq %rax, %rax
jne 0x38409
movq 0x48(%r12), %rax
testq %rax, %rax
je 0x38bb0
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x38bb0
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x38bb0
movq 0x10(%rax), %rbp
callq 0x49d74
testq %rax, %rax
je 0x38bb0
movq %rax, %r14
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x34746
testq %rax, %rax
je 0x38bb0
movq 0x48(%r12), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movslq 0x10(%rcx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x4933f
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x49c4d
movq %r14, %rdi
callq 0x49d9c
movq 0x48(%r12), %rdi
movl %r15d, %esi
callq 0x3430c
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x49da6
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x1c8b4(%rip), %rdx     # 0x54ca4
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3ff68
testl %eax, %eax
movl 0xc(%rsp), %ebp
jne 0x38bb0
movq 0x70(%r12), %r14
testq %r14, %r14
je 0x38507
cmpb $0x2f, (%r14)
jne 0x3843f
movl $0x1000, %edx           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x42b0
movb $0x0, 0x103f(%rsp)
jmp 0x384d9
movl $0x1000, %esi           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x42a0
testq %rax, %rax
je 0x38495
movq %r12, %rdi
callq 0x4230
movq %rax, %rbp
movq %rax, 0x28(%rsp)
shlq $0x20, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rbp, %rax
sarq $0x20, %rax
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x4230
addq 0x18(%rsp), %rax
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x384af
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r14, %rsi
callq 0x42b0
movb $0x0, 0x103f(%rsp)
jmp 0x384d5
sarq $0x20, %rbp
leaq (%rsp,%rbp), %rdi
addq $0x40, %rdi
movl $0x1000, %edx           # imm = 0x1000
subl 0x28(%rsp), %edx
leaq 0x1cbf5(%rip), %rsi     # 0x550c0
movq %r14, %rcx
xorl %eax, %eax
callq 0x4110
movl 0xc(%rsp), %ebp
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x1c7bf(%rip), %rdx     # 0x54ca7
movq %r12, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3ff68
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r12
jne 0x38bb5
incq %r15
movq 0x10(%rsp), %r14
movslq 0x38(%r14), %rax
addq $0x20, %rbx
cmpq %rax, %r15
jl 0x382ec
jmp 0x38209
movq $0x0, (%rsp)
leaq 0x1bbc2(%rip), %rsi     # 0x540f6
leaq 0x1c763(%rip), %rdx     # 0x54c9e
leaq 0x1b5c3(%rip), %r8      # 0x53b05
leaq 0x1b602(%rip), %rcx     # 0x53b4b
movq 0x10(%rsp), %rdi
movq %rcx, %r9
xorl %eax, %eax
callq 0x3ed32
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x38bb5
jmp 0x381ed
movl $0x40, %edi
callq 0x4700
testq %rax, %rax
je 0x3859e
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax)
xorl %eax, %eax
movq %rax, 0x30(%r15)
movupd %xmm0, (%r15)
movq %rax, 0x10(%r15)
movl $0x7, 0x38(%r15)
jmp 0x385a1
xorl %r15d, %r15d
xorl %edi, %edi
xorl %esi, %esi
callq 0x35b0c
movq %rax, %r14
testq %r15, %r15
setne %al
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x38866
movl %ebp, 0xc(%rsp)
movl 0xc(%r12), %eax
movl %eax, 0x18(%rsp)
movq %r15, %rdi
movl %r13d, %esi
callq 0x3234b
movslq %r13d, %r13
movq 0x28(%r15), %rax
movq 0x30(%r15), %rbp
movq %rbp, %rcx
addq %r13, %rcx
cmpq %rcx, %rax
ja 0x38667
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x1a32f(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1a337(%rip), %xmm0    # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1b3eb(%rip), %xmm1    # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x1a2db(%rip), %xmm1    # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq 0x20(%r15), %rdi
callq 0x48d0
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rbp
movq %rbp, %rcx
addq %r13, %rcx
cmpq %rcx, %rax
jbe 0x385f4
addq 0x20(%r15), %rbp
movq 0x10(%rsp), %rdi
callq 0x40f87
movq %rbp, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x4420
addq 0x30(%r15), %r13
movq %r13, 0x30(%r15)
movl %r13d, 0x14(%r15)
movl %r13d, 0x10(%r15)
cmpl $0x300, 0xc(%r12)       # imm = 0x300
jl 0x386b6
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x32fbb
cmpl $0x3, 0xc(%rsp)
jl 0x38881
movq %r12, 0x20(%rsp)
xorl %r12d, %r12d
cmpl $0x300, 0x18(%rsp)      # imm = 0x300
setge %dl
movl 0xc(%r15), %ebx
movl $0x1, %ecx
movl $0x1, %eax
cmpl $0x80, %ebx
jb 0x38712
movl $0x2, %eax
cmpl $0x4000, %ebx           # imm = 0x4000
jb 0x38712
movl $0x3, %eax
cmpl $0x200000, %ebx         # imm = 0x200000
jb 0x38712
cmpl $0x10000000, %ebx       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movb %dl, %r12b
movl 0x10(%r15), %edx
movl 0x14(%r15), %esi
cmpl $0x80, %esi
jb 0x3874d
movl $0x2, %ecx
cmpl $0x4000, %esi           # imm = 0x4000
jb 0x3874d
movl $0x3, %ecx
cmpl $0x200000, %esi         # imm = 0x200000
jb 0x3874d
cmpl $0x10000000, %esi       # imm = 0x10000000
movl $0x5, %ecx
sbbl $0x0, %ecx
shll $0x2, %r12d
movl $0x1, %esi
cmpl $0x80, %edx
jb 0x38786
movl $0x2, %esi
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x38786
movl $0x3, %esi
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x38786
cmpl $0x10000000, %edx       # imm = 0x10000000
movl $0x5, %esi
sbbl $0x0, %esi
addl %r12d, %edx
addl %ecx, %eax
addl %edx, %eax
leal (%rsi,%rax), %r13d
addl $0x2, %r13d
movl %r13d, (%r14)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0x24(%r14)
movl $0x8, %edi
callq 0x4700
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x38ba0
movl $0x0, (%rax)
movl %r13d, 0x4(%rax)
cvtsi2sd %r13d, %xmm0
mulsd 0x1a124(%rip), %xmm0    # 0x528f8
minsd 0x1c114(%rip), %xmm0    # 0x548f0
cvttsd2si %xmm0, %ebp
movl $0x1, %eax
cmpl $0x80, %ebx
jb 0x38815
movl $0x2, %eax
cmpl $0x4000, %ebx           # imm = 0x4000
jb 0x38815
movl $0x3, %eax
cmpl $0x200000, %ebx         # imm = 0x200000
jb 0x38815
cmpl $0x10000000, %ebx       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movl $0x2, %ecx
cmpl $0x80, %ebp
jb 0x3884e
movl $0x4, %ecx
cmpl $0x4000, %ebp           # imm = 0x4000
jb 0x3884e
movl $0x6, %ecx
cmpl $0x200000, %ebp         # imm = 0x200000
jb 0x3884e
xorl %ecx, %ecx
cmpl $0x10000000, %ebp       # imm = 0x10000000
setae %cl
leal 0x8(,%rcx,2), %ecx
addl %r12d, %r13d
addl %eax, %r13d
addl %ebp, %r13d
leal (%rcx,%r13), %eax
addl $0x2, %eax
movl %eax, (%r14)
jmp 0x38a6a
testq %r15, %r15
je 0x38873
movq %r15, %rdi
callq 0x32ea8
testq %r14, %r14
jne 0x38ba8
jmp 0x38bb0
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x24(%r14)
movl $0x4, %edi
callq 0x4700
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x38bb0
movl $0x0, (%rax)
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
movsd 0x1b14c(%rip), %xmm0    # 0x53a08
mulsd %xmm1, %xmm0
maxsd 0x1c028(%rip), %xmm0    # 0x548f0
movl 0xc(%r15), %edx
movl $0x1, %eax
movl $0x1, %ecx
cmpl $0x80, %edx
jb 0x38906
movl $0x2, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x38906
movl $0x3, %ecx
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x38906
cmpl $0x10000000, %edx       # imm = 0x10000000
movl $0x5, %ecx
sbbl $0x0, %ecx
subsd %xmm1, %xmm0
movl 0x10(%r15), %edx
movl 0x14(%r15), %esi
cmpl $0x80, %esi
jb 0x38942
movl $0x2, %eax
cmpl $0x4000, %esi           # imm = 0x4000
jb 0x38942
movl $0x3, %eax
cmpl $0x200000, %esi         # imm = 0x200000
jb 0x38942
cmpl $0x10000000, %esi       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movq %r12, 0x20(%rsp)
cvttsd2si %xmm0, %ebp
movl $0x1, %esi
cmpl $0x80, %edx
jb 0x38980
movl $0x2, %esi
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x38980
movl $0x3, %esi
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x38980
cmpl $0x10000000, %edx       # imm = 0x10000000
movl $0x5, %esi
sbbl $0x0, %esi
xorl %edi, %edi
cmpl $0x300, 0x18(%rsp)      # imm = 0x300
setge %dil
leal (%rdx,%rdi,4), %edx
addl %ecx, %edx
addl %eax, %edx
addl %ebp, %edx
leal (%rsi,%rdx), %eax
addl $0x2, %eax
movl %eax, (%r14)
movslq %ebp, %r12
movl $0x1, %edi
movq %r12, %rsi
callq 0x4360
testq %rax, %rax
je 0x38ba0
movq %rax, %r13
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
ja 0x38a43
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x19f51(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x19f59(%rip), %xmm0    # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1b00d(%rip), %xmm1    # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x19efd(%rip), %xmm1    # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq 0x20(%r15), %rdi
callq 0x48d0
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
jbe 0x389d2
addq 0x20(%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4420
addq 0x30(%r15), %r12
movq %r12, 0x30(%r15)
movl %r12d, 0x14(%r15)
movl %r12d, 0x10(%r15)
movq %r13, %rdi
callq 0x4610
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36cb9
cmpl $-0x1, %eax
je 0x38ba0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x32aba
cmpl $-0x1, %eax
je 0x38ba0
cmpl $0x3, 0xc(%rsp)
jl 0x38b53
movq %rbx, %r13
movslq %ebp, %r12
movq 0x28(%r15), %rax
cmpq %r12, %rax
ja 0x38b1f
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x19e6d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x19e75(%rip), %xmm0    # 0x52940
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x1af29(%rip), %xmm1    # 0x53a08
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x19e19(%rip), %xmm1    # 0x52908
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq 0x20(%r15), %rdi
callq 0x48d0
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
cmpq %r12, %rax
jbe 0x38ab6
movq 0x20(%r15), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x42d0
movq %r12, 0x30(%r15)
movl %r12d, 0x14(%r15)
movl %r12d, 0x10(%r15)
movl $0x0, (%r15)
movq %r13, %rbx
movq %r13, %rdi
movq %r15, %rsi
callq 0x32aba
cmpl $-0x1, %eax
je 0x38ba0
movq %rbx, %rbp
movq %r15, %rdi
callq 0x32ea8
movq %r14, %rdi
callq 0x35cde
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x33e56
cmpl $-0x1, %eax
je 0x38bb0
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x33c60
cmpl $-0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
je 0x38bb5
movq (%rbp), %rdi
callq 0x48277
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
jmp 0x38bb5
movq %r15, %rdi
callq 0x32ea8
movq %r14, %rdi
callq 0x35cde
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq