// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/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 0x5b9a8
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x5b8e3
leaq 0x3d726(%rip), %rsi     # 0x98ff6
movq 0x10(%rsp), %rdi
callq 0x64315
testq %rax, %rax
je 0x5bc1b
cmpq $0x0, 0x48(%r12)
movq 0x10(%rsp), %r14
je 0x5b8ff
cmpl $0x0, 0x20c(%r12)
je 0x5b9c9
movq %r14, %rdi
callq 0x6342e
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c2ab
movq %r14, %rdi
callq 0x641f0
movl %eax, %r13d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x5bc60
movq %r12, %rdi
movl %r13d, %esi
callq 0x55bc6
cmpl $-0x1, %eax
je 0x5c2a6
movq %r14, %rdi
movslq %r13d, %r14
movq %r12, %rbp
movq (%r12), %r15
callq 0x641eb
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 0x6570
addq %r12, 0x8(%r15)
cmpq %r14, %rbx
jae 0x5b99a
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x6b222
movq %rax, %r12
cmpq %r14, %r12
je 0x5c25c
jmp 0x5c2a6
movb %bpl, 0x4(%rsi)
movb %al, 0x5(%rsi)
movq %r12, %rdi
callq 0x5b409
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c2ab
jmp 0x5b8b8
cmpl $0x0, 0x38(%r14)
jle 0x5b8ff
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 0x3ea94(%rip), %rsi     # 0x9a488
leaq 0x3d60c(%rip), %rdx     # 0x99007
callq 0x62ab8
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x5c2ab
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
leaq 0x3d5ec(%rip), %rdx     # 0x9900a
xorl %ecx, %ecx
callq 0x6321d
testq %rax, %rax
jne 0x5baff
movq 0x48(%r12), %rax
testq %rax, %rax
je 0x5c2a6
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x5c2a6
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x5c2a6
movq 0x10(%rax), %rbp
callq 0x6cc30
testq %rax, %rax
je 0x5c2a6
movq %rax, %r14
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x580c5
testq %rax, %rax
je 0x5c2a6
movq 0x48(%r12), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movslq 0x10(%rcx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x6c1fb
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6cb09
movq %r14, %rdi
callq 0x6cc58
movq 0x48(%r12), %rdi
movl %r15d, %esi
callq 0x57c8b
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6cc62
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x3d524(%rip), %rdx     # 0x9900a
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x63261
testl %eax, %eax
movl 0xc(%rsp), %ebp
jne 0x5c2a6
movq 0x70(%r12), %r14
testq %r14, %r14
je 0x5bbfd
cmpb $0x2f, (%r14)
jne 0x5bb35
movl $0x1000, %edx           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x6380
movb $0x0, 0x103f(%rsp)
jmp 0x5bbcf
movl $0x1000, %esi           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x6370
testq %rax, %rax
je 0x5bb8b
movq %r12, %rdi
callq 0x62d0
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 0x62d0
addq 0x18(%rsp), %rax
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x5bba5
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r14, %rsi
callq 0x6380
movb $0x0, 0x103f(%rsp)
jmp 0x5bbcb
sarq $0x20, %rbp
leaq (%rsp,%rbp), %rdi
addq $0x40, %rdi
movl $0x1000, %edx           # imm = 0x1000
subl 0x28(%rsp), %edx
leaq 0x3d767(%rip), %rsi     # 0x99328
movq %r14, %rcx
xorl %eax, %eax
callq 0x6170
movl 0xc(%rsp), %ebp
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x34700(%rip), %rdx     # 0x902de
movq %r12, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x63261
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r12
jne 0x5c2ab
incq %r15
movq 0x10(%rsp), %r14
movslq 0x38(%r14), %rax
addq $0x20, %rbx
cmpq %rax, %r15
jl 0x5b9e2
jmp 0x5b8ff
movq $0x0, (%rsp)
leaq 0x3d3d4(%rip), %rsi     # 0x98ffe
leaq 0x3d3d0(%rip), %rdx     # 0x99001
leaq 0x3d3cc(%rip), %r8      # 0x99004
leaq 0x3d3b7(%rip), %rcx     # 0x98ff6
movq 0x10(%rsp), %rdi
movq %rcx, %r9
xorl %eax, %eax
callq 0x6211d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c2ab
jmp 0x5b8e3
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x5bc94
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 0x5bc97
xorl %r15d, %r15d
xorl %edi, %edi
xorl %esi, %esi
callq 0x59202
movq %rax, %r14
testq %r15, %r15
setne %al
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x5bf5c
movl %ebp, 0xc(%rsp)
movl 0xc(%r12), %eax
movl %eax, 0x18(%rsp)
movq %r15, %rdi
movl %r13d, %esi
callq 0x55c63
movslq %r13d, %r13
movq 0x28(%r15), %rax
movq 0x30(%r15), %rbp
movq %rbp, %rcx
addq %r13, %rcx
cmpq %rcx, %rax
ja 0x5bd5d
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x30319(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x30321(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x34ae5(%rip), %xmm1    # 0x907f8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x3c3f5(%rip), %xmm1    # 0x98118
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 0x6c80
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rbp
movq %rbp, %rcx
addq %r13, %rcx
cmpq %rcx, %rax
jbe 0x5bcea
addq 0x20(%r15), %rbp
movq 0x10(%rsp), %rdi
callq 0x641eb
movq %rbp, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x6570
addq 0x30(%r15), %r13
movq %r13, 0x30(%r15)
movl %r13d, 0x14(%r15)
movl %r13d, 0x10(%r15)
cmpl $0x300, 0xc(%r12)       # imm = 0x300
jl 0x5bdac
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x568d3
cmpl $0x3, 0xc(%rsp)
jl 0x5bf77
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 0x5be08
movl $0x2, %eax
cmpl $0x4000, %ebx           # imm = 0x4000
jb 0x5be08
movl $0x3, %eax
cmpl $0x200000, %ebx         # imm = 0x200000
jb 0x5be08
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 0x5be43
movl $0x2, %ecx
cmpl $0x4000, %esi           # imm = 0x4000
jb 0x5be43
movl $0x3, %ecx
cmpl $0x200000, %esi         # imm = 0x200000
jb 0x5be43
cmpl $0x10000000, %esi       # imm = 0x10000000
movl $0x5, %ecx
sbbl $0x0, %ecx
shll $0x2, %r12d
movl $0x1, %esi
cmpl $0x80, %edx
jb 0x5be7c
movl $0x2, %esi
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5be7c
movl $0x3, %esi
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5be7c
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 0x69d0
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x5c296
movl $0x0, (%rax)
movl %r13d, 0x4(%rax)
cvtsi2sd %r13d, %xmm0
mulsd 0x32ede(%rip), %xmm0    # 0x8eda8
minsd 0x3cd76(%rip), %xmm0    # 0x98c48
cvttsd2si %xmm0, %ebp
movl $0x1, %eax
cmpl $0x80, %ebx
jb 0x5bf0b
movl $0x2, %eax
cmpl $0x4000, %ebx           # imm = 0x4000
jb 0x5bf0b
movl $0x3, %eax
cmpl $0x200000, %ebx         # imm = 0x200000
jb 0x5bf0b
cmpl $0x10000000, %ebx       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movl $0x2, %ecx
cmpl $0x80, %ebp
jb 0x5bf44
movl $0x4, %ecx
cmpl $0x4000, %ebp           # imm = 0x4000
jb 0x5bf44
movl $0x6, %ecx
cmpl $0x200000, %ebp         # imm = 0x200000
jb 0x5bf44
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 0x5c160
testq %r15, %r15
je 0x5bf69
movq %r15, %rdi
callq 0x567c0
testq %r14, %r14
jne 0x5c29e
jmp 0x5c2a6
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x24(%r14)
movl $0x4, %edi
callq 0x69d0
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x5c2a6
movl $0x0, (%rax)
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
movsd 0x34846(%rip), %xmm0    # 0x907f8
mulsd %xmm1, %xmm0
maxsd 0x3cc8a(%rip), %xmm0    # 0x98c48
movl 0xc(%r15), %edx
movl $0x1, %eax
movl $0x1, %ecx
cmpl $0x80, %edx
jb 0x5bffc
movl $0x2, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5bffc
movl $0x3, %ecx
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5bffc
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 0x5c038
movl $0x2, %eax
cmpl $0x4000, %esi           # imm = 0x4000
jb 0x5c038
movl $0x3, %eax
cmpl $0x200000, %esi         # imm = 0x200000
jb 0x5c038
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 0x5c076
movl $0x2, %esi
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5c076
movl $0x3, %esi
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5c076
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 0x6470
testq %rax, %rax
je 0x5c296
movq %rax, %r13
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
ja 0x5c139
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x2ff3b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2ff43(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x34707(%rip), %xmm1    # 0x907f8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x3c017(%rip), %xmm1    # 0x98118
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 0x6c80
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdi
leaq (%rdi,%r12), %rcx
cmpq %rcx, %rax
jbe 0x5c0c8
addq 0x20(%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x6570
addq 0x30(%r15), %r12
movq %r12, 0x30(%r15)
movl %r12d, 0x14(%r15)
movl %r12d, 0x10(%r15)
movq %r13, %rdi
callq 0x68a0
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5a3af
cmpl $-0x1, %eax
je 0x5c296
movq %rbx, %rdi
movq %r15, %rsi
callq 0x563d2
cmpl $-0x1, %eax
je 0x5c296
cmpl $0x3, 0xc(%rsp)
jl 0x5c249
movq %rbx, %r13
movslq %ebp, %r12
movq 0x28(%r15), %rax
cmpq %r12, %rax
ja 0x5c215
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x2fe57(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2fe5f(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x34623(%rip), %xmm1    # 0x907f8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
subsd 0x3bf33(%rip), %xmm1    # 0x98118
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 0x6c80
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
cmpq %r12, %rax
jbe 0x5c1ac
movq 0x20(%r15), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x63b0
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 0x563d2
cmpl $-0x1, %eax
je 0x5c296
movq %rbx, %rbp
movq %r15, %rdi
callq 0x567c0
movq %r14, %rdi
callq 0x593d4
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x577d5
cmpl $-0x1, %eax
je 0x5c2a6
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x575df
cmpl $-0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
je 0x5c2ab
movq (%rbp), %rdi
callq 0x6b143
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
jmp 0x5c2ab
movq %r15, %rdi
callq 0x567c0
movq %r14, %rdi
callq 0x593d4
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