// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_io.c
// Function: cram_write_SAM_hdr
int cram_write_SAM_hdr(cram_fd *fd, sam_hdr_t *hdr) {
    size_t 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_hrecs_find_rg(hdr->hrecs, "UNKNOWN"))
            if (sam_hdr_add_line(hdr, "RG",
                            "ID", "UNKNOWN", "SM", "UNKNOWN", NULL))
                return -1;
    }

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

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

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

            if (!sam_hrecs_find_key(ty, "M5", NULL)) {
                char unsigned buf[16];
                char buf2[33];
                hts_pos_t 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;
                ref = cram_get_ref(fd, i, 1, rlen);
                if (NULL == ref) {
                    if (fd->embed_ref == -1) {
                        // auto embed-ref
                        hts_log_warning("No M5 tags present and could not "
                                        "find reference");
                        hts_log_warning("Enabling embed_ref=2 option");
                        hts_log_warning("NOTE: the CRAM file will be bigger "
                                        "than using an external reference");
                        pthread_mutex_lock(&fd->ref_lock);
                        // Best guess.  It may be unmapped data with broken
                        // headers, in which case this will get ignored.
                        fd->embed_ref = 2;
                        pthread_mutex_unlock(&fd->ref_lock);
                        break;
                    }
                    return -1;
                }
                rlen = fd->refs->ref_id[i]->length; /* In case it just loaded */
                if (!(md5 = hts_md5_init()))
                    return -1;
                if (HTS_POS_MAX <= ULONG_MAX) {
                    // Platforms with 64-bit unsigned long update in one go
                    hts_md5_update(md5, ref, rlen);
                } else {
                    // Those with 32-bit ulong (Windows) may have to loop
                    // over epic references
                    hts_pos_t pos = 0;
                    while (rlen - pos > ULONG_MAX) {
                        hts_md5_update(md5, ref + pos, ULONG_MAX);
                        pos += ULONG_MAX;
                    }
                    hts_md5_update(md5, ref + pos, (unsigned long)(rlen - pos));
                }
                hts_md5_final(buf, md5);
                hts_md5_destroy(md5);
                cram_ref_decr(fd->refs, i);

                hts_md5_hex(buf2, buf);
                fd->refs->ref_id[i]->validated_md5 = 1;
                if (sam_hdr_update_line(hdr, "SQ", "SN", hdr->hrecs->ref[i].name, "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_line(hdr, "SQ", "SN", hdr->hrecs->ref[i].name, "UR", ref_fn, NULL))
                    return -1;
            }
        }
    }

    /* Length */
    header_len = sam_hdr_length(hdr);
    if (header_len > INT32_MAX) {
        hts_log_error("Header is too long for CRAM format");
        return -1;
    }
    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;
        }

        if (int32_put_blk(b, header_len) < 0)
            return -1;
        if (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)
            if (cram_compress_block(fd, b, NULL, -1, -1) < 0)
                return -1;

        if (blank_block) {
            c->length = b->comp_size + 2 + 4*is_cram_3 +
                fd->vv.varint_size(b->content_id)   +
                fd->vv.varint_size(b->uncomp_size)  +
                fd->vv.varint_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 +
                fd->vv.varint_size(b->content_id) +
                fd->vv.varint_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 +
                fd->vv.varint_size(b->content_id)   +
                fd->vv.varint_size(b->uncomp_size)  +
                fd->vv.varint_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 (0 != hflush(fd->fp))
        return -1;

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

    return 0;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1058, %rsp           # imm = 0x1058
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc(%rdi), %eax
movl %eax, %r12d
sarl $0x8, %r12d
movq 0x10(%rdi), %rsi
cmpb $0x0, 0x4(%rsi)
je 0x54c5d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%rbx), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x54830
movq 0x38(%r14), %rdi
leaq 0x47a0f(%rip), %rsi     # 0x9c231
callq 0x8c9eb
testq %rax, %rax
je 0x54c7a
movq %rbx, %rdi
callq 0x50b2f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x54cee
movq 0x18(%rbx), %rsi
movq 0x50(%rbx), %rdi
callq 0x50914
cmpl $-0x1, %eax
je 0x54ce9
cmpq $0x0, 0x50(%rbx)
je 0x54cbf
cmpl $0x0, 0x224(%rbx)
jne 0x54cbf
cmpl $0x1, 0x220(%rbx)
jg 0x54cbf
movq 0x38(%r14), %rdi
cmpl $0x0, 0x28(%rdi)
jle 0x54cbf
leaq 0x88f0(%rbx), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
xorl %ecx, %ecx
movq %r14, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x30(%rdi), %rax
movq (%rax,%r13), %rcx
leaq 0x46902(%rip), %rsi     # 0x9b1bb
leaq 0x47ac9(%rip), %rdx     # 0x9c389
callq 0x881f0
movl $0x1, %r15d
testq %rax, %rax
je 0x54b9a
movq %rax, %rdi
leaq 0x47aae(%rip), %rsi     # 0x9c38c
xorl %edx, %edx
callq 0x89a0b
testq %rax, %rax
jne 0x54a28
movq 0x50(%rbx), %rax
movl $0x1, %r15d
testq %rax, %rax
je 0x54a1e
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x54a1e
movq 0x10(%rsp), %rsi
movq (%rax,%rsi,8), %rax
testq %rax, %rax
je 0x54a1e
movq 0x10(%rax), %rcx
movl $0x1, %edx
movq %rbx, %rdi
callq 0x513e3
testq %rax, %rax
je 0x54a11
movq %rax, 0x20(%rsp)
movq 0x50(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movq %rax, 0x30(%rsp)
callq 0x8e160
testq %rax, %rax
je 0x54a1e
movq %rax, %rdi
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x8d72b
leaq 0x40(%rsp), %rdi
movq 0x28(%rsp), %r15
movq %r15, %rsi
callq 0x8e039
movq %r15, %rdi
callq 0x8e188
movq 0x50(%rbx), %rdi
movq 0x10(%rsp), %r15
movl %r15d, %esi
callq 0x50ecf
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8e192
movq 0x50(%rbx), %rax
movq 0x10(%rax), %rax
movq (%rax,%r15,8), %rax
movl $0x1, 0x4c(%rax)
movq 0x38(%r14), %rax
movq 0x30(%rax), %rax
movq (%rax,%r13), %rcx
movq $0x0, (%rsp)
movq %r14, %rdi
leaq 0x467d2(%rip), %rsi     # 0x9b1bb
leaq 0x47999(%rip), %rdx     # 0x9c389
leaq 0x47995(%rip), %r8      # 0x9c38c
leaq 0x50(%rsp), %r9
xorl %eax, %eax
callq 0x8903d
xorl %r15d, %r15d
testl %eax, %eax
sete %al
setne %r15b
jmp 0x54a20
cmpl $-0x1, 0x220(%rbx)
je 0x54be8
xorl %eax, %eax
testb %al, %al
je 0x54b9a
movq 0x80(%rbx), %r15
testq %r15, %r15
je 0x54b97
movq %r15, %rdi
callq 0x41d0
movq %rax, %r14
movq %r15, %rdi
callq 0x103cd
testl %eax, %eax
je 0x54a81
cmpq $0x1001, %r14           # imm = 0x1001
jb 0x54aa7
movl $0x1, %edi
leaq 0x49bd2(%rip), %rsi     # 0x9e636
leaq 0x49bd5(%rip), %rdx     # 0x9e640
movl $0x1000, %ecx           # imm = 0x1000
xorl %eax, %eax
callq 0x14378
leaq 0x50(%rsp), %r15
jmp 0x54b52
movq %r15, 0x20(%rsp)
movzbl (%r15), %r15d
cmpq $0x2f, %r15
jne 0x54abc
movl $0xfff, %edx            # imm = 0xFFF
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq 0x20(%rsp), %rsi
jmp 0x54b45
movl $0xfff, %edx            # imm = 0xFFF
movq %r15, %rsi
leaq 0x50(%rsp), %r15
movq %r15, %rdi
jmp 0x54b45
cmpq $0x4, %r14
jb 0x54af2
callq 0x40a0
movq (%rax), %rax
movb (%rax,%r15,4), %al
addb $-0x41, %al
cmpb $0x19, %al
ja 0x54af2
movq 0x20(%rsp), %rax
cmpb $0x3a, 0x1(%rax)
jne 0x54af2
movq 0x20(%rsp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x5c, %eax
je 0x54a90
cmpl $0x2f, %eax
je 0x54a90
movl $0x1000, %esi           # imm = 0x1000
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x4240
testq %rax, %rax
movq 0x20(%rsp), %rcx
je 0x54b3a
movq %r15, %rdi
callq 0x41d0
movq %rax, %r14
movq 0x20(%rsp), %rdi
callq 0x41d0
movq 0x20(%rsp), %rcx
addq %r14, %rax
incq %rax
cmpq $0x1000, %rax           # imm = 0x1000
jb 0x54bc5
movl $0xfff, %edx            # imm = 0xFFF
movq %r15, %rdi
movq %rcx, %rsi
callq 0x4250
movb $0x0, 0x104f(%rsp)
movq 0x18(%rsp), %r14
movq 0x38(%r14), %rax
movq 0x30(%rax), %rax
movq (%rax,%r13), %rcx
movq $0x0, (%rsp)
movq %r14, %rdi
leaq 0x46646(%rip), %rsi     # 0x9b1bb
leaq 0x4780d(%rip), %rdx     # 0x9c389
leaq 0x49556(%rip), %r8      # 0x9e0d9
movq %r15, %r9
xorl %eax, %eax
callq 0x8903d
movl $0x1, %r15d
testl %eax, %eax
jne 0x54b9a
xorl %r15d, %r15d
testl %r15d, %r15d
jne 0x54cb9
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x38(%r14), %rdi
movslq 0x28(%rdi), %rax
addq $0x18, %r13
cmpq %rax, %rcx
jl 0x548a5
jmp 0x54cbf
leaq (%rsp,%r14), %rdi
addq $0x50, %rdi
movl $0x1000, %esi           # imm = 0x1000
subq %r14, %rsi
leaq 0x4ef59(%rip), %rdx     # 0xa3b35
xorl %eax, %eax
callq 0x4800
jmp 0x54b52
movl $0x3, %edi
leaq 0x49486(%rip), %r15     # 0x9e07a
movq %r15, %rsi
leaq 0x4948f(%rip), %rdx     # 0x9e08d
xorl %eax, %eax
callq 0x14378
movl $0x3, %edi
movq %r15, %rsi
leaq 0x494a9(%rip), %rdx     # 0x9e0bd
xorl %eax, %eax
callq 0x14378
movl $0x3, %edi
movq %r15, %rsi
leaq 0x47e99(%rip), %rdx     # 0x9cac3
xorl %eax, %eax
callq 0x14378
movq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x4750
movl $0x2, 0x220(%rbx)
movq %r15, %rdi
callq 0x4340
xorl %eax, %eax
movl $0x2, %r15d
jmp 0x54a20
movb %r12b, 0x4(%rsi)
movb %al, 0x5(%rsi)
movq %rbx, %rdi
callq 0x54389
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x54cee
jmp 0x54808
movq $0x0, (%rsp)
leaq 0x4645c(%rip), %rsi     # 0x9b0e5
leaq 0x46458(%rip), %rdx     # 0x9b0e8
leaq 0x474b0(%rip), %r8      # 0x9c147
leaq 0x47593(%rip), %rcx     # 0x9c231
movq %r14, %rdi
movq %rcx, %r9
xorl %eax, %eax
callq 0x87a2f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x54cee
jmp 0x54830
cmpl $0x2, %r15d
jne 0x54ce9
movq %r14, %rdi
callq 0x8730b
testq $-0x80000000, %rax      # imm = 0x80000000
je 0x54d02
leaq 0x493a4(%rip), %rsi     # 0x9e07a
leaq 0x493ff(%rip), %rdx     # 0x9e0dc
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r13
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0xc(%rbx), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x54daf
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4f773
cmpl $-0x1, %eax
je 0x54cee
movq (%rbx), %r15
movq %r14, %rdi
callq 0x87472
movq %rax, %r14
testb $0x2, 0x30(%r15)
jne 0x54d63
movq 0x18(%r15), %rsi
movq %rsi, %rax
subq 0x8(%r15), %rax
cmpq %r13, %rax
jae 0x54d63
addq %r13, %rsi
subq (%r15), %rsi
movq %r15, %rdi
callq 0xefdd
movq 0x18(%r15), %rax
movq %rax, 0x10(%r15)
movq 0x8(%r15), %rdi
movq 0x18(%r15), %rbp
subq %rdi, %rbp
cmpq %r13, %rbp
ja 0x54d7c
cmpq (%r15), %rdi
je 0x54f61
cmpq %r13, %rbp
movq %r13, %r12
cmovbq %rbp, %r12
movq %r14, %rsi
movq %r12, %rdx
callq 0x43c0
addq %r12, 0x8(%r15)
cmpq %r13, %rbp
jae 0x54f74
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
jmp 0x54f6c
xorl %edi, %edi
xorl %esi, %esi
callq 0x4ee42
movq %rax, %r15
xorl %edi, %edi
xorl %esi, %esi
callq 0x5278c
movq %rax, %rbp
testq %r15, %r15
setne %al
testq %rbp, %rbp
setne %cl
testb %cl, %al
je 0x54f46
movl 0xc(%rbx), %eax
movl %eax, 0x10(%rsp)
movq %r15, %rdi
movl %r13d, %esi
callq 0x4eb9f
testl %eax, %eax
js 0x54ce9
testq %r13, %r13
je 0x54e18
movq %r14, %rdi
callq 0x87472
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x4e873
testl %eax, %eax
js 0x54ce9
movq %rbp, 0x18(%rsp)
movl 0x30(%r15), %eax
movl %eax, 0x14(%r15)
movl %eax, 0x10(%r15)
cmpl $0x300, 0xc(%rbx)       # imm = 0x300
jl 0x54e61
movl $0x0, (%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x4fca8
testl %eax, %eax
js 0x54cee
cmpl $0x3, %r12d
jl 0x54f95
xorl %r13d, %r13d
cmpl $0x300, 0x10(%rsp)      # imm = 0x300
setge %r13b
shll $0x2, %r13d
movslq 0xc(%r15), %rdi
movl 0x10(%r15), %ebp
addl %r13d, %ebp
callq *0x8a08(%rbx)
movl %eax, 0x10(%rsp)
movslq 0x14(%r15), %rdi
callq *0x8a08(%rbx)
movl %eax, %r14d
movslq 0x10(%r15), %rdi
callq *0x8a08(%rbx)
addl 0x10(%rsp), %r14d
addl %ebp, %r14d
addl %eax, %r14d
addl $0x2, %r14d
movq 0x18(%rsp), %rbp
movl %r14d, (%rbp)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0x2c(%rbp)
movl $0x8, %edi
callq 0x4680
movq %rax, 0x38(%rbp)
testq %rax, %rax
je 0x5510d
movl $0x0, (%rax)
cvtsi2sd %r14d, %xmm0
mulsd 0x41126(%rip), %xmm0    # 0x96020
minsd 0x429ae(%rip), %xmm0    # 0x978b0
movl %r14d, 0x4(%rax)
cvttsd2si %xmm0, %r14d
movslq 0xc(%r15), %rdi
callq *0x8a08(%rbx)
movl %eax, 0x20(%rsp)
movl %r14d, 0x10(%rsp)
movslq %r14d, %r14
movq %r14, %rdi
callq *0x8a08(%rbx)
movl (%rbp), %ecx
addl 0x20(%rsp), %r13d
addl %r13d, %r14d
leal (%r14,%rax,2), %eax
addl %ecx, %eax
addl $0x2, %eax
movl %eax, (%rbp)
jmp 0x55089
testq %r15, %r15
je 0x54f53
movq %r15, %rdi
callq 0x4f82d
testq %rbp, %rbp
jne 0x55115
jmp 0x54ce9
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xf4c6
movq %rax, %r12
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %r12, %r13
jne 0x54cee
movq (%rbx), %rdi
callq 0xf3e7
xorl %ebp, %ebp
negl %eax
sbbl %ebp, %ebp
jmp 0x54cee
movabsq $0x100000001, %rax      # imm = 0x100000001
movq 0x18(%rsp), %r14
movq %rax, 0x2c(%r14)
movl $0x4, %edi
callq 0x4680
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x54ce9
xorl %r13d, %r13d
cmpl $0x300, 0x10(%rsp)      # imm = 0x300
setge %r13b
cvtsi2sdl (%r14), %xmm0
movsd 0x475f5(%rip), %xmm1    # 0x9c5d0
mulsd %xmm0, %xmm1
maxsd 0x428c9(%rip), %xmm1    # 0x978b0
movl $0x0, (%rax)
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %ebp
movslq 0xc(%r15), %rdi
shll $0x2, %r13d
addl 0x10(%r15), %r13d
callq *0x8a08(%rbx)
movl %eax, %r14d
movslq 0x14(%r15), %rdi
callq *0x8a08(%rbx)
movl %eax, 0x10(%rsp)
movslq 0x10(%r15), %rdi
callq *0x8a08(%rbx)
addl %r13d, %r14d
addl 0x10(%rsp), %r14d
addl %ebp, %r14d
addl %r14d, %eax
addl $0x2, %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl %ebp, 0x10(%rsp)
movslq %ebp, %r13
movl $0x1, %edi
movq %r13, %rsi
callq 0x4300
testq %rax, %rax
je 0x55122
movq %rax, %r14
movq 0x18(%rsp), %rbp
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x4e873
testl %eax, %eax
js 0x54ce9
movl 0x30(%r15), %eax
movl %eax, 0x14(%r15)
movl %eax, 0x10(%r15)
movq %r14, %rdi
callq 0x45c0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x53556
cmpl $-0x1, %eax
je 0x5510d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f35f
cmpl $-0x1, %eax
je 0x5510d
cmpl $0x3, %r12d
jl 0x550f8
movslq 0x10(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x55131
testl %eax, %eax
js 0x54ce9
movq 0x20(%r15), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x4260
movq %r14, 0x30(%r15)
movl %r14d, 0x14(%r15)
movl %r14d, 0x10(%r15)
movl $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f35f
cmpl $-0x1, %eax
je 0x5510d
movq %r15, %rdi
callq 0x4f82d
movq %rbp, %rdi
callq 0x5295e
jmp 0x54f82
movq %r15, %rdi
callq 0x4f82d
movq %rbp, %rdi
callq 0x5295e
jmp 0x54ce9
movq %r15, %rdi
callq 0x4f82d
movq 0x18(%rsp), %rdi
jmp 0x55118