LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/faidx.c
// Function: download_and_open
FILE *download_and_open(const char *fn)
{
    const int buf_size = 1 * 1024 * 1024;
    uint8_t *buf;
    FILE *fp;
    knetFile *fp_remote;
    const char *url = fn;
    const char *p;
    int l = strlen(fn);
    for (p = fn + l - 1; p >= fn; --p)
        if (*p == '/') break;
    fn = p + 1;

    // First try to open a local copy
    fp = fopen(fn, "r");
    if (fp)
        return fp;

    // If failed, download from remote and open
    fp_remote = knet_open(url, "rb");
    if (fp_remote == 0) {
        fprintf(stderr, "[download_from_remote] fail to open remote file %s\n",url);
        return NULL;
    }
    if ((fp = fopen(fn, "wb")) == 0) {
        fprintf(stderr, "[download_from_remote] fail to create file in the working directory %s\n",fn);
        knet_close(fp_remote);
        return NULL;
    }
    buf = (uint8_t*)calloc(buf_size, 1);
    while ((l = knet_read(fp_remote, buf, buf_size)) != 0)
        fwrite(buf, 1, l, fp);
    free(buf);
    fclose(fp);
    knet_close(fp_remote);

    return fopen(fn, "r");
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
callq 0x31e0
cltq
addq %r15, %rax
decq %rax
movq %rax, %rbx
cmpq %r15, %rax
jb 0x13e25
leaq -0x1(%rbx), %rax
cmpb $0x2f, (%rbx)
jne 0x13e14
incq %rbx
leaq 0x79d7(%rip), %rsi      # 0x1b806
movq %rbx, %rdi
callq 0x3340
movq %rax, %r12
testq %rax, %rax
je 0x13e4e
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x5efe(%rip), %rsi      # 0x19d53
movq %r15, %rdi
callq 0x156b5
testq %rax, %rax
je 0x13efc
movq %rax, %r14
leaq 0x7504(%rip), %rsi      # 0x1b374
movq %rbx, %rdi
callq 0x3340
testq %rax, %rax
je 0x13f1f
movq %rax, %r15
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x32e0
movq %rax, %r12
movl $0x100000, %edx         # imm = 0x100000
movq %r14, %rdi
movq %rax, %rsi
callq 0x1582a
testl %eax, %eax
je 0x13eca
movslq %eax, %rdx
movl $0x1, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x3540
movl $0x100000, %edx         # imm = 0x100000
movq %r14, %rdi
movq %r12, %rsi
jmp 0x13ea1
movq %r12, %rdi
callq 0x3060
movq %r15, %rdi
callq 0x31c0
movq %r14, %rdi
callq 0x157a8
leaq 0x791d(%rip), %rsi      # 0x1b806
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3340
movq 0xe0f5(%rip), %rax      # 0x21ff8
movq (%rax), %rdi
leaq 0x7a5b(%rip), %rsi      # 0x1b968
xorl %r12d, %r12d
movq %r15, %rdx
xorl %eax, %eax
callq 0x3320
jmp 0x13e3f
movq 0xe0d2(%rip), %rax      # 0x21ff8
movq (%rax), %rdi
leaq 0x7a6c(%rip), %rsi      # 0x1b99c
xorl %r12d, %r12d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3320
movq %r14, %rdi
callq 0x157a8
jmp 0x13e3f
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/faidx.c
// Function: fai_load
faidx_t *fai_load(const char *fn)
{
	char *str;
	FILE *fp;
	faidx_t *fai;
	str = (char*)calloc(strlen(fn) + 5, 1);
	sprintf(str, "%s.fai", fn);

#ifdef _USE_KNETFILE
    if (strstr(fn, "ftp://") == fn || strstr(fn, "http://") == fn)
    {
        fp = download_and_open(str);
        if ( !fp )
        {
            fprintf(stderr, "[fai_load] failed to open remote FASTA index %s\n", str);
            free(str);
            return 0;
        }
    }
    else
#endif
        fp = fopen(str, "rb");
	if (fp == 0) {
		fprintf(stderr, "[fai_load] build FASTA index.\n");
		fai_build(fn);
		fp = fopen(str, "rb");
		if (fp == 0) {
			fprintf(stderr, "[fai_load] fail to open FASTA index.\n");
			free(str);
			return 0;
		}
	}

	fai = fai_read(fp);
	fclose(fp);

	fai->rz = razf_open(fn, "rb");
	free(str);
	if (fai->rz == 0) {
		fprintf(stderr, "[fai_load] fail to open FASTA file.\n");
		return 0;
	}
	return fai;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x31e0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x32e0
movq %rax, %r14
leaq 0x7999(%rip), %rsi      # 0x1b90b
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3510
leaq 0x7311(%rip), %rsi      # 0x1b297
movl $0x6, %edx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
je 0x13fc3
leaq 0x7300(%rip), %rsi      # 0x1b29e
movl $0x7, %edx
movq %rbx, %rdi
callq 0x30c0
testl %eax, %eax
je 0x13fc3
leaq 0x5d9d(%rip), %rsi      # 0x19d53
movq %r14, %rdi
callq 0x3340
movq %rax, %r12
jmp 0x13fd3
movq %r14, %rdi
callq 0x13dfc
movq %rax, %r12
testq %rax, %rax
je 0x1403b
testq %r12, %r12
je 0x1401c
movq %r12, %rdi
callq 0x13c18
movq %rax, %r15
movq %r12, %rdi
callq 0x31c0
leaq 0x5d61(%rip), %rsi      # 0x19d53
movq %rbx, %rdi
callq 0x12671
movq %rax, %rbx
movq %rax, (%r15)
movq %r14, %rdi
callq 0x3060
testq %rbx, %rbx
je 0x14034
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rsp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x40ec
testb $0x1, %al
je 0x14043
movq (%rsp), %r12
jmp 0x13fd8
callq 0x4169
jmp 0x14043
movq %r14, %rdi
callq 0x4185
xorl %r15d, %r15d
jmp 0x1400d
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/faidx.c
// Function: faidx_main
int faidx_main(int argc, char *argv[])
{
	if (argc == 1) {
		fprintf(stderr, "Usage: faidx <in.fasta> [<reg> [...]]\n");
		return 1;
	} else {
		if (argc == 2) fai_build(argv[1]);
		else {
			int i, j, k, l;
			char *s;
			faidx_t *fai;
			fai = fai_load(argv[1]);
			if (fai == 0) return 1;
			for (i = 2; i != argc; ++i) {
				printf(">%s\n", argv[i]);
				s = fai_fetch(fai, argv[i], &l);
				for (j = 0; j < l; j += 60) {
					for (k = 0; k < 60 && k < l - j; ++k)
						putchar(s[j + k]);
					putchar('\n');
				}
				free(s);
			}
			fai_destroy(fai);
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
cmpl $0x2, %edi
je 0x147dc
movl %edi, %ebp
cmpl $0x1, %edi
je 0x147e9
movq 0x8(%rbx), %rdi
callq 0x13f4a
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x147ee
cmpl $0x2, %ebp
je 0x147c8
movl %ebp, %eax
movq %rax, 0x18(%rsp)
movl $0x2, %r15d
movq %rbx, 0x20(%rsp)
movq (%rbx,%r15,8), %rsi
leaq 0x73bc(%rip), %rdi      # 0x1bafc
xorl %eax, %eax
callq 0x3210
movq (%rbx,%r15,8), %rsi
movq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x14048
movq %rax, 0x10(%rsp)
movslq 0x4(%rsp), %rbx
testq %rbx, %rbx
jle 0x147ab
movq 0x10(%rsp), %r13
xorl %r14d, %r14d
movq %rbx, %r12
subq %r14, %r12
jle 0x14794
xorl %ebp, %ebp
movsbl (%r13,%rbp), %edi
callq 0x3070
cmpq $0x3a, %rbp
ja 0x14794
incq %rbp
cmpq %r12, %rbp
jl 0x1477b
movl $0xa, %edi
callq 0x3070
addq $0x3c, %r14
addq $0x3c, %r13
cmpq %rbx, %r14
jb 0x14771
movq 0x10(%rsp), %rdi
callq 0x3060
incq %r15
cmpq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0x14735
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x13a1c
testq %rbx, %rbx
jne 0x147e5
jmp 0x147ee
movq 0x8(%rbx), %rdi
callq 0x13d27
xorl %eax, %eax
jmp 0x147f3
callq 0x41ad
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 %rbx
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movq 0x18(%rbx), %rsi
callq 0x14d74
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x14d6d
movq %rbx, %rdi
callq 0x14e65
leaq 0x6e5c(%rip), %rsi      # 0x1bb90
movq %rbx, %rdi
movl $0x1, %edx
callq 0x14f8d
leaq 0x6e59(%rip), %rsi      # 0x1bba1
movq %rbx, %rdi
movl $0x1, %edx
callq 0x14f8d
leaq 0x6e52(%rip), %rsi      # 0x1bbae
movq %rbx, %rdi
movl $0x1, %edx
callq 0x14f8d
xorl %eax, %eax
jmp 0x14d72
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 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 (getaddrinfo(host, port, &hints, &res) != 0) __err_connect("getaddrinfo");
	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 %rbx
subq $0x50, %rsp
movl $0x1, %eax
movl %eax, 0x14(%rsp)
xorl %edx, %edx
movq %rdx, 0x18(%rsp)
leaq 0x8(%rsp), %rcx
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl %eax, 0x8(%rdx)
callq 0x3570
testl %eax, %eax
jne 0x14e39
movq 0x8(%rsp), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x3620
cmpl $-0x1, %eax
je 0x14e42
movl %eax, %ebx
leaq 0x14(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x3160
cmpl $-0x1, %eax
je 0x14e30
leaq 0x18(%rsp), %rcx
movl %ebx, %edi
movl $0x1, %esi
movl $0xd, %edx
movl $0x8, %r8d
callq 0x3160
cmpl $-0x1, %eax
je 0x14e30
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %ebx, %edi
callq 0x3530
testl %eax, %eax
je 0x14e53
leaq 0x6eec(%rip), %rdi      # 0x1bd1a
jmp 0x14e49
leaq 0x6ed8(%rip), %rdi      # 0x1bd0f
jmp 0x14e49
leaq 0x6ebc(%rip), %rdi      # 0x1bcfc
jmp 0x14e49
leaq 0x6ebf(%rip), %rdi      # 0x1bd08
callq 0x34d0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x3610
movl %ebx, %eax
addq $0x50, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 = 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
movl $0x1, %esi
callq 0x15965
testl %eax, %eax
jle 0x14f50
movl 0x20(%rbx), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x32b0
testq %rax, %rax
je 0x14f54
xorl %r13d, %r13d
leaq 0xf(%rsp), %r14
movl $0x100, %ebp            # imm = 0x100
movl 0x38(%rbx), %eax
cmpl %eax, %r13d
jl 0x14ed6
leal (%rax,%rax), %ecx
testl %eax, %eax
cmovel %ebp, %ecx
movl %ecx, 0x38(%rbx)
movq 0x48(%rbx), %rdi
movslq %ecx, %rsi
callq 0x3430
movq %rax, 0x48(%rbx)
movb 0xf(%rsp), %al
movq 0x48(%rbx), %rcx
leal 0x1(%r13), %r12d
movslq %r13d, %rdx
movb %al, (%rcx,%rdx)
cmpb $0xa, %al
jne 0x14f2c
xorl %r15d, %r15d
cmpl $0x3, %r13d
jl 0x14f2f
callq 0x35f0
movq (%rax), %rcx
movq 0x48(%rbx), %rax
movsbq (%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x14f2f
movsbq 0x1(%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x14f2f
movsbq 0x2(%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x14f2f
cmpb $0x2d, 0x3(%rax)
je 0x14f2f
jmp 0x14f57
movl %r12d, %r15d
movl 0x20(%rbx), %edi
movl $0x1, %edx
movq %r14, %rsi
callq 0x32b0
movl %r15d, %r13d
movl %r15d, %r12d
testq %rax, %rax
jne 0x14eb3
jmp 0x14f57
xorl %eax, %eax
jmp 0x14f7e
xorl %r12d, %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x2, %r12d
jl 0x14f7e
movq 0x48(%rbx), %rax
movl %r12d, %ecx
movb $0x0, -0x2(%rax,%rcx)
movq 0x48(%rbx), %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x3360
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 0x14ffd
callq 0x3270
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
movl 0x4(%rbx), %edi
callq 0x3270
movl $0xffffffff, 0x4(%rbx)  # imm = 0xFFFFFFFF
movq %rbx, %rdi
popq %rbx
jmp 0x14d0c
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 = 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 = calloc(l + 1, 1);
	if (strchr(mode, 'c')) fp->no_reconnect = 1;
	strncpy(fp->host, fn + 6, l);
	fp->retr = calloc(strlen(p) + 8, 1);
	sprintf(fp->retr, "RETR %s\r\n", p);
    fp->size_cmd = 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 0x626a(%rip), %rsi      # 0x1b297
movl $0x6, %edx
callq 0x30c0
testl %eax, %eax
je 0x15050
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 0x1503b
cmpl $0x2f, %eax
je 0x15078
incq %rbx
addq %rbp, %r13
jmp 0x15064
movl $0x1, %edi
movl $0x80, %esi
callq 0x32e0
movq %rax, %r14
movabsq $-0xfffffffe, %rax      # imm = 0xFFFFFFFF00000002
movq %rax, (%r14)
leaq 0x6b19(%rip), %rdi      # 0x1bbb7
callq 0x3590
movq %rax, 0x18(%r14)
addq %r13, %rbp
sarq $0x20, %rbp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x32e0
movq %rax, %rbp
movq %rax, 0x10(%r14)
movq %r12, %rdi
movl $0x63, %esi
callq 0x3200
testq %rax, %rax
je 0x150dc
movl $0x1, 0x3c(%r14)
sarq $0x20, %r13
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30b0
movq %rbx, %rdi
callq 0x31e0
leaq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x32e0
movq %rax, 0x50(%r14)
leaq 0x6aab(%rip), %rsi      # 0x1bbba
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3510
movq %rbx, %rdi
callq 0x31e0
leaq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x32e0
movq %rax, 0x58(%r14)
leaq 0x6a87(%rip), %rsi      # 0x1bbc4
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3510
movq $0x0, 0x60(%r14)
jmp 0x1503e
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 = calloc(1, sizeof(knetFile));
	fp->http_host = 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 0x5f73(%rip), %rsi      # 0x1b29e
movl $0x7, %edx
callq 0x30c0
testl %eax, %eax
je 0x15340
xorl %ebx, %ebx
jmp 0x1549d
movabsq $0x100000000, %rbp      # imm = 0x100000000
leaq 0x7(%rbx), %r13
xorl %r12d, %r12d
movq %r13, %r15
movzbl (%r15), %r14d
testl %r14d, %r14d
je 0x1536b
cmpl $0x2f, %r14d
je 0x1536b
incq %r15
addq %rbp, %r12
jmp 0x15354
movq %rbx, (%rsp)
movl $0x1, %edi
movl $0x80, %esi
callq 0x32e0
movq %rax, %rbx
addq %r12, %rbp
sarq $0x20, %rbp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x32e0
movq %rax, %rbp
movq %rax, 0x78(%rbx)
sarq $0x20, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x30b0
movb $0x0, (%rbp,%r12)
movq %rbp, %r13
movzbl (%r13), %eax
testl %eax, %eax
je 0x153d2
cmpl $0x3a, %eax
je 0x153ca
incq %r13
jmp 0x153b7
movb $0x0, (%r13)
incq %r13
leaq 0x6822(%rip), %rdi      # 0x1bbfb
callq 0x3040
testq %rax, %rax
je 0x1541f
movq %rax, %r12
leaq 0x5eb1(%rip), %rsi      # 0x1b29e
movl $0x7, %edx
movq %rax, %rdi
callq 0x30c0
leaq 0x7(%r12), %rdi
testl %eax, %eax
cmovneq %r12, %rdi
callq 0x3590
movq %rax, 0x10(%rbx)
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x1545d
cmpl $0x3a, %ecx
je 0x15457
incq %rax
jmp 0x1540e
movq %rbp, %rdi
callq 0x3590
cmpb $0x0, (%r13)
movq %rax, 0x10(%rbx)
leaq 0x67cf(%rip), %rdi      # 0x1bc06
cmovneq %r13, %rdi
callq 0x3590
movq %rax, 0x18(%rbx)
testb %r14b, %r14b
leaq 0x5e4e(%rip), %rax      # 0x1b29c
cmoveq %rax, %r15
movq %r15, %rdi
jmp 0x15478
movb $0x0, (%rax)
incq %rax
cmpb $0x0, (%rax)
leaq 0x679f(%rip), %rdi      # 0x1bc06
cmovneq %rax, %rdi
callq 0x3590
movq %rax, 0x18(%rbx)
movq (%rsp), %rdi
callq 0x3590
movq %rax, 0x70(%rbx)
movabsq $-0xfffffffd, %rax      # imm = 0xFFFFFFFF00000003
movq %rax, (%rbx)
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
movq $0x0, 0x60(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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, 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 %rbx
pushq %rax
testq %rdx, %rdx
je 0x156a5
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebp
xorl %ebx, %ebx
movl %ebp, %edi
movl $0x1, %esi
callq 0x15965
testl %eax, %eax
jle 0x156a7
leaq (%r15,%rbx), %rsi
movl %ebp, %edi
movq %r14, %rdx
callq 0x32b0
testq %rax, %rax
je 0x156a7
addq %rax, %rbx
subq %rax, %r14
jne 0x15678
jmp 0x156a7
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 0x15789
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x5bc8(%rip), %rsi      # 0x1b297
movl $0x6, %edx
callq 0x30c0
testl %eax, %eax
je 0x15735
leaq 0x5bba(%rip), %rsi      # 0x1b29e
movl $0x7, %edx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
testl %eax, %eax
je 0x1575f
xorl %esi, %esi
xorl %eax, %eax
callq 0x3460
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x15798
movl $0x1, %edi
movl $0x80, %esi
callq 0x32e0
movq %rax, %rbx
movl $0x1, (%rax)
movl %ebp, 0x4(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
jne 0x15774
jmp 0x1578e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x15015
testq %rax, %rax
je 0x1578e
movq %rax, %rbx
movq %rax, %rdi
callq 0x14d0c
cmpl $-0x1, %eax
je 0x1577f
movq %rbx, %rdi
callq 0x15157
jmp 0x15774
callq 0x15316
testq %rax, %rax
je 0x1578e
movq %rax, %rbx
movq %rax, %rdi
callq 0x154af
testq %rbx, %rbx
je 0x15790
cmpl $-0x1, 0x4(%rbx)
jne 0x15790
movq %rbx, %rdi
callq 0x157a8
jmp 0x1578e
callq 0x4275
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x6502(%rip), %rdi      # 0x1bca1
callq 0x34d0
xorl %ebx, %ebx
jmp 0x1572e
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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 0x1580a
pushq %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
cmpl $-0x1, %edi
je 0x157be
callq 0x3270
movl 0x4(%rbx), %edi
cmpl $-0x1, %edi
je 0x157cb
callq 0x3270
movq 0x10(%rbx), %rdi
callq 0x3060
movq 0x18(%rbx), %rdi
callq 0x3060
movq 0x48(%rbx), %rdi
callq 0x3060
movq 0x50(%rbx), %rdi
callq 0x3060
movq 0x70(%rbx), %rdi
callq 0x3060
movq 0x78(%rbx), %rdi
callq 0x3060
movq %rbx, %rdi
callq 0x3060
popq %rbx
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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
movl $0x1, %edi
movl $0x80, %esi
callq 0x32e0
movl $0x1, (%rax)
movl %ebx, 0x4(%rax)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/knetfile.c
// Function: knet_read
off_t knet_read(knetFile *fp, void *buf, off_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
		off_t rest = len, curr;
		while (rest) {
			do {
				curr = read(fp->fd, 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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $-0x1, 0x4(%rdi)
je 0x1586c
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl (%rdi), %eax
cmpl $0x3, %eax
je 0x15871
cmpl $0x2, %eax
jne 0x1587f
cmpl $0x0, 0x40(%rbx)
jne 0x1587f
cmpl $0x0, 0x3c(%rbx)
jne 0x15862
movq %rbx, %rdi
callq 0x14fe5
movq %rbx, %rdi
callq 0x15157
jmp 0x1587f
xorl %r12d, %r12d
jmp 0x158d9
cmpl $0x0, 0x40(%rbx)
jne 0x1587f
movq %rbx, %rdi
callq 0x154af
cmpl $0x1, (%rbx)
jne 0x158bb
xorl %r12d, %r12d
testq %r14, %r14
je 0x158cc
leaq (%r15,%r12), %r13
movl 0x4(%rbx), %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x32b0
testq %rax, %rax
jns 0x158af
callq 0x3090
cmpl $0x4, (%rax)
je 0x15890
jmp 0x158d2
je 0x158cc
addq %rax, %r12
subq %rax, %r14
jne 0x1588c
jmp 0x158cc
movl 0x4(%rbx), %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x15662
movq %rax, %r12
addq %r12, 0x8(%rbx)
jmp 0x158d9
movq $-0x1, %r12
movq %r12, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/knetfile.c
// Function: knet_seek
off_t knet_seek(knetFile *fp, int64_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) {
            // Be silent, it is OK for knet_seek to fail when the file is streamed
            // fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
			return -1;
		}
		fp->offset = offset;
		return 0;
	}
    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;
		fp->is_ready = 0;
		return 0;
	} 
    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;
		fp->is_ready = 0;
		return 0;
	}
	errno = EINVAL;
    fprintf(stderr,"[knet_seek] %s\n", strerror(errno));
	return -1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
testl %edx, %edx
jne 0x158f4
cmpq %rsi, 0x8(%rbx)
je 0x1594c
movl (%rbx), %eax
cmpl $0x3, %eax
je 0x15919
cmpl $0x2, %eax
je 0x15929
cmpl $0x1, %eax
jne 0x15950
movl 0x4(%rbx), %edi
callq 0x3550
cmpq $-0x1, %rax
je 0x1595c
movq %rax, 0x8(%rbx)
jmp 0x1594c
cmpl $0x1, %edx
je 0x1592e
cmpl $0x2, %edx
je 0x15957
testl %edx, %edx
jne 0x15945
jmp 0x15941
cmpl $0x1, %edx
jne 0x15934
addq %rsi, 0x8(%rbx)
jmp 0x15945
testl %edx, %edx
je 0x15941
cmpl $0x2, %edx
jne 0x15945
addq 0x68(%rbx), %rsi
movq %rsi, 0x8(%rbx)
movl $0x0, 0x40(%rbx)
xorl %eax, %eax
popq %rbx
retq
callq 0x42be
jmp 0x1595c
callq 0x4291
movq $-0x1, %rax
jmp 0x1594e
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/knetfile.c
// Function: socket_wait
static int socket_wait(int fd, int is_read)
{
	fd_set fds, *fdr = 0, *fdw = 0;
	struct timeval tv;
	int ret;
	tv.tv_sec = 5; tv.tv_usec = 0; // 5 seconds time out
	FD_ZERO(&fds);
	FD_SET(fd, &fds);
	if (is_read) fdr = &fds;
	else fdw = &fds;
	ret = select(fd+1, fdr, fdw, 0, &tv);
#ifndef _WIN32
	if (ret == -1) perror("select");
#else
	if (ret == 0)
		fprintf(stderr, "select time-out\n");
	else if (ret == SOCKET_ERROR)
		fprintf(stderr, "select: %d\n", WSAGetLastError());
#endif
	return ret;
}

// Assembly:
pushq %rbx
subq $0x90, %rsp
movl %esi, %eax
movq %rsp, %r8
movq $0x5, (%r8)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x40(%rsi)
movaps %xmm0, 0x50(%rsi)
leal 0x3f(%rdi), %edx
testl %edi, %edi
cmovnsl %edi, %edx
movl %edx, %r9d
andl $-0x40, %r9d
movl %edi, %ecx
subl %r9d, %ecx
movl $0x1, %r9d
shlq %cl, %r9
movaps %xmm0, 0x60(%rsi)
movaps %xmm0, 0x70(%rsi)
sarl $0x6, %edx
movslq %edx, %rcx
orq %r9, 0x10(%rsp,%rcx,8)
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmoveq %rsi, %rdx
movq $0x0, 0x8(%r8)
cmoveq %rcx, %rsi
incl %edi
xorl %ecx, %ecx
callq 0x33a0
movl %eax, %ebx
cmpl $-0x1, %eax
je 0x159fc
movl %ebx, %eax
addq $0x90, %rsp
popq %rbx
retq
leaq 0x631f(%rip), %rdi      # 0x1bd22
callq 0x34d0
jmp 0x159f1
nop
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header_free
void sam_header_free(void *_header)
{
	HeaderDict *header = (HeaderDict*)_header;
    list_t *hlines = header;
    while (hlines)
    {
        sam_header_line_free(hlines->data);
        hlines = hlines->next;
    }
    list_free(header);
}

// Assembly:
testq %rdi, %rdi
je 0x15a96
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq %rdi, %r12
movq 0x10(%r12), %r14
movq 0x8(%r14), %r13
testq %r13, %r13
je 0x15a4d
movq 0x10(%r13), %r15
movq 0x8(%r15), %rdi
callq 0x3060
movq %r15, %rdi
callq 0x3060
movq 0x8(%r13), %r13
jmp 0x15a2d
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x15a67
movq 0x8(%rdi), %r15
callq 0x3060
movq %r15, %rdi
testq %r15, %r15
jne 0x15a56
movq %r14, %rdi
callq 0x3060
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x15a24
movq 0x8(%rbx), %r14
movq %rbx, %rdi
callq 0x3060
movq %r14, %rbx
testq %r14, %r14
jne 0x15a79
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header_clone
HeaderDict *sam_header_clone(const HeaderDict *dict)
{
    HeaderDict *out = NULL;
    while (dict)
    {
        HeaderLine *hline = dict->data;
        out = list_append(out, sam_header_line_clone(hline));
        dict = dict->next;
    }
    return out;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x15ac8
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x10(%rbx), %rdi
callq 0x15b27
movq %r14, %rdi
movq %rax, %rsi
callq 0x15ad6
movq %rax, %r14
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
jne 0x15aa6
jmp 0x15acb
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: list_append
static list_t *list_append(list_t *root, void *data)
{
    list_t *l = root;
    while (l && l->next)
        l = l->next;
    if ( l ) 
    {
        l->next = malloc(sizeof(list_t));
        l = l->next;
    }
    else
    {
        l = malloc(sizeof(list_t));
        root = l;
    }
    l->data = data;
    l->next = NULL;
    return root;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq %rdi, %rax
testq %rax, %rax
je 0x15b05
movq %rax, %r15
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x15ae4
movl $0x18, %edi
callq 0x33e0
movq %rax, 0x8(%r15)
jmp 0x15b12
movl $0x18, %edi
callq 0x33e0
movq %rax, %r14
movq %rbx, 0x10(%rax)
movq $0x0, 0x8(%rax)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header_line_clone
static HeaderLine *sam_header_line_clone(const HeaderLine *hline)
{
    list_t *tags;
    HeaderLine *out = malloc(sizeof(HeaderLine));
    out->type[0] = hline->type[0];
    out->type[1] = hline->type[1];
    out->tags = NULL;

    tags = hline->tags;
    while (tags)
    {
        HeaderTag *old = tags->data;

        HeaderTag *new = malloc(sizeof(HeaderTag));
        new->key[0] = old->key[0];
        new->key[1] = old->key[1];
        new->value  = strdup(old->value);
        out->tags = list_append(out->tags, new);

        tags = tags->next;
    }
    return out;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r14
movl $0x10, %edi
callq 0x33e0
movq %rax, %rbx
movb (%r14), %al
movb %al, (%rbx)
movb 0x1(%r14), %al
movb %al, 0x1(%rbx)
movq 0x8(%r14), %r12
xorl %r14d, %r14d
testq %r12, %r12
je 0x15b9b
movq 0x10(%r12), %r13
movl $0x10, %edi
callq 0x33e0
movq %rax, %r15
movb (%r13), %al
movb %al, (%r15)
movb 0x1(%r13), %al
movb %al, 0x1(%r15)
movq 0x8(%r13), %rdi
callq 0x3590
movq %rax, 0x8(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x15ad6
movq %rax, %r14
movq 0x8(%r12), %r12
jmp 0x15b53
movq %r14, 0x8(%rbx)
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header_write
char *sam_header_write(const void *_header)
{
	const HeaderDict *header = (const HeaderDict*)_header;
    char *out = NULL;
    int len=0, nout=0;
    const list_t *hlines;

    // Calculate the length of the string to allocate
    hlines = header;
    while (hlines)
    {
        len += 4;   // @XY and \n

        HeaderLine *hline = hlines->data;
        list_t *tags = hline->tags;
        while (tags)
        {
            HeaderTag *tag = tags->data;
            len += strlen(tag->value) + 1;                  // \t
            if ( tag->key[0]!=' ' || tag->key[1]!=' ' )
                len += strlen(tag->value) + 3;              // XY:
            tags = tags->next;
        }
        hlines = hlines->next;
    }

    nout = 0;
    out  = malloc(len+1);
    hlines = header;
    while (hlines)
    {
        HeaderLine *hline = hlines->data;

        nout += sprintf(out+nout,"@%c%c",hline->type[0],hline->type[1]);

        list_t *tags = hline->tags;
        while (tags)
        {
            HeaderTag *tag = tags->data;
            nout += sprintf(out+nout,"\t");
            if ( tag->key[0]!=' ' || tag->key[1]!=' ' )
                nout += sprintf(out+nout,"%c%c:", tag->key[0],tag->key[1]);
            nout += sprintf(out+nout,"%s", tag->value);
            tags = tags->next;
        }
        hlines = hlines->next;
        nout += sprintf(out+nout,"\n");
    }
    out[len] = 0;
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r12
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x15c06
movq %r12, %r14
addl $0x4, %ebp
movq 0x10(%r14), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x15bfd
movq 0x10(%rbx), %r15
movq 0x8(%r15), %rdi
callq 0x31e0
addl %eax, %ebp
incl %ebp
cmpb $0x20, (%r15)
jne 0x15bf2
cmpb $0x20, 0x1(%r15)
je 0x15bf7
addl %eax, %ebp
addl $0x3, %ebp
movq 0x8(%rbx), %rbx
jmp 0x15bcf
movq 0x8(%r14), %r14
testq %r14, %r14
jne 0x15bc4
leal 0x1(%rbp), %eax
movslq %eax, %rdi
callq 0x33e0
movq %rax, %r14
testq %r12, %r12
je 0x15cc9
xorl %eax, %eax
movq %r12, (%rsp)
movq 0x10(%r12), %r15
movslq %eax, %rbx
leaq (%r14,%rbx), %rdi
movsbl (%r15), %edx
movsbl 0x1(%r15), %ecx
leaq 0x6189(%rip), %rsi      # 0x1bdc8
xorl %eax, %eax
callq 0x3510
addl %eax, %ebx
movq 0x8(%r15), %r15
testq %r15, %r15
je 0x15cab
movq 0x10(%r15), %r12
movslq %ebx, %rbx
movw $0x9, (%r14,%rbx)
incl %ebx
movsbl (%r12), %edx
cmpl $0x20, %edx
jne 0x15c73
cmpb $0x20, 0x1(%r12)
je 0x15c90
movslq %ebx, %rbx
leaq (%r14,%rbx), %rdi
movsbl 0x1(%r12), %ecx
leaq 0x6147(%rip), %rsi      # 0x1bdce
xorl %eax, %eax
callq 0x3510
addl %eax, %ebx
movslq %ebx, %rbx
leaq (%r14,%rbx), %r13
movq 0x8(%r12), %rsi
movq %r13, %rdi
callq 0x31d0
subl %r13d, %eax
addl %eax, %ebx
jmp 0x15c48
movq (%rsp), %r12
movq 0x8(%r12), %r12
movslq %ebx, %rax
movw $0xa, (%r14,%rax)
incl %eax
testq %r12, %r12
jne 0x15c1f
movslq %ebp, %rax
movb $0x0, (%r14,%rax)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header2list
char **sam_header2list(const void *_dict, char type[2], char key_tag[2], int *_n)
{
	const HeaderDict *dict = (const HeaderDict*)_dict;
    const list_t *l   = dict;
    int max, n;
	char **ret;

	ret = 0; *_n = max = n = 0;
    while (l)
    {
        HeaderLine *hline = l->data;
        if ( hline->type[0]!=type[0] || hline->type[1]!=type[1] ) 
        {
            l = l->next;
            continue;
        }
        
        HeaderTag *key;
        key   = header_line_has_tag(hline,key_tag);
        if ( !key )
        {
            l = l->next;
            continue;
        }

		if (n == max) {
			max = max? max<<1 : 4;
			ret = realloc(ret, max * sizeof(void*));
		}
		ret[n++] = key->value;

        l = l->next;
    }
	*_n = n;
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, (%rsp)
movl $0x0, (%rcx)
testq %rdi, %rdi
je 0x16566
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r13d, %r13d
movq 0x10(%r12), %rdx
movb (%rdx), %sil
cmpb (%r15), %sil
jne 0x16556
movb 0x1(%rdx), %sil
cmpb 0x1(%r15), %sil
jne 0x16556
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x1651e
movq 0x10(%rdx), %rdi
movb (%rdi), %sil
cmpb (%r14), %sil
jne 0x16510
movb 0x1(%rdi), %sil
cmpb 0x1(%r14), %sil
jne 0x16510
xorl %esi, %esi
movq %rdi, %rbp
jmp 0x16517
movq 0x8(%rdx), %rdx
movb $0x1, %sil
testb %sil, %sil
jne 0x164ee
jmp 0x16520
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x16556
cmpl %ecx, %r13d
jne 0x16548
leal (%rcx,%rcx), %ebx
testl %ecx, %ecx
movl $0x4, %ecx
cmovel %ecx, %ebx
movslq %ebx, %rsi
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x3430
movl %ebx, %ecx
movq 0x8(%rbp), %rdx
movslq %r13d, %rsi
incl %r13d
movq %rdx, (%rax,%rsi,8)
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x164d3
jmp 0x1656b
xorl %r13d, %r13d
xorl %eax, %eax
movq (%rsp), %rcx
movl %r13d, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header2key_val
void *sam_header2key_val(void *iter, const char type[2], const char key_tag[2], const char value_tag[2], const char **_key, const char **_value)
{
    list_t *l = iter;
    if ( !l ) return NULL;

    while (l)
    {
        HeaderLine *hline = l->data;
        if ( hline->type[0]!=type[0] || hline->type[1]!=type[1] )
        {
            l = l->next;
            continue;
        }

        HeaderTag *key, *value;
        key   = header_line_has_tag(hline,key_tag);
        value = header_line_has_tag(hline,value_tag);
        if ( !key && !value ) 
        {
            l = l->next;
            continue;
        }

        *_key = key->value;
        *_value = value->value;
        return l->next;
    }
    return l;
}

// Assembly:
testq %rdi, %rdi
je 0x1664a
pushq %rbp
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0x1664d
movq 0x10(%rdi), %r10
movb (%r10), %r11b
cmpb (%rsi), %r11b
jne 0x16621
movb 0x1(%r10), %r11b
cmpb 0x1(%rsi), %r11b
jne 0x16621
movq 0x8(%r10), %r11
movq %r11, %rbx
testq %rbx, %rbx
je 0x165e4
movq 0x10(%rbx), %r14
movb (%r14), %bpl
cmpb (%rdx), %bpl
jne 0x165d6
movb 0x1(%r14), %bpl
cmpb 0x1(%rdx), %bpl
jne 0x165d6
xorl %ebp, %ebp
movq %r14, %r10
jmp 0x165dd
movq 0x8(%rbx), %rbx
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x165b4
jmp 0x165e7
xorl %r10d, %r10d
testq %r11, %r11
je 0x16617
movq 0x10(%r11), %r14
movb (%r14), %bpl
cmpb (%rcx), %bpl
jne 0x16609
movb 0x1(%r14), %bpl
cmpb 0x1(%rcx), %bpl
jne 0x16609
xorl %ebp, %ebp
movq %r14, %rbx
jmp 0x16610
movq 0x8(%r11), %r11
movb $0x1, %bpl
testb %bpl, %bpl
jne 0x165e7
jmp 0x16619
xorl %ebx, %ebx
movq %r10, %r11
orq %rbx, %r11
jne 0x16633
movq 0x8(%rdi), %rdi
movb $0x1, %r10b
testb %r10b, %r10b
jne 0x1658e
jmp 0x1664f
movq 0x8(%r10), %rax
movq %rax, (%r8)
movq 0x8(%rbx), %rax
movq %rax, (%r9)
movq 0x8(%rdi), %rax
xorl %r10d, %r10d
jmp 0x16628
xorl %eax, %eax
retq
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_tbl_get
const char *sam_tbl_get(void *h, const char *key)
{
	khash_t(str) *tbl = (khash_t(str)*)h;
	khint_t k;
	k = kh_get(str, tbl, key);
	return k == kh_end(tbl)? 0 : kh_val(tbl, k);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, (%rsp)
movl (%rdi), %r10d
testl %r10d, %r10d
je 0x166a5
movq %rsi, %r14
movsbl (%rsi), %edi
xorl %r8d, %r8d
movl $0x0, %ecx
testl %edi, %edi
je 0x166af
movb 0x1(%r14), %al
testb %al, %al
je 0x166ad
leaq 0x2(%r14), %rdx
movl %edi, %ecx
movl %ecx, %edi
shll $0x5, %edi
subl %ecx, %edi
movsbl %al, %ecx
addl %edi, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x1668e
jmp 0x166af
xorl %r13d, %r13d
jmp 0x1674f
movl %edi, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
movl %edx, %r15d
leal -0x1(%r10), %edi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %edx, %ebx
incl %ebx
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movl %r15d, %r13d
movq %r10, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %ebp
leal (,%r13,2), %r12d
andl $0x1e, %r12d
movl %ebp, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x16742
testb $0x1, %al
jne 0x16728
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x3300
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r10
xorl %r8d, %r8d
testl %eax, %eax
je 0x16742
addl %ebx, %r13d
cmpl %r10d, %r13d
movl %r10d, %eax
cmovbl %r8d, %eax
subl %eax, %r13d
cmpl %r15d, %r13d
jne 0x166dc
movl %r10d, %r13d
jmp 0x1674f
movl %r12d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %r10d, %r13d
cmpl %r10d, %r13d
jne 0x16758
xorl %eax, %eax
jmp 0x16767
movq (%rsp), %rax
movq 0x20(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: print_header_line
static void print_header_line(FILE *fp, HeaderLine *hline)
{
    list_t *tags = hline->tags;
    HeaderTag *tag;

    fprintf(fp, "@%c%c", hline->type[0],hline->type[1]);
    while (tags)
    {
        tag = tags->data;

        fprintf(fp, "\t");
        if ( tag->key[0]!=' ' || tag->key[1]!=' ' )
            fprintf(fp, "%c%c:", tag->key[0],tag->key[1]);
        fprintf(fp, "%s", tag->value);

        tags = tags->next;
    }
    fprintf(fp,"\n");
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rsi), %r15
movsbl (%rsi), %edx
movsbl 0x1(%rsi), %ecx
leaq 0x50a5(%rip), %rsi      # 0x1bdc8
xorl %eax, %eax
callq 0x3320
testq %r15, %r15
je 0x16d82
leaq 0x5098(%rip), %r14      # 0x1bdce
movq 0x10(%r15), %r12
movl $0x9, %edi
movq %rbx, %rsi
callq 0x3280
movsbl (%r12), %edx
cmpl $0x20, %edx
jne 0x16d59
cmpb $0x20, 0x1(%r12)
je 0x16d6c
movsbl 0x1(%r12), %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x3320
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x3240
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x16d36
movl $0xa, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3280
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: sam_header2tbl_n
char **sam_header2tbl_n(const void *dict, const char type[2], const char *tags[], int *n)
{
    int nout = 0;
    char **out = NULL;

    *n = 0;
    list_t *l = (list_t *)dict;
    if ( !l ) return NULL;

    int i, ntags = 0;
    while ( tags[ntags] ) ntags++;

    while (l)
    {
        HeaderLine *hline = l->data;
        if ( hline->type[0]!=type[0] || hline->type[1]!=type[1] )
        {
            l = l->next;
            continue;
        }
        out = (char**) realloc(out, sizeof(char*)*(nout+1)*ntags);
        for (i=0; i<ntags; i++)
        {
            HeaderTag *key = header_line_has_tag(hline, tags[i]);
            if ( !key ) 
            {
                out[nout*ntags+i] = NULL;
                continue;
            }
            out[nout*ntags+i] = key->value;
        }
        nout++;
        l = l->next;
    }
    *n = nout;
    return out;
}

// Assembly:
movl $0x0, (%rcx)
testq %rdi, %rdi
je 0x16ebb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rdi, %r12
movq %rcx, 0x10(%rsp)
movq $-0x1, %rbp
movl $0x8, %r13d
addq $-0x8, %r13
cmpq $0x0, 0x8(%r14,%rbp,8)
leaq 0x1(%rbp), %rbp
jne 0x16dcf
negq %r13
xorl %ebx, %ebx
xorl %eax, %eax
movq %rsi, 0x8(%rsp)
movq 0x10(%r12), %r15
movb (%r15), %cl
cmpb (%rsi), %cl
jne 0x16e97
movb 0x1(%r15), %cl
cmpb 0x1(%rsi), %cl
jne 0x16e97
leal 0x1(%rbx), %ecx
movl %ecx, 0x4(%rsp)
movslq %ecx, %rsi
imulq %r13, %rsi
movq %rax, %rdi
callq 0x3430
testq %rbp, %rbp
je 0x16e8c
movq 0x8(%r15), %rcx
imull %ebp, %ebx
movslq %ebx, %rdx
leaq (%rax,%rdx,8), %rdx
xorl %esi, %esi
movl 0x4(%rsp), %ebx
movq (%r14,%rsi,8), %r8
movq %rcx, %r9
testq %r9, %r9
je 0x16e6f
movq 0x10(%r9), %r11
movb (%r11), %r10b
cmpb (%r8), %r10b
jne 0x16e61
movb 0x1(%r11), %r10b
cmpb 0x1(%r8), %r10b
jne 0x16e61
xorl %r10d, %r10d
movq %r11, %rdi
jmp 0x16e68
movq 0x8(%r9), %r9
movb $0x1, %r10b
testb %r10b, %r10b
jne 0x16e3e
jmp 0x16e71
xorl %edi, %edi
testq %rdi, %rdi
je 0x16e7c
movq 0x8(%rdi), %rdi
jmp 0x16e7e
xorl %edi, %edi
movq %rdi, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rbp
jne 0x16e37
jmp 0x16e92
movl 0x4(%rsp), %ecx
movl %ecx, %ebx
movq 0x8(%rsp), %rsi
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0x16deb
movq 0x10(%rsp), %rcx
movl %ebx, (%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/sam_header.c
// Function: new_tag
static HeaderTag *new_tag(const char *name, const char *value_from, const char *value_to)
{
    HeaderTag *tag = malloc(sizeof(HeaderTag));
    int len = value_to-value_from+1;

    tag->key[0] = name[0];
    tag->key[1] = name[1];
    tag->value = malloc(len+1);
    memcpy(tag->value,value_from,len+1);
    tag->value[len] = 0;
    return tag;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movl $0x10, %edi
callq 0x33e0
movq %rax, %r14
subl %r15d, %ebx
movb (%r12), %al
movb %al, (%r14)
movb 0x1(%r12), %al
movb %al, 0x1(%r14)
shlq $0x20, %rbx
movabsq $0x200000000, %r12      # imm = 0x200000000
addq %rbx, %r12
sarq $0x20, %r12
movq %r12, %rdi
callq 0x33e0
movq %rax, %r13
movq %rax, 0x8(%r14)
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3370
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rbx, %rax
sarq $0x20, %rax
movb $0x0, (%r13,%rax)
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq