LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x32d0
cltq
addq %r15, %rax
decq %rax
movq %rax, %rbx
cmpq %r15, %rax
jb 0x1b6f4
leaq -0x1(%rbx), %rax
cmpb $0x2f, (%rbx)
jne 0x1b6e3
incq %rbx
leaq 0xb9c9(%rip), %rsi      # 0x270c7
movq %rbx, %rdi
callq 0x35f0
movq %rax, %r12
testq %rax, %rax
je 0x1b71d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x84c3(%rip), %rsi      # 0x23be7
movq %r15, %rdi
callq 0x1c952
testq %rax, %rax
je 0x1b7cb
movq %rax, %r14
leaq 0x921e(%rip), %rsi      # 0x2495d
movq %rbx, %rdi
callq 0x35f0
testq %rax, %rax
je 0x1b7ee
movq %rax, %r15
movl $0x100000, %edi         # imm = 0x100000
movl $0x1, %esi
callq 0x3530
movq %rax, %r12
movl $0x100000, %edx         # imm = 0x100000
movq %r14, %rdi
movq %rax, %rsi
callq 0x1cabb
testl %eax, %eax
je 0x1b799
movslq %eax, %rdx
movl $0x1, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x3600
movl $0x100000, %edx         # imm = 0x100000
movq %r14, %rdi
movq %r12, %rsi
jmp 0x1b770
movq %r12, %rdi
callq 0x32c0
movq %r15, %rdi
callq 0x3560
movq %r14, %rdi
callq 0x1ca39
leaq 0xb90f(%rip), %rsi      # 0x270c7
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x35f0
movq 0x12816(%rip), %rax     # 0x2dfe8
movq (%rax), %rdi
leaq 0xac79(%rip), %rsi      # 0x26455
xorl %r12d, %r12d
movq %r15, %rdx
xorl %eax, %eax
callq 0x3630
jmp 0x1b70e
movq 0x127f3(%rip), %rax     # 0x2dfe8
movq (%rax), %rdi
leaq 0xac8a(%rip), %rsi      # 0x26489
xorl %r12d, %r12d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3630
movq %r14, %rdi
callq 0x1ca39
jmp 0x1b70e
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x32d0
leaq 0x5(%rax), %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, %r14
leaq 0xabb7(%rip), %rsi      # 0x263f8
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3350
leaq 0xa201(%rip), %rsi      # 0x25a56
movl $0x6, %edx
movq %rbx, %rdi
callq 0x31c0
testl %eax, %eax
je 0x1b8aa
leaq 0xa1f0(%rip), %rsi      # 0x25a5d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x31c0
testl %eax, %eax
je 0x1b8aa
leaq 0x8362(%rip), %rsi      # 0x23be7
movq %r14, %rdi
callq 0x35f0
testq %rax, %rax
jne 0x1b8b7
movq %rsp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c7a
testb $0x1, %al
je 0x1b90d
movq (%rsp), %r12
jmp 0x1b8ba
movq %r14, %rdi
callq 0x1b6cb
testq %rax, %rax
je 0x1b905
movq %rax, %r12
movq %r12, %rdi
callq 0x1b502
movq %rax, %r15
movq %r12, %rdi
callq 0x3560
leaq 0x8313(%rip), %rsi      # 0x23be7
movq %rbx, %rdi
callq 0x21f77
movq %rax, %rbx
movq %rax, (%r15)
movq %r14, %rdi
callq 0x32c0
testq %rbx, %rbx
je 0x1b8fe
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x4cf7
jmp 0x1b90d
movq %r14, %rdi
callq 0x4d13
xorl %r15d, %r15d
jmp 0x1b8ef
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1bd49
movl %edi, %ebp
cmpl $0x1, %edi
je 0x1bd56
movq 0x8(%rbx), %rdi
callq 0x1b819
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1bd5b
movl %ebp, %eax
movq %rax, 0x18(%rsp)
movl $0x2, %r15d
movq %rbx, 0x20(%rsp)
movq (%rbx,%r15,8), %rsi
leaq 0xa8de(%rip), %rdi      # 0x26593
xorl %eax, %eax
callq 0x3040
movq (%rbx,%r15,8), %rsi
movq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x1b912
movq %rax, 0x10(%rsp)
movslq 0x4(%rsp), %rbx
testq %rbx, %rbx
jle 0x1bd20
movq 0x10(%rsp), %r13
xorl %r14d, %r14d
movq %rbx, %r12
subq %r14, %r12
jle 0x1bd09
xorl %ebp, %ebp
movsbl (%r13,%rbp), %edi
callq 0x3170
cmpq $0x3a, %rbp
ja 0x1bd09
incq %rbp
cmpq %r12, %rbp
jb 0x1bcf0
movl $0xa, %edi
callq 0x3170
addq $0x3c, %r14
addq $0x3c, %r13
cmpq %rbx, %r14
jb 0x1bce6
movq 0x10(%rsp), %rdi
callq 0x32c0
incq %r15
cmpq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbx
jne 0x1bcaa
movq 0x8(%rsp), %rdi
callq 0x1b2fd
jmp 0x1bd52
movq 0x8(%rbx), %rdi
callq 0x1b611
xorl %eax, %eax
jmp 0x1bd60
callq 0x4d3b
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1c020
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x1c019
movq %rbx, %rdi
callq 0x1c115
leaq 0xa640(%rip), %rsi      # 0x26620
movq %rbx, %rdi
movl $0x1, %edx
callq 0x1c244
leaq 0xa63d(%rip), %rsi      # 0x26631
movq %rbx, %rdi
movl $0x1, %edx
callq 0x1c244
leaq 0xa636(%rip), %rsi      # 0x2663e
movq %rbx, %rdi
movl $0x1, %edx
callq 0x1c244
xorl %eax, %eax
jmp 0x1c01e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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;
	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 %r14
