LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_gamma_decode_init
cram_codec *cram_gamma_decode_init(char *data, int size,
				   enum cram_external_type option,
				   int version) {
    cram_codec *c;
    char *cp = data;

    if (!(c = malloc(sizeof(*c))))
	return NULL;

    c->codec  = E_GAMMA;
    c->decode = cram_gamma_decode;
    c->free   = cram_gamma_decode_free;
    
    cp += itf8_get(cp, &c->gamma.offset);

    if (cp - data != size) {
	fprintf(stderr, "Malformed gamma header stream\n");
	free(c);
	return NULL;
    }

    return c;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %r14
movl $0x240, %edi            # imm = 0x240
callq 0x46f0
testq %rax, %rax
je 0x3d1bc
movq %rax, %rbx
movl $0x9, (%rax)
leaq -0x139(%rip), %rax      # 0x3cfbd
movq %rax, 0x18(%rbx)
leaq -0x3c(%rip), %rax       # 0x3d0c5
movq %rax, 0x10(%rbx)
movzbl (%r14), %eax
testb %al, %al
js 0x3d111
pushq $0x1
jmp 0x3d18c
movzbl 0x1(%r14), %ecx
cmpb $-0x41, %al
ja 0x3d126
andl $0x3f, %eax
shll $0x8, %eax
orl %ecx, %eax
pushq $0x2
jmp 0x3d18c
cmpb $-0x21, %al
ja 0x3d140
shll $0x8, %ecx
movzbl 0x2(%r14), %edx
andl $0x1f, %eax
shll $0x10, %eax
orl %ecx, %eax
orl %edx, %eax
pushq $0x3
jmp 0x3d18c
cmpb $-0x11, %al
ja 0x3d164
shll $0x10, %ecx
movzbl 0x2(%r14), %edx
shll $0x8, %edx
movzbl 0x3(%r14), %esi
andl $0xf, %eax
shll $0x18, %eax
orl %ecx, %eax
orl %edx, %eax
orl %esi, %eax
pushq $0x4
jmp 0x3d18c
shll $0x1c, %eax
shll $0x14, %ecx
orl %eax, %ecx
movzbl 0x2(%r14), %eax
shll $0xc, %eax
orl %ecx, %eax
movzbl 0x3(%r14), %ecx
shll $0x4, %ecx
orl %eax, %ecx
movzbl 0x4(%r14), %eax
andl $0xf, %eax
orl %ecx, %eax
pushq $0x5
popq %rcx
movl %eax, 0x30(%rbx)
movslq %ebp, %rax
cmpq %rax, %rcx
je 0x3d1be
movq 0x19e31(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0xa4bb(%rip), %rdi      # 0x47664
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
movq %rbx, %rdi
callq 0x4600
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_free
void cram_huffman_decode_free(cram_codec *c) {
    if (!c)
	return;

    if (c->huffman.codes)
	free(c->huffman.codes);
    free(c);
}

// Assembly:
testq %rdi, %rdi
je 0x3d1e1
pushq %rbx
movq %rdi, %rbx
movq 0x38(%rdi), %rdi
callq 0x4600
movq %rbx, %rdi
popq %rbx
jmp 0x4600
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_char0
int cram_huffman_decode_char0(cram_slice *slice, cram_codec *c,
			      cram_block *in, char *out, int *out_size) {
    int i, n;

    if (!out)
	return 0;

    /* Special case of 0 length codes */
    for (i = 0, n = *out_size; i < n; i++) {
	out[i] = c->huffman.codes[0].symbol;
    }
    return 0;
}

// Assembly:
testq %rcx, %rcx
je 0x3d20a
movl (%r8), %eax
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
cmpq %rdx, %rax
je 0x3d20a
movq 0x38(%rsi), %rdi
movb (%rdi), %dil
movb %dil, (%rcx,%rdx)
incq %rdx
jmp 0x3d1f5
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_char
int cram_huffman_decode_char(cram_slice *slice, cram_codec *c,
			     cram_block *in, char *out, int *out_size) {
    int i, n, ncodes = c->huffman.ncodes;
    const cram_huffman_code * const codes = c->huffman.codes;

    for (i = 0, n = *out_size; i < n; i++) {
	int idx = 0;
	int val = 0, len = 0, last_len = 0;

	for (;;) {
	    int dlen = codes[idx].len - last_len;
	    if (cram_not_enough_bits(in, dlen))
		return -1;

	    //val <<= dlen;
	    //val  |= get_bits_MSB(in, dlen);
	    //last_len = (len += dlen);

	    last_len = (len += dlen);
	    for (; dlen; dlen--) GET_BIT_MSB(in, val);

	    idx = val - codes[idx].p;
	    if (idx >= ncodes || idx < 0)
		return -1;

	    if (codes[idx].code == val && codes[idx].len == len) {
		out[i] = codes[idx].symbol;
		break;
	    }
	}
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movl 0x30(%rsi), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsi), %r12
movl (%r8), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
xorl %eax, %eax
movq %rcx, 0x10(%rsp)
cmpq %rcx, %rax
je 0x3d31b
movq %rax, 0x20(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
movl %eax, %ebp
shlq $0x4, %rbp
movl 0xc(%r12,%rbp), %r13d
movl %r13d, %esi
subl %ebx, %esi
movq %r15, %rdi
callq 0x3c3b2
testl %eax, %eax
jne 0x3d309
addq %r12, %rbp
cmpl %ebx, %r13d
je 0x3d2b6
movq 0x20(%r15), %rax
movq 0x30(%r15), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%r15), %edx
xorl %esi, %esi
btl %edx, %eax
setb %sil
leal (%rsi,%r14,2), %r14d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%r15)
andl $0x7, %eax
movl %eax, 0x38(%r15)
incl %ebx
jmp 0x3d277
movl %r14d, %eax
subl 0x4(%rbp), %eax
cmpl 0xc(%rsp), %eax
jge 0x3d309
testl %eax, %eax
js 0x3d309
movl %eax, %ecx
shlq $0x4, %rcx
movl %r13d, %ebx
cmpl %r14d, 0x8(%r12,%rcx)
jne 0x3d254
addq %r12, %rcx
movl %r13d, %ebx
cmpl %r13d, 0xc(%rcx)
jne 0x3d254
movb (%rcx), %al
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movb %al, (%rcx,%rdx)
movq %rdx, %rax
incq %rax
movq 0x10(%rsp), %rcx
jmp 0x3d23f
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x3d30c
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_int0
int cram_huffman_decode_int0(cram_slice *slice, cram_codec *c,
			     cram_block *in, char *out, int *out_size) {
    int32_t *out_i = (int32_t *)out;
    int i, n;
    const cram_huffman_code * const codes = c->huffman.codes;

    /* Special case of 0 length codes */
    for (i = 0, n = *out_size; i < n; i++) {
	out_i[i] = codes[0].symbol;
    }
    return 0;
}

// Assembly:
movq 0x38(%rsi), %rax
movl (%r8), %edx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
cmpq %rsi, %rdx
je 0x3d33c
movl (%rax), %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
jmp 0x3d32d
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_decode_int
int cram_huffman_decode_int(cram_slice *slice, cram_codec *c,
			    cram_block *in, char *out, int *out_size) {
    int32_t *out_i = (int32_t *)out;
    int i, n, ncodes = c->huffman.ncodes;
    const cram_huffman_code * const codes = c->huffman.codes;

    for (i = 0, n = *out_size; i < n; i++) {
	int idx = 0;
	int val = 0, len = 0, last_len = 0;

	// Now one bit at a time for remaining checks
	for (;;) {
	    int dlen = codes[idx].len - last_len;
	    if (cram_not_enough_bits(in, dlen))
		return -1;
	    
	    //val <<= dlen;
	    //val  |= get_bits_MSB(in, dlen);
	    //last_len = (len += dlen);

	    last_len = (len += dlen);
	    for (; dlen; dlen--) GET_BIT_MSB(in, val);

	    idx = val - codes[idx].p;
	    if (idx >= ncodes || idx < 0)
		return -1;

	    if (codes[idx].code == val && codes[idx].len == len) {
		out_i[i] = codes[idx].symbol;
		break;
	    }
	}
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movl 0x30(%rsi), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rsi), %r12
movl (%r8), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
xorl %eax, %eax
movq %rcx, 0x10(%rsp)
cmpq %rcx, %rax
je 0x3d44d
movq %rax, 0x20(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
movl %eax, %ebp
shlq $0x4, %rbp
movl 0xc(%r12,%rbp), %r13d
movl %r13d, %esi
subl %ebx, %esi
movq %r15, %rdi
callq 0x3c3b2
testl %eax, %eax
jne 0x3d43b
addq %r12, %rbp
cmpl %ebx, %r13d
je 0x3d3e8
movq 0x20(%r15), %rax
movq 0x30(%r15), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%r15), %edx
xorl %esi, %esi
btl %edx, %eax
setb %sil
leal (%rsi,%r14,2), %r14d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%r15)
andl $0x7, %eax
movl %eax, 0x38(%r15)
incl %ebx
jmp 0x3d3a9
movl %r14d, %eax
subl 0x4(%rbp), %eax
cmpl 0xc(%rsp), %eax
jge 0x3d43b
testl %eax, %eax
js 0x3d43b
movl %eax, %ecx
shlq $0x4, %rcx
movl %r13d, %ebx
cmpl %r14d, 0x8(%r12,%rcx)
jne 0x3d386
addq %r12, %rcx
movl %r13d, %ebx
cmpl %r13d, 0xc(%rcx)
jne 0x3d386
movl (%rcx), %eax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
movq %rdx, %rax
incq %rax
movq 0x10(%rsp), %rcx
jmp 0x3d371
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x3d43e
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_encode_char
int cram_huffman_encode_char(cram_slice *slice, cram_codec *c,
			     char *in, int in_size) {
    int i, code, len, r = 0;
    unsigned char *syms = (unsigned char *)in;

    while (in_size--) {
	int sym = *syms++;
	if (sym >= -1 && sym < MAX_HUFF) {
	    i = c->e_huffman.val2code[sym+1];
	    assert(c->e_huffman.codes[i].symbol == sym);
	    code = c->e_huffman.codes[i].code;
	    len  = c->e_huffman.codes[i].len;
	} else {
	    /* Slow - use a lookup table for when sym < MAX_HUFF? */
	    for (i = 0; i < c->e_huffman.nvals; i++) {
		if (c->e_huffman.codes[i].symbol == sym)
		    break;
	    }
	    if (i == c->e_huffman.nvals)
		return -1;
    
	    code = c->e_huffman.codes[i].code;
	    len  = c->e_huffman.codes[i].len;
	}

	r |= store_bits_MSB(c->out, code, len);
    }

    return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
xorl %ebx, %ebx
pushq $-0x1
popq %r12
subl $0x1, %ebp
jb 0x3d793
movzbl (%r14), %eax
testb %al, %al
js 0x3d740
movslq 0x40(%r15,%rax,4), %rdx
movq 0x30(%r15), %rcx
shlq $0x4, %rdx
cmpl %eax, (%rcx,%rdx)
jne 0x3d79e
addq %rdx, %rcx
jmp 0x3d77a
movl 0x38(%r15), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
xorl %edi, %edi
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x3d76c
movq 0x30(%r15), %r8
cmpl %eax, (%r8,%rdi)
je 0x3d76a
incq %rsi
addq $0x10, %rdi
jmp 0x3d752
movl %esi, %edx
cmpl %ecx, %edx
je 0x3d790
movl %edx, %ecx
shlq $0x4, %rcx
addq 0x30(%r15), %rcx
incq %r14
movl 0x8(%rcx), %esi
movl 0xc(%rcx), %edx
movq 0x8(%r15), %rdi
callq 0x3ca9c
orl %eax, %ebx
jmp 0x3d71c
movl %r12d, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9eff(%rip), %rdi      # 0x476a4
leaq 0x9e2f(%rip), %rsi      # 0x475db
leaq 0x9f15(%rip), %rcx      # 0x476c8
movl $0x429, %edx            # imm = 0x429
callq 0x4360
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_huffman_encode_free
void cram_huffman_encode_free(cram_codec *c) {
    if (!c)
	return;

    if (c->e_huffman.codes)
	free(c->e_huffman.codes);
    free(c);
}

// Assembly:
testq %rdi, %rdi
je 0x3d89b
pushq %rbx
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
callq 0x4600
movq %rbx, %rdi
popq %rbx
jmp 0x4600
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_len_decode
int cram_byte_array_len_decode(cram_slice *slice, cram_codec *c,
			       cram_block *in, char *out,
			       int *out_size) {
    /* Fetch length */
    int32_t len = 0, one = 1;
    int r;

    r = c->byte_array_len.len_codec->decode(slice, c->byte_array_len.len_codec,
                                            in, (char *)&len, &one);
    //printf("ByteArray Len=%d\n", len);

    if (!r && c->byte_array_len.val_codec && len >= 0) {
	r = c->byte_array_len.val_codec->decode(slice,
						c->byte_array_len.val_codec,
						in, out, &len);
    } else {
	return -1;
    }

    *out_size = len;

    return r;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r13
leaq 0x8(%rsp), %rcx
andl $0x0, (%rcx)
movq %rdi, %r12
leaq 0xc(%rsp), %r8
movl $0x1, (%r8)
movq 0x30(%rsi), %rsi
callq *0x18(%rsi)
movl %eax, %ecx
pushq $-0x1
popq %rax
testl %ecx, %ecx
jne 0x3e286
movq 0x38(%r13), %rsi
testq %rsi, %rsi
je 0x3e286
cmpl $0x0, 0x8(%rsp)
js 0x3e286
leaq 0x8(%rsp), %r13
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
movq %r13, %r8
callq *0x18(%rsi)
movl (%r13), %ecx
movl %ecx, (%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_len_decode_free
void cram_byte_array_len_decode_free(cram_codec *c) {
    if (!c) return;

    if (c->byte_array_len.len_codec)
	c->byte_array_len.len_codec->free(c->byte_array_len.len_codec);

    if (c->byte_array_len.val_codec)
	c->byte_array_len.val_codec->free(c->byte_array_len.val_codec);

    free(c);
}

// Assembly:
testq %rdi, %rdi
je 0x3e2be
pushq %rbx
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
testq %rdi, %rdi
je 0x3e2a9
callq *0x10(%rdi)
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x3e2b5
callq *0x10(%rdi)
movq %rbx, %rdi
popq %rbx
jmp 0x4600
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_decoder_init
cram_codec *cram_decoder_init(enum cram_encoding codec,
			      char *data, int size,
			      enum cram_external_type option,
			      int version) {
    if (codec >= E_NULL && codec < E_NUM_CODECS && decode_init[codec]) {
	return decode_init[codec](data, size, option, version);
    } else {
	fprintf(stderr, "Unimplemented codec of type %s\n", cram_encoding2str(codec));
	return NULL;
    }
}

// Assembly:
cmpl $0x9, %edi
ja 0x3e460
movl $0x105, %eax            # imm = 0x105
btq %rdi, %rax
jb 0x3e460
movl %edi, %eax
leaq 0x1888e(%rip), %r9      # 0x56ce0
movq %rsi, %rdi
movl %edx, %esi
movl %ecx, %edx
movl %r8d, %ecx
jmpq *(%r9,%rax,8)
pushq %rbx
movq 0x18b68(%rip), %rax     # 0x56fd0
movq (%rax), %rbx
callq 0x3f109
leaq 0x9435(%rip), %rsi      # 0x478ac
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4770
xorl %eax, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_len_encode_free
void cram_byte_array_len_encode_free(cram_codec *c) {
    if (!c)
	return;

    if (c->e_byte_array_len.len_codec)
	c->e_byte_array_len.len_codec->free(c->e_byte_array_len.len_codec);

    if (c->e_byte_array_len.val_codec)
	c->e_byte_array_len.val_codec->free(c->e_byte_array_len.val_codec);

    free(c);
}

// Assembly:
testq %rdi, %rdi
je 0x3e4fa
pushq %rbx
movq %rdi, %rbx
movq 0x48(%rdi), %rdi
testq %rdi, %rdi
je 0x3e4e5
callq *0x10(%rdi)
movq 0x50(%rbx), %rdi
testq %rdi, %rdi
je 0x3e4f1
callq *0x10(%rdi)
movq %rbx, %rdi
popq %rbx
jmp 0x4600
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_len_encode_init
cram_codec *cram_byte_array_len_encode_init(cram_stats *st,
					    enum cram_external_type option,
					    void *dat,
					    int version) {
    cram_codec *c;
    cram_byte_array_len_encoder *e = (cram_byte_array_len_encoder *)dat;

    c = malloc(sizeof(*c));
    if (!c)
	return NULL;
    c->codec = E_BYTE_ARRAY_LEN;
    c->free = cram_byte_array_len_encode_free;
    c->encode = cram_byte_array_len_encode;
    c->store = cram_byte_array_len_encode_store;

    c->e_byte_array_len.len_codec = cram_encoder_init(e->len_encoding,
						      NULL, E_INT, 
						      e->len_dat,
						      version);
    c->e_byte_array_len.val_codec = cram_encoder_init(e->val_encoding,
						      NULL, E_BYTE_ARRAY, 
						      e->val_dat,
						      version);

    return c;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %ecx, %ebp
movq %rdx, %r14
movl $0x240, %edi            # imm = 0x240
callq 0x46f0
movq %rax, %rbx
testq %rax, %rax
je 0x3e7e6
movl $0x4, (%rbx)
leaq -0x2cb(%rip), %rax      # 0x3e4d0
movq %rax, 0x10(%rbx)
leaq -0x31e(%rip), %rax      # 0x3e488
movq %rax, 0x20(%rbx)
leaq -0x2b6(%rip), %rax      # 0x3e4fb
movq %rax, 0x28(%rbx)
movl (%r14), %edi
movq 0x8(%r14), %rcx
pushq $0x1
popq %rdx
xorl %esi, %esi
movl %ebp, %r8d
callq 0x3e7ee
movq %rax, 0x48(%rbx)
movl 0x4(%r14), %edi
movq 0x10(%r14), %rcx
pushq $0x4
popq %rdx
xorl %esi, %esi
movl %ebp, %r8d
callq 0x3e7ee
movq %rax, 0x50(%rbx)
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_encoder_init
cram_codec *cram_encoder_init(enum cram_encoding codec,
			      cram_stats *st,
			      enum cram_external_type option,
			      void *dat,
			      int version) {
    if (st && !st->nvals)
	return NULL;

    if (encode_init[codec]) {
	cram_codec *r;
	if ((r = encode_init[codec](st, option, dat, version)))
	    r->out = NULL;
	return r;
    } else {
	fprintf(stderr, "Unimplemented codec of type %s\n", cram_encoding2str(codec));
	abort();
    }
}

// Assembly:
pushq %rbx
testq %rsi, %rsi
je 0x3e7fd
cmpl $0x0, 0x100c(%rsi)
je 0x3e82c
movl $0x385, %eax            # imm = 0x385
btq %rdi, %rax
jb 0x3e830
movl %edi, %eax
leaq 0x1851f(%rip), %r9      # 0x56d30
movq %rsi, %rdi
movl %edx, %esi
movq %rcx, %rdx
movl %r8d, %ecx
callq *(%r9,%rax,8)
testq %rax, %rax
je 0x3e82c
andq $0x0, 0x8(%rax)
jmp 0x3e82e
xorl %eax, %eax
popq %rbx
retq
movq 0x18799(%rip), %rax     # 0x56fd0
movq (%rax), %rbx
callq 0x3f109
leaq 0x9066(%rip), %rsi      # 0x478ac
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4770
callq 0x42f0
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_stop_decode_char
static int cram_byte_array_stop_decode_char(cram_slice *slice, cram_codec *c,
					    cram_block *in, char *out,
					    int *out_size) {
    cram_block *b = NULL;
    char *cp, ch;

    b = cram_get_block_by_id(slice, c->byte_array_stop.content_id);
    if (!b)
        return *out_size?-1:0;

    if (b->idx >= b->uncomp_size)
	return -1;

    cp = (char *)b->data + b->idx;
    if (out) {
	while ((ch = *cp) != (char)c->byte_array_stop.stop) {
	    if (cp - (char *)b->data >= b->uncomp_size)
		return -1;
	    *out++ = ch;
	    cp++;
	}
    } else {
	// Consume input, but produce no output
	while ((ch = *cp) != (char)c->byte_array_stop.stop) {
	    if (cp - (char *)b->data >= b->uncomp_size)
		return -1;
	    cp++;
	}
    }

    *out_size = cp - (char *)(b->data + b->idx);
    b->idx = cp - (char *)b->data + 1;

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %r8, %rbx
movq %rcx, %r15
movq %rsi, %r14
movl 0x34(%rsi), %esi
callq 0x3bc37
testq %rax, %rax
je 0x3ec30
movslq 0x1c(%rax), %rdi
movslq 0x14(%rax), %r8
pushq $-0x1
popq %rcx
cmpl %r8d, %edi
jge 0x3ec6c
movq 0x20(%rax), %rsi
testq %r15, %r15
je 0x3ec38
leaq (%rsi,%rdi), %rdx
addq %rdi, %rsi
movq %rsi, %rdi
movb (%rdx), %r8b
movq 0x20(%rax), %rsi
cmpb 0x30(%r14), %r8b
je 0x3ec4f
movq %rdi, %r9
subq %rsi, %r9
movslq 0x14(%rax), %rsi
cmpq %rsi, %r9
jge 0x3ec6c
movb %r8b, (%r15)
incq %r15
incq %rdx
incq %rdi
jmp 0x3ec06
xorl %ecx, %ecx
cmpl (%rbx), %ecx
sbbl %ecx, %ecx
jmp 0x3ec6c
movb 0x30(%r14), %r9b
movq %rdi, %rdx
cmpb %r9b, (%rsi,%rdx)
je 0x3ec55
cmpq %r8, %rdx
jge 0x3ec6c
incq %rdx
jmp 0x3ec3f
movslq 0x1c(%rax), %rdi
jmp 0x3ec58
addq %rsi, %rdx
movq %rsi, %rcx
addl %edi, %esi
movl %edx, %edi
subl %esi, %edi
movl %edi, (%rbx)
subl %ecx, %edx
incl %edx
movl %edx, 0x1c(%rax)
xorl %ecx, %ecx
movl %ecx, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_byte_array_stop_encode_init
cram_codec *cram_byte_array_stop_encode_init(cram_stats *st,
					     enum cram_external_type option,
					     void *dat,
					     int version) {
    cram_codec *c;

    c = malloc(sizeof(*c));
    if (!c)
	return NULL;
    c->codec = E_BYTE_ARRAY_STOP;
    c->free = cram_byte_array_stop_encode_free;
    c->encode = cram_byte_array_stop_encode;
    c->store = cram_byte_array_stop_encode_store;

    c->e_byte_array_stop.stop = ((int *)dat)[0];
    c->e_byte_array_stop.content_id = ((int *)dat)[1];

    return c;
}

// Assembly:
pushq %rbx
movq %rdx, %rbx
movl $0x240, %edi            # imm = 0x240
callq 0x46f0
testq %rax, %rax
je 0x3f107
movl $0x5, (%rax)
leaq -0x327(%rip), %rcx      # 0x3edbb
movq %rcx, 0x10(%rax)
leaq -0x479(%rip), %rcx      # 0x3ec74
movq %rcx, 0x20(%rax)
leaq -0x338(%rip), %rcx      # 0x3edc0
movq %rcx, 0x28(%rax)
movb (%rbx), %cl
movb %cl, 0x30(%rax)
movl 0x4(%rbx), %ecx
movl %ecx, 0x34(%rax)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_codec_to_id
int cram_codec_to_id(cram_codec *c, int *id2) {
    int bnum1, bnum2 = -2;

    switch (c->codec) {
    case E_HUFFMAN:
	bnum1 = c->huffman.ncodes == 1 ? -2 : -1;
	break;
    case E_GOLOMB:
    case E_BETA:
    case E_SUBEXP:
    case E_GOLOMB_RICE:
    case E_GAMMA:
	bnum1 = -1;
	break;
    case E_EXTERNAL:
	bnum1 = c->external.content_id;
	break;
    case E_BYTE_ARRAY_LEN:
	bnum1 = cram_codec_to_id(c->byte_array_len.len_codec, NULL);
	bnum2 = cram_codec_to_id(c->byte_array_len.val_codec, NULL);
	break;
    case E_BYTE_ARRAY_STOP:
	bnum1 = c->byte_array_stop.content_id;
	break;
    case E_NULL:
	bnum1 = -2;
	break;
    default:
	fprintf(stderr, "Unknown codec type %d\n", c->codec);
	bnum1 = -1;
    }

    if (id2)
	*id2 = bnum2;
    return bnum1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl (%rdi), %edx
pushq $-0x2
popq %r14
pushq $-0x1
popq %rbp
cmpq $0x9, %rdx
ja 0x3f1a8
movq %rdi, %r15
leaq 0x83d6(%rip), %rax      # 0x47520
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
testq %rbx, %rbx
je 0x3f15b
movl %r14d, (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x2
popq %rbp
movl %ebp, %r14d
jmp 0x3f153
movl 0x34(%r15), %ebp
jmp 0x3f153
xorl %ebp, %ebp
cmpl $0x1, 0x30(%r15)
sete %bpl
notl %ebp
jmp 0x3f153
movl 0x30(%r15), %ebp
jmp 0x3f153
movq 0x30(%r15), %rdi
xorl %esi, %esi
callq 0x3f127
movl %eax, %ebp
movq 0x38(%r15), %rdi
xorl %esi, %esi
callq 0x3f127
movl %eax, %r14d
jmp 0x3f153
movq 0x17e21(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0x8713(%rip), %rsi      # 0x478cc
xorl %eax, %eax
callq 0x4770
jmp 0x3f153
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/pooled_alloc.c
// Function: pool_create
pool_alloc_t *pool_create(size_t dsize) {
    pool_alloc_t *p;

    if (NULL == (p = (pool_alloc_t *)malloc(sizeof(*p))))
	return NULL;

    /* Minimum size is a pointer, for free list */
    dsize = (dsize + sizeof(void *) - 1) & ~(sizeof(void *)-1);
    if (dsize < sizeof(void *))
	dsize = sizeof(void *);
    p->dsize = dsize;
    p->psize = MIN(PSIZE, next_power_2(p->dsize*1024));

    p->npools = 0;
    p->pools = NULL;
    p->free  = NULL;

    return p;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
pushq $0x28
popq %rdi
callq 0x46f0
movq %rax, %rbx
testq %rax, %rax
je 0x3f465
addq $0x7, %r14
movq %r14, %rax
andq $-0x8, %rax
cmpq $0x8, %r14
pushq $0x8
popq %rdi
cmovaeq %rax, %rdi
movq %rdi, (%rbx)
shll $0xa, %edi
callq 0x3f470
movl $0x100000, %ecx         # imm = 0x100000
cmpl %ecx, %eax
cmovll %eax, %ecx
movslq %ecx, %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
andq $0x0, 0x20(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/pooled_alloc.c
// Function: pool_destroy
void pool_destroy(pool_alloc_t *p) {
    size_t i;

    for (i = 0; i < p->npools; i++) {
        free(p->pools[i].pool);
    }
    free(p->pools);
    free(p);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x18(%rbx), %rdi
cmpq 0x10(%rbx), %r15
jae 0x3f4c2
movq (%rdi,%r14), %rdi
callq 0x4600
incq %r15
addq $0x10, %r14
jmp 0x3f4a6
callq 0x4600
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x4600
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/pooled_alloc.c
// Function: pool_alloc
void *pool_alloc(pool_alloc_t *p) {
    pool_t *pool;
    void *ret;

    /* Look on free list */
    if (NULL != p->free) {
        ret = p->free;
	p->free = *((void **)p->free);
	return ret;
    }

    /* Look for space in the last pool */
    if (p->npools) {
        pool = &p->pools[p->npools - 1];
        if (pool->used + p->dsize < p->psize) {
	    ret = ((char *) pool->pool) + pool->used;
	    pool->used += p->dsize;
	    return ret;
	}
    }

    /* Need a new pool */
    pool = new_pool(p);
    if (NULL == pool) return NULL;

    pool->used = p->dsize;
    return pool->pool;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x20(%rdi), %r14
testq %r14, %r14
je 0x3f504
movq (%r14), %rax
movq %rax, 0x20(%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
je 0x3f53a
movq 0x18(%rbx), %rdi
movq %rsi, %rax
shlq $0x4, %rax
movq -0x8(%rdi,%rax), %r14
movq (%rbx), %r13
movq 0x8(%rbx), %r12
leaq (%r14,%r13), %rcx
cmpq %r12, %rcx
jae 0x3f545
addq %rax, %rdi
addq -0x10(%rdi), %r14
movq %rcx, -0x8(%rdi)
jmp 0x3f4f2
movq (%rbx), %r13
movq 0x8(%rbx), %r12
movq 0x18(%rbx), %rdi
shlq $0x4, %rsi
addq $0x10, %rsi
callq 0x48c0
testq %rax, %rax
je 0x3f5a6
movq %rax, %r15
xorl %r14d, %r14d
movq %r12, %rax
xorl %edx, %edx
divq %r13
movq %r15, 0x18(%rbx)
movq (%rbx), %r12
movq 0x10(%rbx), %r13
movq %r13, %rbp
shlq $0x4, %rbp
imulq %r12, %rax
movq %rax, %rdi
callq 0x46f0
movq %rax, (%r15,%rbp)
testq %rax, %rax
je 0x3f4f2
addq %rbp, %r15
incq %r13
movq %r13, 0x10(%rbx)
movq %r12, 0x8(%r15)
movq %rax, %r14
jmp 0x3f4f2
xorl %r14d, %r14d
jmp 0x3f4f2
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_connect
int kftp_connect(knetFile *ftp)
{
	ftp->ctrl_fd = socket_connect(ftp->host, ftp->port);
	if (ftp->ctrl_fd == -1) return -1;
	kftp_get_response(ftp);
	kftp_send_cmd(ftp, "USER anonymous\r\n", 1);
	kftp_send_cmd(ftp, "PASS kftp@\r\n", 1);
	kftp_send_cmd(ftp, "TYPE I\r\n", 1);
	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movq 0x18(%rbx), %rsi
callq 0x3f623
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x3f619
movq %rbx, %rdi
callq 0x3f746
leaq 0x8326(%rip), %rsi      # 0x4790c
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0x3f86b
leaq 0x8323(%rip), %rsi      # 0x4791d
movq %rbx, %rdi
movl %ebp, %edx
callq 0x3f86b
leaq 0x831f(%rip), %rsi      # 0x4792a
movq %rbx, %rdi
movl %ebp, %edx
callq 0x3f86b
xorl %eax, %eax
jmp 0x3f61c
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: socket_connect
static int socket_connect(const char *host, const char *port)
{
#define __err_connect(func) do { perror(func); freeaddrinfo(res); return -1; } while (0)

	int ai_err, on = 1, fd;
	struct linger lng = { 0, 0 };
	struct addrinfo hints, *res = 0;
	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	/* In Unix/Mac, getaddrinfo() is the most convenient way to get
	 * server information. */
	if ((ai_err = getaddrinfo(host, port, &hints, &res)) != 0) { fprintf(stderr, "can't resolve %s:%s: %s\n", host, port, gai_strerror(ai_err)); return -1; }
	if ((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) __err_connect("socket");
	/* The following two setsockopt() are used by ftplib
	 * (http://nbpfaus.net/~pfau/ftplib/). I am not sure if they
	 * necessary. */
	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) __err_connect("setsockopt");
	if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1) __err_connect("setsockopt");
	if (connect(fd, res->ai_addr, res->ai_addrlen) != 0) __err_connect("connect");
	freeaddrinfo(res);
	return fd;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x50, %rsp
movq %rsi, %rbx
movq %rdi, %r14
andq $0x0, 0x18(%rsp)
leaq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl %eax, 0x8(%rdx)
callq 0x4690
testl %eax, %eax
jne 0x3f6eb
movq 0x8(%rsp), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x4120
cmpl $-0x1, %eax
je 0x3f718
movl %eax, %ebx
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
leaq 0x14(%rsp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x4970
cmpl $-0x1, %eax
je 0x3f6e2
pushq $0x1
popq %rsi
pushq $0xd
popq %rdx
leaq 0x18(%rsp), %rcx
pushq $0x8
popq %r8
movl %ebx, %edi
callq 0x4970
cmpl $-0x1, %eax
je 0x3f6e2
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %ebx, %edi
callq 0x4430
testl %eax, %eax
jne 0x3f721
movq 0x8(%rsp), %rdi
callq 0x46d0
jmp 0x3f73a
leaq 0x8380(%rip), %rdi      # 0x47a69
jmp 0x3f728
movq 0x178de(%rip), %rcx     # 0x56fd0
movq (%rcx), %r15
movl %eax, %edi
callq 0x4730
leaq 0x8346(%rip), %rsi      # 0x47a49
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x4770
jmp 0x3f737
leaq 0x8343(%rip), %rdi      # 0x47a62
jmp 0x3f728
leaq 0x834c(%rip), %rdi      # 0x47a74
callq 0x4440
movq 0x8(%rsp), %rdi
callq 0x46d0
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x50, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_get_response
static int kftp_get_response(knetFile *ftp)
{
#ifndef _WIN32
	unsigned char c;
#else
	char c;
#endif
	int n = 0;
	char *p;
	if (socket_wait(ftp->ctrl_fd, 1) <= 0) return 0;
	while (netread(ftp->ctrl_fd, &c, 1)) { // FIXME: this is *VERY BAD* for unbuffered I/O
		//fputc(c, stderr);
		if (n >= ftp->max_response) {
			ftp->max_response = ftp->max_response? ftp->max_response<<1 : 256;
			ftp->response = (char*)realloc(ftp->response, ftp->max_response);
		}
		ftp->response[n++] = c;
		if (c == '\n') {
			if (n >= 4 && isdigit(ftp->response[0]) && isdigit(ftp->response[1]) && isdigit(ftp->response[2])
				&& ftp->response[3] != '-') break;
			n = 0;
			continue;
		}
	}
	if (n < 2) return -1;
	ftp->response[n-2] = 0;
	return strtol(ftp->response, &p, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x20(%rdi), %edi
pushq $0x1
popq %rsi
callq 0x402ee
testl %eax, %eax
jle 0x3f839
xorl %ecx, %ecx
leaq 0xf(%rsp), %r14
pushq $0x1
popq %r15
movl $0x100, %ebp            # imm = 0x100
movl %ecx, %r12d
movl 0x20(%rbx), %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4780
testq %rax, %rax
je 0x3f82e
movl 0x38(%rbx), %ecx
movq 0x48(%rbx), %rax
cmpl %ecx, %r12d
jl 0x3f7ba
leal (%rcx,%rcx), %edx
testl %ecx, %ecx
cmovel %ebp, %edx
movl %edx, 0x38(%rbx)
movslq %edx, %rsi
movq %rax, %rdi
callq 0x48c0
movq %rax, 0x48(%rbx)
movb 0xf(%rsp), %dl
leal 0x1(%r12), %r13d
movslq %r12d, %rcx
movb %dl, (%rax,%rcx)
movl %r13d, %ecx
cmpb $0xa, %dl
jne 0x3f77a
movl $0x0, %ecx
cmpl $0x3, %r12d
jl 0x3f77a
callq 0x4580
movq (%rax), %rdx
movq 0x48(%rbx), %rax
movsbq (%rax), %rcx
testb $0x8, 0x1(%rdx,%rcx,2)
movl $0x0, %ecx
je 0x3f77a
movsbq 0x1(%rax), %rcx
testb $0x8, 0x1(%rdx,%rcx,2)
movl $0x0, %ecx
je 0x3f77a
movsbq 0x2(%rax), %rcx
testb $0x8, 0x1(%rdx,%rcx,2)
movl $0x0, %ecx
je 0x3f77a
cmpb $0x2d, 0x3(%rax)
je 0x3f77a
jmp 0x3f844
cmpl $0x2, %r12d
jge 0x3f83d
pushq $-0x1
popq %rax
jmp 0x3f85c
xorl %eax, %eax
jmp 0x3f85c
movq 0x48(%rbx), %rax
movl %r12d, %r13d
movl %r13d, %ecx
movb $0x0, -0x2(%rax,%rcx)
movq 0x48(%rbx), %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x4760
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_send_cmd
static int kftp_send_cmd(knetFile *ftp, const char *cmd, int is_get)
{
	if (socket_wait(ftp->ctrl_fd, 0) <= 0) return -1; // socket is not ready for writing
    int len = strlen(cmd);
	if ( netwrite(ftp->ctrl_fd, cmd, len) != len ) return -1;
	return is_get? kftp_get_response(ftp) : 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x20(%rdi), %edi
xorl %esi, %esi
callq 0x402ee
testl %eax, %eax
jle 0x3f8b0
movq %r14, %rdi
callq 0x4210
movl 0x20(%rbx), %edi
movslq %eax, %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x41d0
cmpq %r15, %rax
setne %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
je 0x3f8bb
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3f746
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_reconnect
int kftp_reconnect(knetFile *ftp)
{
	if (ftp->ctrl_fd != -1) {
		netclose(ftp->ctrl_fd);
		ftp->ctrl_fd = -1;
	}
	netclose(ftp->fd);
	ftp->fd = -1;
	return kftp_connect(ftp);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
cmpl $-0x1, %edi
je 0x3f8e2
callq 0x4a40
orl $-0x1, 0x20(%rbx)
movl 0x4(%rbx), %edi
callq 0x4a40
orl $-0x1, 0x4(%rbx)
movq %rbx, %rdi
popq %rbx
jmp 0x3f5bc
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_parse_url
knetFile *kftp_parse_url(const char *fn, const char *mode)
{
	knetFile *fp;
	char *p;
	int l;
	if (strstr(fn, "ftp://") != fn) return 0;
	for (p = (char*)fn + 6; *p && *p != '/'; ++p);
	if (*p != '/') return 0;
	l = p - fn - 6;
	fp = (knetFile*)calloc(1, sizeof(knetFile));
	fp->type = KNF_TYPE_FTP;
	fp->fd = -1;
	/* the Linux/Mac version of socket_connect() also recognizes a port
	 * like "ftp", but the Windows version does not. */
	fp->port = strdup("21");
	fp->host = (char*)calloc(l + 1, 1);
	if (strchr(mode, 'c')) fp->no_reconnect = 1;
	strncpy(fp->host, fn + 6, l);
	fp->retr = (char*)calloc(strlen(p) + 8, 1);
	sprintf(fp->retr, "RETR %s\r\n", p);
    fp->size_cmd = (char*)calloc(strlen(p) + 8, 1);
    sprintf(fp->size_cmd, "SIZE %s\r\n", p);
	fp->seek_offset = 0;
	return fp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %r15
leaq 0x8024(%rip), %rsi      # 0x47933
pushq $0x6
popq %rdx
callq 0x4280
testl %eax, %eax
je 0x3f930
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x100000000, %rbp      # imm = 0x100000000
addq $0x6, %r15
xorl %r13d, %r13d
movq %r15, %rbx
movzbl (%rbx), %eax
testl %eax, %eax
je 0x3f91b
cmpl $0x2f, %eax
je 0x3f958
incq %rbx
addq %rbp, %r13
jmp 0x3f944
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x4370
movq %rax, %r14
movabsq $-0xfffffffe, %rax      # imm = 0xFFFFFFFF00000002
movq %rax, (%r14)
leaq 0x7fbe(%rip), %rdi      # 0x4793a
callq 0x49a0
movq %rax, 0x18(%r14)
addq %r13, %rbp
sarq $0x20, %rbp
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x4370
movq %rax, %rbp
movq %rax, 0x10(%r14)
pushq $0x63
popq %rsi
movq %r12, %rdi
callq 0x41e0
testq %rax, %rax
je 0x3f9b6
movl $0x1, 0x3c(%r14)
sarq $0x20, %r13
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x42c0
movq %rbx, %rdi
callq 0x4210
leaq 0x8(%rax), %rdi
pushq $0x1
popq %r15
movq %r15, %rsi
callq 0x4370
movq %rax, 0x50(%r14)
leaq 0x7f52(%rip), %rsi      # 0x4793d
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4100
movq %rbx, %rdi
callq 0x4210
leaq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x4370
movq %rax, 0x58(%r14)
leaq 0x7f30(%rip), %rsi      # 0x47947
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4100
jmp 0x3f91e
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: khttp_parse_url
knetFile *khttp_parse_url(const char *fn, const char *mode)
{
	knetFile *fp;
	char *p, *proxy, *q;
	int l;
	if (strstr(fn, "http://") != fn) return 0;
	// set ->http_host
	for (p = (char*)fn + 7; *p && *p != '/'; ++p);
	l = p - fn - 7;
	fp = (knetFile*)calloc(1, sizeof(knetFile));
	fp->http_host = (char*)calloc(l + 1, 1);
	strncpy(fp->http_host, fn + 7, l);
	fp->http_host[l] = 0;
	for (q = fp->http_host; *q && *q != ':'; ++q);
	if (*q == ':') *q++ = 0;
	// get http_proxy
	proxy = getenv("http_proxy");
	// set ->host, ->port and ->path
	if (proxy == 0) {
		fp->host = strdup(fp->http_host); // when there is no proxy, server name is identical to http_host name.
		fp->port = strdup(*q? q : "80");
		fp->path = strdup(*p? p : "/");
	} else {
		fp->host = (strstr(proxy, "http://") == proxy)? strdup(proxy + 7) : strdup(proxy);
		for (q = fp->host; *q && *q != ':'; ++q);
		if (*q == ':') *q++ = 0; 
		fp->port = strdup(*q? q : "80");
		fp->path = strdup(fn);
	}
	fp->type = KNF_TYPE_HTTP;
	fp->ctrl_fd = fp->fd = -1;
	fp->seek_offset = 0;
	return fp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x7d70(%rip), %rsi      # 0x4797e
pushq $0x7
popq %rdx
callq 0x4280
testl %eax, %eax
je 0x3fc21
xorl %ebx, %ebx
jmp 0x3fd73
movabsq $0x100000000, %rbp      # imm = 0x100000000
leaq 0x7(%rbx), %r13
xorl %r12d, %r12d
movq %r13, %r15
movzbl (%r15), %r14d
testl %r14d, %r14d
je 0x3fc4c
cmpl $0x2f, %r14d
je 0x3fc4c
incq %r15
addq %rbp, %r12
jmp 0x3fc35
movq %rbx, (%rsp)
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x4370
movq %rax, %rbx
addq %r12, %rbp
sarq $0x20, %rbp
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x4370
movq %rax, %rbp
movq %rax, 0x78(%rbx)
sarq $0x20, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x42c0
movb $0x0, (%rbp,%r12)
movq %rbp, %r13
movzbl (%r13), %eax
testl %eax, %eax
je 0x3fcaf
cmpl $0x3a, %eax
je 0x3fca7
incq %r13
jmp 0x3fc94
movb $0x0, (%r13)
incq %r13
leaq 0x7cd0(%rip), %rdi      # 0x47986
callq 0x4640
testq %rax, %rax
je 0x3fd0d
movq %rax, %r12
leaq 0x7cb4(%rip), %rsi      # 0x4797e
pushq $0x7
popq %rdx
movq %rax, %rdi
callq 0x4280
leaq 0x7(%r12), %rdi
testl %eax, %eax
cmovneq %r12, %rdi
callq 0x49a0
movq %rax, 0x10(%rbx)
incq %rax
movzbl -0x1(%rax), %ecx
testl %ecx, %ecx
je 0x3fd45
cmpl $0x3a, %ecx
jne 0x3fce9
movb $0x0, -0x1(%rax)
cmpb $0x0, (%rax)
leaq 0x7c8a(%rip), %rdi      # 0x47991
cmovneq %rax, %rdi
jmp 0x3fd4c
movq %rbp, %rdi
callq 0x49a0
cmpb $0x0, (%r13)
movq %rax, 0x10(%rbx)
leaq 0x7c6c(%rip), %rdi      # 0x47991
cmovneq %r13, %rdi
callq 0x49a0
movq %rax, 0x18(%rbx)
testb %r14b, %r14b
leaq 0x773b(%rip), %rax      # 0x47477
cmoveq %rax, %r15
movq %r15, %rdi
jmp 0x3fd59
leaq 0x7c45(%rip), %rdi      # 0x47991
callq 0x49a0
movq %rax, 0x18(%rbx)
movq (%rsp), %rdi
callq 0x49a0
movq %rax, 0x70(%rbx)
movabsq $-0xfffffffd, %rax      # imm = 0xFFFFFFFF00000003
movq %rax, (%rbx)
orl $-0x1, 0x20(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: my_netread
static off_t my_netread(int fd, void *buf, off_t len)
{
	off_t rest = len, curr, l = 0;
	/* recv() and read() may not read the required length of data with
	 * one call. They have to be called repeatedly. */
	while (rest) {
		if (socket_wait(fd, 1) <= 0) break; // socket is not ready for reading
		curr = netread(fd, (void*)((char*)buf + l), rest);
		/* According to the glibc manual, section 13.2, a zero returned
		 * value indicates end-of-file (EOF), which should mean that
		 * read() will not return zero if EOF has not been met but data
		 * are not immediately available. */
		if (curr == 0) break;
		l += curr; rest -= curr;
	}
	return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
xorl %r15d, %r15d
pushq $0x1
popq %r12
testq %rbx, %rbx
je 0x3ffd2
movl %ebp, %edi
movl %r12d, %esi
callq 0x402ee
testl %eax, %eax
jle 0x3ffd2
leaq (%r14,%r15), %rsi
movl %ebp, %edi
movq %rbx, %rdx
callq 0x4780
testq %rax, %rax
je 0x3ffd2
addq %rax, %r15
subq %rax, %rbx
jmp 0x3ffa4
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: knet_open
knetFile *knet_open(const char *fn, const char *mode)
{
	knetFile *fp = 0;
	if (mode[0] != 'r') {
		fprintf(stderr, "[kftp_open] only mode \"r\" is supported.\n");
		return 0;
	}
	if (strstr(fn, "ftp://") == fn) {
		fp = kftp_parse_url(fn, mode);
		if (fp == 0) return 0;
		if (kftp_connect(fp) == -1) {
			knet_close(fp);
			return 0;
		}
		kftp_connect_file(fp);
	} else if (strstr(fn, "http://") == fn) {
		fp = khttp_parse_url(fn, mode);
		if (fp == 0) return 0;
		khttp_connect_file(fp);
	} else { // local file
#ifdef _WIN32
		/* In windows, O_BINARY is necessary. In Linux/Mac, O_BINARY may
		 * be undefined on some systems, although it is defined on my
		 * Mac and the Linux I have tested on. */
		int fd = open(fn, O_RDONLY | O_BINARY);
#else		
		int fd = open(fn, O_RDONLY);
#endif
		if (fd == -1) {
			perror("open");
			return 0;
		}
		fp = (knetFile*)calloc(1, sizeof(knetFile));
		fp->type = KNF_TYPE_LOCAL;
		fp->fd = fd;
		fp->ctrl_fd = -1;
	}
	if (fp && fp->fd == -1) {
		knet_close(fp);
		return 0;
	}
	return fp;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
cmpb $0x72, (%rsi)
jne 0x400a7
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x793b(%rip), %rsi      # 0x47933
pushq $0x6
popq %rdx
callq 0x4280
testl %eax, %eax
je 0x40050
leaq 0x7973(%rip), %rsi      # 0x4797e
pushq $0x7
popq %rdx
movq %rbx, %rdi
callq 0x4280
movq %rbx, %rdi
testl %eax, %eax
je 0x4007a
xorl %esi, %esi
xorl %eax, %eax
callq 0x43c0
cmpl $-0x1, %eax
je 0x400c5
movl %eax, %ebp
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x4370
movq %rax, %rbx
movl $0x1, (%rax)
movl %ebp, 0x4(%rax)
orl $-0x1, 0x20(%rax)
jmp 0x4008f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3f8f7
testq %rax, %rax
je 0x4009d
movq %rax, %rbx
movq %rax, %rdi
callq 0x3f5bc
cmpl $-0x1, %eax
je 0x40095
movq %rbx, %rdi
callq 0x3fa29
jmp 0x4008f
callq 0x3fbf9
testq %rax, %rax
je 0x4009d
movq %rax, %rbx
movq %rax, %rdi
callq 0x3fd85
cmpl $-0x1, 0x4(%rbx)
jne 0x4009f
movq %rbx, %rdi
callq 0x400d3
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
movq 0x16f22(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x7912(%rip), %rdi      # 0x479ca
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
jmp 0x4009d
leaq 0x3dbd(%rip), %rdi      # 0x43e89
callq 0x4440
jmp 0x4009d
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: knet_close
int knet_close(knetFile *fp)
{
	if (fp == 0) return 0;
	if (fp->ctrl_fd != -1) netclose(fp->ctrl_fd); // FTP specific
	if (fp->fd != -1) {
		/* On Linux/Mac, netclose() is an alias of close(), but on
		 * Windows, it is an alias of closesocket(). */
		if (fp->type == KNF_TYPE_LOCAL) close(fp->fd);
		else netclose(fp->fd);
	}
	free(fp->host); free(fp->port);
	free(fp->response); free(fp->retr); // FTP specific
	free(fp->path); free(fp->http_host); // HTTP specific
	free(fp);
	return 0;
}

// Assembly:
testq %rdi, %rdi
je 0x40135
pushq %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
cmpl $-0x1, %edi
je 0x400e9
callq 0x4a40
movl 0x4(%rbx), %edi
cmpl $-0x1, %edi
je 0x400f6
callq 0x4a40
movq 0x10(%rbx), %rdi
callq 0x4600
movq 0x18(%rbx), %rdi
callq 0x4600
movq 0x48(%rbx), %rdi
callq 0x4600
movq 0x50(%rbx), %rdi
callq 0x4600
movq 0x70(%rbx), %rdi
callq 0x4600
movq 0x78(%rbx), %rdi
callq 0x4600
movq %rbx, %rdi
callq 0x4600
popq %rbx
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: knet_dopen
knetFile *knet_dopen(int fd, const char *mode)
{
	knetFile *fp = (knetFile*)calloc(1, sizeof(knetFile));
	fp->type = KNF_TYPE_LOCAL;
	fp->fd = fd;
	return fp;
}

// Assembly:
pushq %rbx
movl %edi, %ebx
pushq $0x1
popq %rdi
movl $0x80, %esi
callq 0x4370
movl $0x1, (%rax)
movl %ebx, 0x4(%rax)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: knet_read
ssize_t knet_read(knetFile *fp, void *buf, size_t len)
{
	off_t l = 0;
	if (fp->fd == -1) return 0;
	if (fp->type == KNF_TYPE_FTP) {
		if (fp->is_ready == 0) {
			if (!fp->no_reconnect) kftp_reconnect(fp);
			kftp_connect_file(fp);
		}
	} else if (fp->type == KNF_TYPE_HTTP) {
		if (fp->is_ready == 0)
			khttp_connect_file(fp);
	}
	if (fp->type == KNF_TYPE_LOCAL) { // on Windows, the following block is necessary; not on UNIX
		size_t rest = len;
		ssize_t curr;
		while (rest) {
			do {
				curr = read(fp->fd, (void*)((char*)buf + l), rest);
			} while (curr < 0 && EINTR == errno);
			if (curr < 0) return -1;
			if (curr == 0) break;
			l += curr; rest -= curr;
		}
	} else l = my_netread(fp->fd, buf, len);
	fp->offset += l;
	return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x4(%rdi), %edi
cmpl $-0x1, %edi
je 0x40199
movq %rdx, %r14
movq %rsi, %r15
movl (%rbx), %eax
cmpl $0x3, %eax
je 0x4019e
cmpl $0x2, %eax
jne 0x401ae
cmpl $0x0, 0x40(%rbx)
jne 0x401ef
cmpl $0x0, 0x3c(%rbx)
jne 0x4018f
movq %rbx, %rdi
callq 0x3f8cd
movq %rbx, %rdi
callq 0x3fa29
jmp 0x401ac
xorl %r13d, %r13d
jmp 0x40204
cmpl $0x0, 0x40(%rbx)
jne 0x401ef
movq %rbx, %rdi
callq 0x3fd85
movl (%rbx), %eax
cmpl $0x1, %eax
jne 0x401ec
xorl %r12d, %r12d
pushq $-0x1
popq %r13
testq %r14, %r14
je 0x401fd
leaq (%r15,%r12), %rbp
movl 0x4(%rbx), %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x4780
testq %rax, %rax
jns 0x401e2
callq 0x4060
cmpl $0x4, (%rax)
je 0x401c3
jmp 0x40204
je 0x401fd
addq %rax, %r12
subq %rax, %r14
jmp 0x401ba
movl 0x4(%rbx), %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3ff8d
movq %rax, %r12
addq %r12, 0x8(%rbx)
movq %r12, %r13
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: knet_seek
off_t knet_seek(knetFile *fp, off_t off, int whence)
{
	if (whence == SEEK_SET && off == fp->offset) return 0;
	if (fp->type == KNF_TYPE_LOCAL) {
		/* Be aware that lseek() returns the offset after seeking, while fseek() returns zero on success. */
		off_t offset = lseek(fp->fd, off, whence);
		if (offset == -1) return -1;
		fp->offset = offset;
		return fp->offset;
	} else if (fp->type == KNF_TYPE_FTP) {
		if (whence == SEEK_CUR) fp->offset += off;
		else if (whence == SEEK_SET) fp->offset = off;
		else if (whence == SEEK_END) fp->offset = fp->file_size + off;
		else return -1;
		fp->is_ready = 0;
		return fp->offset;
	} else if (fp->type == KNF_TYPE_HTTP) {
		if (whence == SEEK_END) { // FIXME: can we allow SEEK_END in future?
			fprintf(stderr, "[knet_seek] SEEK_END is not supported for HTTP. Offset is unchanged.\n");
			errno = ESPIPE;
			return -1;
		}
		if (whence == SEEK_CUR) fp->offset += off;
		else if (whence == SEEK_SET) fp->offset = off;
		else return -1;
		fp->is_ready = 0;
		return fp->offset;
	}
	errno = EINVAL;
	fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
	return -1;
}

// Assembly:
pushq %rbx
movq %rsi, %rax
movq %rdi, %rbx
testl %edx, %edx
jne 0x4022e
cmpq %rax, 0x8(%rbx)
jne 0x4022e
xorl %eax, %eax
jmp 0x402ec
movl (%rbx), %ecx
cmpl $0x3, %ecx
je 0x4025d
cmpl $0x2, %ecx
je 0x4026d
cmpl $0x1, %ecx
jne 0x4028f
movl 0x4(%rbx), %edi
movq %rax, %rsi
callq 0x49c0
cmpq $-0x1, %rax
je 0x402e9
movq %rax, 0x8(%rbx)
jmp 0x402ec
cmpl $0x1, %edx
je 0x40272
cmpl $0x2, %edx
je 0x402c2
testl %edx, %edx
jne 0x402e9
jmp 0x40276
cmpl $0x1, %edx
jne 0x40280
addq 0x8(%rbx), %rax
movq %rax, 0x8(%rbx)
andl $0x0, 0x40(%rbx)
jmp 0x402ec
testl %edx, %edx
je 0x40276
cmpl $0x2, %edx
jne 0x402e9
addq 0x68(%rbx), %rax
jmp 0x40276
callq 0x4060
movl $0x16, (%rax)
movq 0x16d2f(%rip), %rax     # 0x56fd0
movq (%rax), %rbx
pushq $0x16
popq %rdi
callq 0x4190
leaq 0x7786(%rip), %rsi      # 0x47a39
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x402e9
movq 0x16d07(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x7720(%rip), %rdi      # 0x479f3
pushq $0x45
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
callq 0x4060
movl $0x1d, (%rax)
pushq $-0x1
popq %rax
popq %rbx
retq