// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %rdi, %r12
movl 0xc(%rdi), %eax
movl %eax, %ebp
sarl $0x8, %ebp
movq 0x10(%rdi), %rsi
cmpb $0x0, 0x4(%rsi)
je 0x5bb7c
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x100, %eax            # imm = 0x100
jne 0x5bab5
leaq 0x3d75c(%rip), %rsi     # 0x991fe
movq 0x8(%rsp), %rdi
callq 0x6439e
testq %rax, %rax
je 0x5bdf4
cmpq $0x0, 0x48(%r12)
movq 0x8(%rsp), %r14
je 0x5bad1
cmpl $0x0, 0x20c(%r12)
je 0x5bba2
movq %r14, %rdi
callq 0x63537
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c4a0
movq %r14, %rdi
callq 0x6427c
movl %eax, %r14d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%r12), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x5be39
movq %r12, %rdi
movl %r14d, %esi
callq 0x55ff9
cmpl $-0x1, %eax
je 0x5c49b
movslq %r14d, %r14
movq %r12, %rbp
movq (%r12), %r15
movq 0x8(%rsp), %rdi
callq 0x64277
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 0x5bb6e
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x6b241
movq %rax, %r12
cmpq %r14, %r12
je 0x5c451
jmp 0x5c49b
movb %bpl, 0x4(%rsi)
movb %al, 0x5(%rsi)
movq %r12, %rdi
callq 0x5b60d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c4a0
movl 0xc(%r12), %eax
jmp 0x5ba8f
cmpl $0x0, 0x38(%r14)
jle 0x5bad1
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %r12, 0x20(%rsp)
movl %ebp, 0x1c(%rsp)
movq 0x40(%r14), %rax
movq (%rax,%rbx), %rcx
movq %r14, %rdi
leaq 0x3d642(%rip), %rsi     # 0x9920f
leaq 0x3d63e(%rip), %rdx     # 0x99212
callq 0x62c06
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x5c4a0
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
leaq 0x3d61e(%rip), %rdx     # 0x99215
xorl %ecx, %ecx
callq 0x63344
testq %rax, %rax
jne 0x5bcd8
movq 0x48(%r12), %rax
testq %rax, %rax
je 0x5c49b
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x5c49b
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x5c49b
movq 0x10(%rax), %rbp
callq 0x6cbeb
testq %rax, %rax
je 0x5c49b
movq %rax, %r14
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x582ff
testq %rax, %rax
je 0x5c49b
movq 0x48(%r12), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movslq 0x10(%rcx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x6c1bd
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6cac4
movq %r14, %rdi
callq 0x6cc15
movq 0x48(%r12), %rdi
movl %r15d, %esi
callq 0x57ecf
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6cc1f
movq 0x8(%rsp), %rdi
movq %r13, %rsi
leaq 0x3d556(%rip), %rdx     # 0x99215
movq %r14, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x63388
testl %eax, %eax
movl 0x1c(%rsp), %ebp
jne 0x5c49b
movq 0x70(%r12), %r14
testq %r14, %r14
je 0x5bdd6
cmpb $0x2f, (%r14)
jne 0x5bd0e
movl $0x1000, %edx           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x6380
movb $0x0, 0x103f(%rsp)
jmp 0x5bda8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x6370
testq %rax, %rax
je 0x5bd64
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, 0x10(%rsp)
movq %r14, %rdi
callq 0x62d0
addq 0x10(%rsp), %rax
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x5bd7e
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r14, %rsi
callq 0x6380
movb $0x0, 0x103f(%rsp)
jmp 0x5bda4
sarq $0x20, %rbp
leaq (%rsp,%rbp), %rdi
addq $0x40, %rdi
movl $0x1000, %edx           # imm = 0x1000
subl 0x28(%rsp), %edx
leaq 0x3d799(%rip), %rsi     # 0x99533
movq %r14, %rcx
xorl %eax, %eax
callq 0x6170
movl 0x1c(%rsp), %ebp
movq 0x8(%rsp), %rdi
movq %r13, %rsi
leaq 0x345e7(%rip), %rdx     # 0x9039e
movq %r12, %rcx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x63388
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %r12
jne 0x5c4a0
incq %r15
movq 0x8(%rsp), %r14
movslq 0x38(%r14), %rax
addq $0x20, %rbx
cmpq %rax, %r15
jl 0x5bbbb
jmp 0x5bad1
movq $0x0, (%rsp)
leaq 0x3d403(%rip), %rsi     # 0x99206
leaq 0x3d3ff(%rip), %rdx     # 0x99209
leaq 0x3d3fb(%rip), %r8      # 0x9920c
leaq 0x3d3e6(%rip), %rcx     # 0x991fe
movq 0x8(%rsp), %rdi
movq %rcx, %r9
xorl %eax, %eax
callq 0x622a4
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x5c4a0
jmp 0x5bab5
movl $0x40, %edi
callq 0x69d0
movq %rax, %r15
testq %rax, %rax
je 0x5be6c
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%r15)
xorl %eax, %eax
movq %rax, 0x30(%r15)
movupd %xmm0, (%r15)
movq %rax, 0x10(%r15)
movl $0x7, 0x38(%r15)
xorl %edi, %edi
xorl %esi, %esi
callq 0x59467
movq %rax, %rbx
testq %r15, %r15
setne %al
testq %rbx, %rbx
setne %cl
testb %cl, %al
je 0x5c148
movl 0xc(%r12), %eax
movl %eax, 0x28(%rsp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x56096
movslq %r14d, %r13
movq 0x20(%r15), %r14
movq 0x28(%r15), %rax
movq 0x30(%r15), %rcx
leaq (%rcx,%r13), %rdx
cmpq %rdx, %rax
movq %rbx, 0x10(%rsp)
ja 0x5bf35
movl $0x400, %ebx            # imm = 0x400
movq %rax, %xmm0
punpckldq 0x30141(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x30149(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x349fd(%rip), %xmm1    # 0x908e8
cvttsd2si %xmm1, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd 0x3c2d1(%rip), %xmm1    # 0x981d0
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq %r14, %rdi
callq 0x6c80
movq %rax, %r14
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rax
movq 0x30(%r15), %rcx
leaq (%rcx,%r13), %rdx
cmpq %rdx, %rax
jbe 0x5bec2
addq %rcx, %r14
movq 0x8(%rsp), %rdi
callq 0x64277
movq %r14, %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
movq 0x10(%rsp), %rbx
jl 0x5bf88
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x56b63
cmpl $0x3, %ebp
jl 0x5c163
movq %r12, 0x20(%rsp)
movl 0xc(%r15), %r12d
movl $0x1, %eax
movl $0x1, %ebx
cmpl $0x80, %r12d
jb 0x5bfd8
movl $0x2, %ebx
cmpl $0x4000, %r12d          # imm = 0x4000
jb 0x5bfd8
movl $0x3, %ebx
cmpl $0x200000, %r12d        # imm = 0x200000
jb 0x5bfd8
cmpl $0x10000000, %r12d      # imm = 0x10000000
movl $0x5, %ebx
sbbl $0x0, %ebx
movl 0x10(%r15), %ecx
movl 0x14(%r15), %edx
cmpl $0x80, %edx
jb 0x5c010
movl $0x2, %eax
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5c010
movl $0x3, %eax
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5c010
cmpl $0x10000000, %edx       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movl $0x1, %edx
cmpl $0x80, %ecx
jb 0x5c045
movl $0x2, %edx
cmpl $0x4000, %ecx           # imm = 0x4000
jb 0x5c045
movl $0x3, %edx
cmpl $0x200000, %ecx         # imm = 0x200000
jb 0x5c045
cmpl $0x10000000, %ecx       # imm = 0x10000000
movl $0x5, %edx
sbbl $0x0, %edx
xorl %r13d, %r13d
cmpl $0x300, 0x28(%rsp)      # imm = 0x300
setge %r13b
leal (%rcx,%r13,4), %ecx
addl $0x2, %ecx
addl %eax, %ebx
addl %edx, %ebx
addl %ecx, %ebx
movq 0x10(%rsp), %r14
movl %ebx, (%r14)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0x24(%r14)
movl $0x8, %edi
callq 0x69d0
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x5c4b4
movl $0x0, (%rax)
movl %ebx, 0x4(%rax)
cvtsi2sd %ebx, %xmm0
mulsd 0x32dc5(%rip), %xmm0    # 0x8ee68
minsd 0x3cda5(%rip), %xmm0    # 0x98e50
cvttsd2si %xmm0, %r14d
movl $0x1, %eax
cmpl $0x80, %r12d
jb 0x5c0e9
movl $0x2, %eax
cmpl $0x4000, %r12d          # imm = 0x4000
jb 0x5c0e9
movl $0x3, %eax
cmpl $0x200000, %r12d        # imm = 0x200000
jb 0x5c0e9
cmpl $0x10000000, %r12d      # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
leal 0x2(,%r13,4), %ecx
movl $0x2, %edx
cmpl $0x80, %r14d
jb 0x5c12e
movl $0x4, %edx
cmpl $0x4000, %r14d          # imm = 0x4000
jb 0x5c12e
movl $0x6, %edx
cmpl $0x200000, %r14d        # imm = 0x200000
jb 0x5c12e
xorl %edx, %edx
cmpl $0x10000000, %r14d      # imm = 0x10000000
setae %dl
leal 0x8(,%rdx,2), %edx
addl %ebx, %ecx
addl %eax, %ecx
addl %edx, %ecx
addl %r14d, %ecx
movq 0x10(%rsp), %rbx
movl %ecx, (%rbx)
movq 0x20(%rsp), %r12
jmp 0x5c35b
testq %r15, %r15
je 0x5c155
movq %r15, %rdi
callq 0x56a50
testq %rbx, %rbx
jne 0x5c493
jmp 0x5c49b
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x24(%rbx)
movl $0x4, %edi
callq 0x69d0
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x5c49b
movl $0x0, (%rax)
xorps %xmm1, %xmm1
cvtsi2sdl (%rbx), %xmm1
movsd 0x3474b(%rip), %xmm0    # 0x908e8
mulsd %xmm1, %xmm0
maxsd 0x3cca7(%rip), %xmm0    # 0x98e50
movl 0xc(%r15), %edx
movl $0x1, %eax
movl $0x1, %ecx
cmpl $0x80, %edx
jb 0x5c1e7
movl $0x2, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5c1e7
movl $0x3, %ecx
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5c1e7
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 0x5c223
movl $0x2, %eax
cmpl $0x4000, %esi           # imm = 0x4000
jb 0x5c223
movl $0x3, %eax
cmpl $0x200000, %esi         # imm = 0x200000
jb 0x5c223
cmpl $0x10000000, %esi       # imm = 0x10000000
movl $0x5, %eax
sbbl $0x0, %eax
movq %r12, 0x20(%rsp)
cvttsd2si %xmm0, %r14d
movl $0x1, %esi
cmpl $0x80, %edx
jb 0x5c262
movl $0x2, %esi
cmpl $0x4000, %edx           # imm = 0x4000
jb 0x5c262
movl $0x3, %esi
cmpl $0x200000, %edx         # imm = 0x200000
jb 0x5c262
cmpl $0x10000000, %edx       # imm = 0x10000000
movl $0x5, %esi
sbbl $0x0, %esi
xorl %edi, %edi
cmpl $0x300, 0x28(%rsp)      # imm = 0x300
setge %dil
leal (%rdx,%rdi,4), %edx
addl %ecx, %edx
addl %eax, %edx
addl %r14d, %edx
leal (%rsi,%rdx), %eax
addl $0x2, %eax
movl %eax, (%rbx)
movslq %r14d, %r12
movl $0x1, %edi
movq %r12, %rsi
callq 0x6470
testq %rax, %rax
je 0x5c48b
movq %rax, %r13
movq 0x20(%r15), %rax
movq 0x28(%r15), %rcx
movq 0x30(%r15), %rdx
leaq (%rdx,%r12), %rsi
cmpq %rsi, %rcx
ja 0x5c328
movl $0x400, %ebx            # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x2fd4b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2fd53(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x34607(%rip), %xmm1    # 0x908e8
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x3bedb(%rip), %xmm1    # 0x981d0
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq %rax, %rdi
callq 0x6c80
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rcx
movq 0x30(%r15), %rdx
leaq (%rdx,%r12), %rsi
cmpq %rsi, %rcx
jbe 0x5c2b8
addq %rdx, %rax
movq %rax, %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), %r12
movq 0x10(%rsp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5a5ef
cmpl $-0x1, %eax
je 0x5c48b
movq %r12, %rdi
movq %r15, %rsi
callq 0x56662
cmpl $-0x1, %eax
je 0x5c48b
cmpl $0x3, %ebp
jl 0x5c43e
movslq %r14d, %r14
movq 0x20(%r15), %rax
movq 0x28(%r15), %rcx
cmpq %r14, %rcx
ja 0x5c409
movl $0x400, %ebx            # imm = 0x400
movq %rcx, %xmm0
punpckldq 0x2fc62(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2fc6a(%rip), %xmm0    # 0x8c020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x3451e(%rip), %xmm1    # 0x908e8
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0x3bdf2(%rip), %xmm1    # 0x981d0
cvttsd2si %xmm1, %rsi
andq %rdi, %rsi
orq %rdx, %rsi
testq %rcx, %rcx
cmoveq %rbx, %rsi
movq %rsi, 0x28(%r15)
movq %rax, %rdi
callq 0x6c80
movq %rax, 0x20(%r15)
movq 0x28(%r15), %rcx
cmpq %r14, %rcx
jbe 0x5c3a1
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x63b0
movq %r14, 0x30(%r15)
movl %r14d, 0x14(%r15)
movl %r14d, 0x10(%r15)
movl $0x0, (%r15)
movq %r12, %rdi
movq %r15, %rsi
callq 0x56662
cmpl $-0x1, %eax
movq 0x10(%rsp), %rbx
je 0x5c48b
movq %r12, %rbp
movq %r15, %rdi
callq 0x56a50
movq %rbx, %rdi
callq 0x59605
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x57a34
cmpl $-0x1, %eax
je 0x5c49b
movq 0x18(%rbp), %rsi
movq 0x48(%rbp), %rdi
callq 0x57823
cmpl $-0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
je 0x5c4a0
movq (%rbp), %rdi
callq 0x6b16c
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
jmp 0x5c4a0
movq %r15, %rdi
callq 0x56a50
movq %rbx, %rdi
callq 0x59605
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
movq %r15, %rdi
callq 0x56a50
movq %r14, %rdi
jmp 0x5c496