pushq %rbx
subq $0x58, %rsp
movl $0x1, %eax
movl %eax, 0x14(%rsp)
movq $0x0, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl %eax, 0x8(%rdx)
leaq 0x8(%rsp), %rcx
callq 0x3160
testl %eax, %eax
jne 0x1c0e4
movq 0x8(%rsp), %rax
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x3450
cmpl $-0x1, %eax
je 0x1c0ed
movl %eax, %ebx
leaq 0x14(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x31f0
leaq 0xa701(%rip), %r14      # 0x2679f
cmpl $-0x1, %eax
je 0x1c0f4
leaq 0x18(%rsp), %rcx
movl %ebx, %edi
movl $0x1, %esi
movl $0xd, %edx
movl $0x8, %r8d
callq 0x31f0
cmpl $-0x1, %eax
je 0x1c0f4
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
movl %ebx, %edi
callq 0x3420
testl %eax, %eax
je 0x1c101
leaq 0xa6c8(%rip), %r14      # 0x267aa
jmp 0x1c0f4
leaq 0xa6a1(%rip), %r14      # 0x2678c
jmp 0x1c0f4
leaq 0xa6a4(%rip), %r14      # 0x26798
movq %r14, %rdi
callq 0x3620
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x32b0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1cbfa
testl %eax, %eax
jle 0x1c22f
movl 0x20(%rbx), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x31b0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1c232
xorl %r12d, %r12d
leaq 0xf(%rsp), %r15
movl $0x100, %ebp            # imm = 0x100
movl 0x38(%rbx), %ecx
movq 0x48(%rbx), %rax
cmpl %ecx, %r12d
jl 0x1c18f
leal (%rcx,%rcx), %edx
testl %ecx, %ecx
cmovel %ebp, %edx
movl %edx, 0x38(%rbx)
movslq %edx, %rsi
movq %rax, %rdi
callq 0x3610
movq %rax, 0x48(%rbx)
movb 0xf(%rsp), %cl
leal 0x1(%r12), %r13d
movslq %r12d, %rdx
movb %cl, (%rax,%rdx)
cmpb $0xa, %cl
jne 0x1c1ae
cmpl $0x3, %r12d
jge 0x1c1c8
xorl %r12d, %r12d
jmp 0x1c1b1
movl %r13d, %r12d
movl 0x20(%rbx), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x31b0
testq %rax, %rax
jne 0x1c169
jmp 0x1c205
callq 0x3310
movq (%rax), %rcx
movq 0x48(%rbx), %rax
movsbq (%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1c1a9
movsbq 0x1(%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1c1a9
movsbq 0x2(%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
je 0x1c1a9
cmpb $0x2d, 0x3(%rax)
movl $0x0, %r12d
je 0x1c1b1
jmp 0x1c212
cmpl $0x2, %r12d
jl 0x1c232
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 0x3400
movq %rax, %r14
jmp 0x1c232
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1c2b4
callq 0x3090
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
movl 0x4(%rbx), %edi
callq 0x3090
movl $0xffffffff, 0x4(%rbx)  # imm = 0xFFFFFFFF
movq %rbx, %rdi
popq %rbx
jmp 0x1bfb8
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x9772(%rip), %rsi      # 0x25a56
movl $0x6, %edx
callq 0x31c0
testl %eax, %eax
je 0x1c307
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 0x1c2f2
cmpl $0x2f, %eax
je 0x1c32f
incq %rbx
addq %rbp, %r13
jmp 0x1c31b
movl $0x1, %edi
movl $0x80, %esi
callq 0x3530
movq %rax, %r14
movabsq $-0xfffffffe, %rax      # imm = 0xFFFFFFFF00000002
movq %rax, (%r14)
leaq 0xa2f2(%rip), %rdi      # 0x26647
callq 0x34b0
movq %rax, 0x18(%r14)
addq %r13, %rbp
sarq $0x20, %rbp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x3530
movq %rax, %rbp
movq %rax, 0x10(%r14)
movq %r12, %rdi
movl $0x63, %esi
callq 0x3440
testq %rax, %rax
je 0x1c393
movl $0x1, 0x3c(%r14)
sarq $0x20, %r13
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3580
movq %rbx, %rdi
callq 0x32d0
leaq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x50(%r14)
leaq 0xa284(%rip), %rsi      # 0x2664a
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3350
movq %rbx, %rdi
callq 0x32d0
leaq 0x8(%rax), %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x58(%r14)
leaq 0xa260(%rip), %rsi      # 0x26654
movq %rax, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3350
jmp 0x1c2f5
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x9483(%rip), %rsi      # 0x25a5d
movl $0x7, %edx
callq 0x31c0
testl %eax, %eax
je 0x1c5ef
xorl %ebx, %ebx
jmp 0x1c74a
movabsq $0x100000000, %rbp      # imm = 0x100000000
leaq 0x7(%rbx), %r13
xorl %r12d, %r12d
movq %r13, %r15
movzbl (%r15), %r14d
testl %r14d, %r14d
je 0x1c61a
cmpl $0x2f, %r14d
je 0x1c61a
incq %r15
addq %rbp, %r12
jmp 0x1c603
movq %rbx, (%rsp)
movl $0x1, %edi
movl $0x80, %esi
callq 0x3530
movq %rax, %rbx
addq %r12, %rbp
sarq $0x20, %rbp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x3530
movq %rax, %rbp
movq %rax, 0x78(%rbx)
sarq $0x20, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x3580
movb $0x0, (%rbp,%r12)
movq %rbp, %r13
movzbl (%r13), %eax
testl %eax, %eax
je 0x1c681
cmpl $0x3a, %eax
je 0x1c679
incq %r13
jmp 0x1c666
movb $0x0, (%r13)
incq %r13
leaq 0xa003(%rip), %rdi      # 0x2668b
callq 0x3480
testq %rax, %rax
je 0x1c6e1
movq %rax, %r12
leaq 0x93c1(%rip), %rsi      # 0x25a5d
movl $0x7, %edx
movq %rax, %rdi
callq 0x31c0
leaq 0x7(%r12), %rdi
testl %eax, %eax
cmovneq %r12, %rdi
callq 0x34b0
movq %rax, 0x10(%rbx)
incq %rax
movzbl -0x1(%rax), %ecx
testl %ecx, %ecx
je 0x1c719
cmpl $0x3a, %ecx
jne 0x1c6bd
movb $0x0, -0x1(%rax)
cmpb $0x0, (%rax)
leaq 0x9fbb(%rip), %rdi      # 0x26696
cmovneq %rax, %rdi
jmp 0x1c720
movq %rbp, %rdi
callq 0x34b0
cmpb $0x0, (%r13)
movq %rax, 0x10(%rbx)
leaq 0x9f9d(%rip), %rdi      # 0x26696
cmovneq %r13, %rdi
callq 0x34b0
movq %rax, 0x18(%rbx)
testb %r14b, %r14b
leaq 0x934b(%rip), %rax      # 0x25a5b
cmoveq %rax, %r15
movq %r15, %rdi
jmp 0x1c72d
leaq 0x9f76(%rip), %rdi      # 0x26696
callq 0x34b0
movq %rax, 0x18(%rbx)
movq (%rsp), %rdi
callq 0x34b0
movq %rax, 0x70(%rbx)
movabsq $-0xfffffffd, %rax      # imm = 0xFFFFFFFF00000003
movq %rax, (%rbx)
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
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_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1c942
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebp
xorl %ebx, %ebx
movl %ebp, %edi
movl $0x1, %esi
callq 0x1cbfa
testl %eax, %eax
jle 0x1c944
leaq (%r15,%rbx), %rsi
movl %ebp, %edi
movq %r14, %rdx
callq 0x31b0
testq %rax, %rax
je 0x1c944
addq %rax, %rbx
subq %rax, %r14
jne 0x1c915
jmp 0x1c944
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1ca24
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x90ea(%rip), %rsi      # 0x25a56
movl $0x6, %edx
callq 0x31c0
testl %eax, %eax
je 0x1c9cd
leaq 0x90dc(%rip), %rsi      # 0x25a5d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x31c0
movq %rbx, %rdi
testl %eax, %eax
je 0x1c9f7
xorl %esi, %esi
xorl %eax, %eax
callq 0x33b0
cmpl $-0x1, %eax
je 0x1ca2b
movl %eax, %ebp
movl $0x1, %edi
movl $0x80, %esi
callq 0x3530
movq %rax, %rbx
movl $0x1, (%rax)
movl %ebp, 0x4(%rax)
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
jmp 0x1ca0c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c2cc
testq %rax, %rax
je 0x1ca1a
movq %rax, %rbx
movq %rax, %rdi
callq 0x1bfb8
cmpl $-0x1, %eax
je 0x1ca12
movq %rbx, %rdi
callq 0x1c406
jmp 0x1ca0c
callq 0x1c5c5
testq %rax, %rax
je 0x1ca1a
movq %rax, %rbx
movq %rax, %rdi
callq 0x1c75c
cmpl $-0x1, 0x4(%rbx)
jne 0x1ca1c
movq %rbx, %rdi
callq 0x1ca39
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
callq 0x4e03
jmp 0x1ca1a
leaq 0x9cff(%rip), %rdi      # 0x26731
callq 0x3620
jmp 0x1ca1a
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1ca9b
pushq %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
cmpl $-0x1, %edi
je 0x1ca4f
callq 0x3090
movl 0x4(%rbx), %edi
cmpl $-0x1, %edi
je 0x1ca5c
callq 0x3090
movq 0x10(%rbx), %rdi
callq 0x32c0
movq 0x18(%rbx), %rdi
callq 0x32c0
movq 0x48(%rbx), %rdi
callq 0x32c0
movq 0x50(%rbx), %rdi
callq 0x32c0
movq 0x70(%rbx), %rdi
callq 0x32c0
movq 0x78(%rbx), %rdi
callq 0x32c0
movq %rbx, %rdi
callq 0x32c0
popq %rbx
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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
movq %rdi, %rbx
movl 0x4(%rdi), %edi
cmpl $-0x1, %edi
je 0x1caff
movq %rdx, %r14
movq %rsi, %r15
movl (%rbx), %eax
cmpl $0x3, %eax
je 0x1cb04
cmpl $0x2, %eax
jne 0x1cb14
cmpl $0x0, 0x40(%rbx)
jne 0x1cb53
cmpl $0x0, 0x3c(%rbx)
jne 0x1caf5
movq %rbx, %rdi
callq 0x1c29c
movq %rbx, %rdi
callq 0x1c406
jmp 0x1cb12
xorl %r12d, %r12d
jmp 0x1cb65
cmpl $0x0, 0x40(%rbx)
jne 0x1cb53
movq %rbx, %rdi
callq 0x1c75c
movl (%rbx), %eax
cmpl $0x1, %eax
jne 0x1cb50
xorl %r12d, %r12d
testq %r14, %r14
je 0x1cb61
leaq (%r15,%r12), %r13
movl 0x4(%rbx), %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x31b0
testq %rax, %rax
jns 0x1cb44
callq 0x34a0
cmpl $0x4, (%rax)
je 0x1cb25
jmp 0x1cb72
je 0x1cb61
addq %rax, %r12
subq %rax, %r14
jne 0x1cb21
jmp 0x1cb61
movl 0x4(%rbx), %edi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1c8ff
movq %rax, %r12
addq %r12, 0x8(%rbx)
movq %r12, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq $-0x1, %r12
jmp 0x1cb65
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1cb89
cmpq %rsi, 0x8(%rbx)
je 0x1cbe1
movl (%rbx), %eax
cmpl $0x3, %eax
je 0x1cbae
cmpl $0x2, %eax
je 0x1cbbe
cmpl $0x1, %eax
jne 0x1cbe5
movl 0x4(%rbx), %edi
callq 0x3590
cmpq $-0x1, %rax
je 0x1cbf1
movq %rax, 0x8(%rbx)
jmp 0x1cbe1
cmpl $0x1, %edx
je 0x1cbc3
cmpl $0x2, %edx
je 0x1cbec
testl %edx, %edx
jne 0x1cbda
jmp 0x1cbd6
cmpl $0x1, %edx
jne 0x1cbc9
addq %rsi, 0x8(%rbx)
jmp 0x1cbda
testl %edx, %edx
je 0x1cbd6
cmpl $0x2, %edx
jne 0x1cbda
addq 0x68(%rbx), %rsi
movq %rsi, 0x8(%rbx)
movl $0x0, 0x40(%rbx)
xorl %eax, %eax
popq %rbx
retq
callq 0x4e4c
jmp 0x1cbf1
callq 0x4e1f
movq $-0x1, %rax
jmp 0x1cbe3
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_sort.c
// Function: heap_lt
static inline int heap_lt(const heap1_t a, const heap1_t b)
{
	if (g_is_by_qname) {
		int t;
		if (a.b == 0 || b.b == 0) return a.b == 0? 1 : 0;
		t = strnum_cmp(bam1_qname(a.b), bam1_qname(b.b));
		return (t > 0 || (t == 0 && __pos_cmp(a, b)));
	} else return __pos_cmp(a, b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
cmpl $0x0, 0x122cf(%rip)     # 0x2f324
je 0x1d125
movq 0x18(%rsi), %rcx
testq %rcx, %rcx
sete %al
movq 0x18(%rdi), %rdx
testq %rdx, %rdx
sete %sil
orb %al, %sil
jne 0x1d188
movq 0x30(%rcx), %r12
movq 0x30(%rdx), %r15
movq %r12, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movb (%r12), %r13b
testb %r13b, %r13b
je 0x1d14e
movq %r12, %rbx
movq 0x8(%rsp), %r14
movsbq (%r14), %rbp
testq %rbp, %rbp
je 0x1d157
callq 0x3310
movq (%rax), %rax
movsbq %r13b, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x1d0c7
testb $0x8, 0x1(%rax,%rbp,2)
jne 0x1d0e2
cmpb %bpl, %r13b
jne 0x1d157
incq %rbx
movq %rbx, 0x10(%rsp)
incq %r14
movq %r14, 0x8(%rsp)
jmp 0x1d113
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x3400
movq %rax, %rbx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x3400
cmpq %rax, %rbx
jne 0x1d165
movq 0x10(%rsp), %rbx
movb (%rbx), %r13b
testb %r13b, %r13b
jne 0x1d09b
movq 0x8(%rsp), %r14
xorl %r13d, %r13d
jmp 0x1d157
movq 0x8(%rsi), %rcx
movq 0x8(%rdi), %rdx
movb $0x1, %al
cmpq %rdx, %rcx
ja 0x1d188
jne 0x1d186
movl (%rdi), %ecx
cmpl %ecx, (%rsi)
jg 0x1d188
sete %cl
movq 0x10(%rdi), %rax
cmpq %rax, 0x10(%rsi)
seta %al
andb %cl, %al
jmp 0x1d188
xorl %r13d, %r13d
movq %r15, %r14
movq %r12, %rbx
cmpb (%r14), %r13b
jne 0x1d165
subq %r12, %rbx
subq %r15, %r14
cmpq %r14, %rbx
setl %cl
setg %dl
leaq 0x50(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movb $0x1, %al
testb %cl, %cl
jne 0x1d17f
testb %dl, %dl
jne 0x1d188
orb %dl, %cl
testb $0x1, %cl
je 0x1d19a
xorl %eax, %eax
movzbl %al, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsi), %rcx
movq 0x8(%rdi), %rdx
jmp 0x1d12f
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_sort.c
// Function: bam_merge
int bam_merge(int argc, char *argv[])
{
	int c, is_by_qname = 0, add_RG = 0;
	char *fn_headers = NULL;

	while ((c = getopt(argc, argv, "h:nr")) >= 0) {
		switch (c) {
		case 'r': add_RG = 1; break;
		case 'h': fn_headers = strdup(optarg); break;
		case 'n': is_by_qname = 1; break;
		}
	}
	if (optind + 2 >= argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   samtools merge [-nr] [-h inh.sam] <out.bam> <in1.bam> <in2.bam> [...]\n\n");
		fprintf(stderr, "Options: -n       sort by read names\n");
		fprintf(stderr, "         -r       attach RG tag (inferred from file names)\n");
		fprintf(stderr, "         -h FILE  copy the header in FILE to <out.bam> [in1.bam]\n\n");
		fprintf(stderr, "Note: Samtools' merge does not reconstruct the @RG dictionary in the header. Users\n");
		fprintf(stderr, "      must provide the correct header with -h, or uses Picard which properly maintains\n");
		fprintf(stderr, "      the header dictionary in merging.\n\n");
		return 1;
	}
	bam_merge_core(is_by_qname, argv[optind], fn_headers, argc - optind - 1, argv + optind + 1, add_RG);
	free(fn_headers);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %ebx
leaq 0x8569(%rip), %rdx      # 0x26a53
callq 0x31a0
testl %eax, %eax
js 0x1e545
xorl %r15d, %r15d
leaq 0x8556(%rip), %r13      # 0x26a53
xorl %ebp, %ebp
xorl %r12d, %r12d
cmpl $0x68, %eax
je 0x1e520
cmpl $0x6e, %eax
je 0x1e518
cmpl $0x72, %eax
jne 0x1e532
movl $0x1, %ebp
jmp 0x1e532
movl $0x1, %r12d
jmp 0x1e532
movq 0xfab9(%rip), %rax      # 0x2dfe0
movq (%rax), %rdi
callq 0x34b0
movq %rax, %r15
movl %ebx, %edi
movq %r14, %rsi
movq %r13, %rdx
callq 0x31a0
testl %eax, %eax
jns 0x1e502
jmp 0x1e54d
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0xfa64(%rip), %rax      # 0x2dfb8
movslq (%rax), %rcx
leal 0x2(%rcx), %eax
cmpl %ebx, %eax
jge 0x1e595
leaq (%r14,%rcx,8), %r8
addq $0x8, %r8
movq -0x8(%r8), %rsi
notl %ecx
addl %ebx, %ecx
movl %r12d, %edi
movq %r15, %rdx
movl %ebp, %r9d
callq 0x1dd9f
movq %r15, %rdi
callq 0x32c0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4f09
movl $0x1, %eax
jmp 0x1e586
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_sort.c
// Function: bam1_lt
static inline int bam1_lt(const bam1_p a, const bam1_p b)
{
	if (g_is_by_qname) {
		int t = strnum_cmp(bam1_qname(a), bam1_qname(b));
		return (t < 0 || (t == 0 && (((uint64_t)a->core.tid<<32|a->core.pos) < ((uint64_t)b->core.tid<<32|b->core.pos))));
	} else return (((uint64_t)a->core.tid<<32|a->core.pos) < ((uint64_t)b->core.tid<<32|b->core.pos));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
cmpl $0x0, 0x10af2(%rip)     # 0x2f324
je 0x1e91d
movq 0x30(%r14), %rbp
movq %rsi, 0x10(%rsp)
movq 0x30(%rsi), %r12
movq %rbp, 0x18(%rsp)
movq %r12, 0x8(%rsp)
movb (%rbp), %r13b
testb %r13b, %r13b
movq %r12, 0x20(%rsp)
je 0x1e8e7
movq %rbp, %r15
movq 0x8(%rsp), %r12
movsbq (%r12), %rbx
testq %rbx, %rbx
je 0x1e8ed
callq 0x3310
movq (%rax), %rax
movsbq %r13b, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x1e88d
testb $0x8, 0x1(%rax,%rbx,2)
jne 0x1e8a4
cmpb %bl, %r13b
jne 0x1e8ed
incq %r15
movq %r15, 0x18(%rsp)
incq %r12
movq %r12, 0x8(%rsp)
jmp 0x1e8d5
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
movl $0xa, %edx
callq 0x3400
movq %rax, %r15
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x3400
cmpq %rax, %r15
jne 0x1e908
movq 0x18(%rsp), %r15
movb (%r15), %r13b
testb %r13b, %r13b
jne 0x1e864
movq 0x8(%rsp), %r12
xorl %r13d, %r13d
jmp 0x1e8ed
xorl %r13d, %r13d
movq %rbp, %r15
cmpb (%r12), %r13b
jne 0x1e908
subq %rbp, %r15
subq 0x20(%rsp), %r12
movl $0x1, %eax
cmpq %r12, %r15
setg %cl
jmp 0x1e910
setg %cl
movl $0x1, %eax
movq 0x10(%rsp), %rsi
jl 0x1e940
xorl %eax, %eax
testb %cl, %cl
jne 0x1e940
movl (%r14), %eax
shlq $0x20, %rax
movslq 0x4(%r14), %rcx
orq %rax, %rcx
movl (%rsi), %eax
shlq $0x20, %rax
movslq 0x4(%rsi), %rdx
orq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
setb %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_sort.c
// Function: bam_sort
int bam_sort(int argc, char *argv[])
{
	size_t max_mem = 500000000;
	int c, is_by_qname = 0, is_stdout = 0;
	while ((c = getopt(argc, argv, "nom:")) >= 0) {
		switch (c) {
		case 'o': is_stdout = 1; break;
		case 'n': is_by_qname = 1; break;
		case 'm': max_mem = atol(optarg); break;
		}
	}
	if (optind + 2 > argc) {
		fprintf(stderr, "Usage: samtools sort [-on] [-m <maxMem>] <in.bam> <out.prefix>\n");
		return 1;
	}
	bam_sort_core_ext(is_by_qname, argv[optind], argv[optind+1], max_mem, is_stdout);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x78b7(%rip), %rdx      # 0x26cb9
callq 0x31a0
testl %eax, %eax
js 0x1f462
movl $0x1dcd6500, %r15d      # imm = 0x1DCD6500
xorl %r14d, %r14d
leaq 0x789e(%rip), %r13      # 0x26cb9
xorl %r12d, %r12d
cmpl $0x6d, %eax
je 0x1f43d
cmpl $0x6e, %eax
je 0x1f435
cmpl $0x6f, %eax
jne 0x1f44f
movl $0x1, %r14d
jmp 0x1f44f
movl $0x1, %r12d
jmp 0x1f44f
movq 0xeb9c(%rip), %rax      # 0x2dfe0
movq (%rax), %rdi
callq 0x3370
movq %rax, %r15
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x31a0
testl %eax, %eax
jns 0x1f41e
jmp 0x1f46e
xorl %r12d, %r12d
movl $0x1dcd6500, %r15d      # imm = 0x1DCD6500
xorl %r14d, %r14d
movq 0xeb43(%rip), %rax      # 0x2dfb8
movslq (%rax), %rax
leal 0x2(%rax), %ecx
cmpl %ebp, %ecx
jg 0x1f4a7
movq (%rbx,%rax,8), %rsi
movq 0x8(%rbx,%rax,8), %rdx
movl %r12d, %edi
movq %r15, %rcx
movl %r14d, %r8d
callq 0x1efa1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5000
movl $0x1, %eax
jmp 0x1f498
nop
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1f4ee
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rdi, %r14
movq 0x8(%r14), %rdi
callq 0x1f4ef
movq (%r14), %r14
testq %r14, %r14
jne 0x1f4c3
movq (%rbx), %r14
movq %rbx, %rdi
callq 0x32c0
movq %r14, %rbx
testq %r14, %r14
jne 0x1f4d4
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/sam_header.c
// Function: sam_header_line_free
static void sam_header_line_free(HeaderLine *hline)
{
    list_t *tags = hline->tags;
    while (tags)
    {
        HeaderTag *tag = tags->data;
        free(tag->value);
        free(tag);
        tags = tags->next;
    }
    list_free(hline->tags);
    free(hline);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %r15
testq %r15, %r15
je 0x1f536
movq 0x8(%r15), %r14
movq 0x8(%r14), %rdi
callq 0x32c0
movq %r14, %rdi
callq 0x32c0
movq (%r15), %r15
testq %r15, %r15
jne 0x1f500
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x1f536
movq (%rdi), %r14
callq 0x32c0
movq %r14, %rdi
testq %r14, %r14
jne 0x1f526
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x32c0
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1f573
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x8(%rbx), %rdi
callq 0x1f5cf
movq %r14, %rdi
movq %rax, %rsi
callq 0x1f581
movq %rax, %r14
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1f552
jmp 0x1f576
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1f5ae
movq %rax, %r15
movq (%rax), %rax
testq %rax, %rax
jne 0x1f58f
movl $0x10, %edi
callq 0x31d0
movq %rax, (%r15)
jmp 0x1f5bb
movl $0x10, %edi
callq 0x31d0
movq %rax, %r14
movq %rbx, 0x8(%rax)
movq $0x0, (%rax)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x31d0
movq %rax, %rbx
movb (%r14), %al
movb %al, (%rbx)
movb 0x1(%r14), %al
movb %al, 0x1(%rbx)
movq $0x0, 0x8(%rbx)
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x1f651
xorl %r14d, %r14d
movq 0x8(%r12), %r13
movl $0x10, %edi
callq 0x31d0
movq %rax, %r15
movb (%r13), %al
movb %al, (%r15)
movb 0x1(%r13), %al
movb %al, 0x1(%r15)
movq 0x8(%r13), %rdi
callq 0x34b0
movq %rax, 0x8(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x1f581
movq %rax, %r14
movq (%r12), %r12
testq %r12, %r12
jne 0x1f608
movq %r14, 0x8(%rbx)
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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
movl $0x0, (%rcx)
testq %rdi, %rdi
je 0x20412
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %r8d, %r8d
movl $0x4, %r9d
xorl %eax, %eax
xorl %r13d, %r13d
movq 0x8(%r12), %rdx
movb (%rdx), %sil
cmpb (%r15), %sil
jne 0x20403
movb 0x1(%rdx), %sil
cmpb 0x1(%r15), %sil
jne 0x20403
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
je 0x20403
movb (%r14), %sil
movq 0x8(%rdx), %rbp
cmpb %sil, (%rbp)
jne 0x203bb
movb 0x1(%rbp), %dil
cmpb 0x1(%r14), %dil
je 0x203c5
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0x203a7
jmp 0x20403
cmpl %r8d, %r13d
jne 0x203f5
leal (%r8,%r8), %ebx
testl %r8d, %r8d
cmovel %r9d, %ebx
movslq %ebx, %rsi
shlq $0x3, %rsi
movq %rax, %rdi
movq %rcx, (%rsp)
callq 0x3610
movl $0x4, %r9d
movq (%rsp), %rcx
movl %ebx, %r8d
movq 0x8(%rbp), %rdx
movslq %r13d, %rsi
incl %r13d
movq %rdx, (%rax,%rsi,8)
movq (%r12), %r12
testq %r12, %r12
jne 0x20384
jmp 0x20417
xorl %r13d, %r13d
xorl %eax, %eax
movl %r13d, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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), %ebx
testl %ebx, %ebx
je 0x2047e
movq %rsi, %r14
movsbl (%rsi), %r8d
xorl %edi, %edi
movl $0x0, %ecx
testl %r8d, %r8d
je 0x20489
movb 0x1(%r14), %al
testb %al, %al
je 0x20486
leaq 0x2(%r14), %rdx
movl %r8d, %ecx
movl %ecx, %r8d
shll $0x5, %r8d
subl %ecx, %r8d
movsbl %al, %ecx
addl %r8d, %ecx
movb (%rdx), %al
incq %rdx
testb %al, %al
jne 0x20463
jmp 0x20489
xorl %r15d, %r15d
jmp 0x2051c
movl %r8d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %ebx
movl %edx, %r12d
leal -0x1(%rbx), %r8d
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
incl %edx
movq (%rsp), %rax
movq 0x10(%rax), %r8
movl %r12d, %r15d
movl %edx, 0xc(%rsp)
movq %r8, 0x10(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %ebp
leal (%r15,%r15), %r13d
andl $0x1e, %r13d
movl %ebp, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x2050f
testb $0x1, %al
jne 0x204fa
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x34e0
movq 0x10(%rsp), %r8
movl 0xc(%rsp), %edx
xorl %edi, %edi
testl %eax, %eax
je 0x2050f
addl %edx, %r15d
cmpl %ebx, %r15d
movl %ebx, %eax
cmovbl %edi, %eax
subl %eax, %r15d
cmpl %r12d, %r15d
jne 0x204b3
jmp 0x20534
movl %r13d, %ecx
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %ebx, %r15d
cmpl %ebx, %r15d
jne 0x20525
xorl %edi, %edi
jmp 0x20534
movq (%rsp), %rax
movq 0x20(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rdi, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x62e0(%rip), %rsi      # 0x26d58
xorl %eax, %eax
callq 0x3630
testq %r15, %r15
je 0x20adb
leaq 0x4a79(%rip), %r14      # 0x25504
movq 0x8(%r15), %r12
movl $0x9, %edi
movq %rbx, %rsi
callq 0x3290
movsbl (%r12), %edx
movl %edx, %ecx
xorb $0x20, %cl
movb 0x1(%r12), %al
movl %eax, %esi
xorb $0x20, %sil
orb %cl, %sil
je 0x20ac6
movsbl %al, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x3630
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x33f0
movq (%r15), %r15
testq %r15, %r15
jne 0x20a8b
movl $0xa, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3290
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %r15
movl %esi, %ebp
movl %edi, %r12d
movl $0x10, %edi
callq 0x31d0
movq %rax, %r14
subl %r15d, %ebx
movb %r12b, (%rax)
movb %bpl, 0x1(%rax)
shlq $0x20, %rbx
movabsq $0x200000000, %r12      # imm = 0x200000000
addq %rbx, %r12
sarq $0x20, %r12
movq %r12, %rdi
callq 0x31d0
movq %rax, %r13
movq %rax, 0x8(%r14)
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3680
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rbx, %rax
sarq $0x20, %rax
movb $0x0, (%r13,%rax)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/razf.c
// Function: razf_buffered_write
static void _razf_buffered_write(RAZF *rz, const void *data, int size){
	int i, n;
	while(1){
		if(rz->buf_len == RZ_BUFFER_SIZE){
			_razf_write(rz, rz->inbuf, rz->buf_len);
			rz->buf_len = 0;
		}
		if(size + rz->buf_len < RZ_BUFFER_SIZE){
			for(i=0;i<size;i++) ((char*)rz->inbuf + rz->buf_len)[i] = ((char*)data)[i];
			rz->buf_len += size;
			return;
		} else {
			n = RZ_BUFFER_SIZE - rz->buf_len;
			for(i=0;i<n;i++) ((char*)rz->inbuf + rz->buf_len)[i] = ((char*)data)[i];
			size -= n;
			data += n;
			rz->buf_len += n;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movl 0x84(%rdi), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jne 0x21d8e
movq 0x60(%rbx), %rsi
movl $0x1000, %ebp           # imm = 0x1000
movq %rbx, %rdi
movl $0x1000, %edx           # imm = 0x1000
callq 0x22bd4
movl $0x0, 0x84(%rbx)
cmpl $0xfff, %r14d           # imm = 0xFFF
jg 0x21da8
jmp 0x21dee
leal (%rax,%r14), %ecx
cmpl $0x1000, %ecx           # imm = 0x1000
jl 0x21df1
movl $0x1000, %ebp           # imm = 0x1000
subl %eax, %ebp
cmpl $0xfff, %eax            # imm = 0xFFF
jg 0x21dd6
cmpl $0x2, %ebp
movl $0x1, %eax
cmovgel %ebp, %eax
xorl %ecx, %ecx
movslq 0x84(%rbx), %rdx
addq 0x60(%rbx), %rdx
movb (%r15,%rcx), %sil
movb %sil, (%rcx,%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x21db5
movl 0x84(%rbx), %eax
subl %ebp, %r14d
movslq %ebp, %rcx
addq %rcx, %r15
addl %eax, %ecx
movl %ecx, 0x84(%rbx)
movl %ecx, %eax
jmp 0x21d5c
movl %r14d, %ecx
testl %r14d, %r14d
jle 0x21e20
movl %r14d, %eax
xorl %ecx, %ecx
movslq 0x84(%rbx), %rdx
addq 0x60(%rbx), %rdx
movb (%r15,%rcx), %sil
movb %sil, (%rcx,%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x21dfb
addl 0x84(%rbx), %r14d
movl %r14d, %ecx
movl %ecx, 0x84(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq