// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bam_sort.c
// Function: bam_merge_core
int bam_merge_core(int by_qname, const char *out, const char *headers, int n, char * const *fn,
					int flag, const char *reg)
{
	bamFile fpout, *fp;
	heap1_t *heap;
	bam_header_t *hout = 0;
	bam_header_t *hheaders = NULL;
	int i, j, *RG_len = 0;
	uint64_t idx = 0;
	char **RG = 0;
	bam_iter_t *iter = 0;

	if (headers) {
		tamFile fpheaders = sam_open(headers);
		if (fpheaders == 0) {
			const char *message = strerror(errno);
			fprintf(stderr, "[bam_merge_core] cannot open '%s': %s\n", headers, message);
			return -1;
		}
		hheaders = sam_header_read(fpheaders);
		sam_close(fpheaders);
	}

	g_is_by_qname = by_qname;
	fp = (bamFile*)calloc(n, sizeof(bamFile));
	heap = (heap1_t*)calloc(n, sizeof(heap1_t));
	iter = (bam_iter_t*)calloc(n, sizeof(bam_iter_t));
	// prepare RG tag
	if (flag & MERGE_RG) {
		RG = (char**)calloc(n, sizeof(void*));
		RG_len = (int*)calloc(n, sizeof(int));
		for (i = 0; i != n; ++i) {
			int l = strlen(fn[i]);
			const char *s = fn[i];
			if (l > 4 && strcmp(s + l - 4, ".bam") == 0) l -= 4;
			for (j = l - 1; j >= 0; --j) if (s[j] == '/') break;
			++j; l -= j;
			RG[i] = calloc(l + 1, 1);
			RG_len[i] = l;
			strncpy(RG[i], s + j, l);
		}
	}
	// read the first
	for (i = 0; i != n; ++i) {
		bam_header_t *hin;
		fp[i] = bam_open(fn[i], "r");
		if (fp[i] == 0) {
			int j;
			fprintf(stderr, "[bam_merge_core] fail to open file %s\n", fn[i]);
			for (j = 0; j < i; ++j) bam_close(fp[j]);
			free(fp); free(heap);
			// FIXME: possible memory leak
			return -1;
		}
		hin = bam_header_read(fp[i]);
		if (i == 0) { // the first BAM
			hout = hin;
		} else { // validate multiple baf
			int min_n_targets = hout->n_targets;
			if (hin->n_targets < min_n_targets) min_n_targets = hin->n_targets;

			for (j = 0; j < min_n_targets; ++j)
				if (strcmp(hout->target_name[j], hin->target_name[j]) != 0) {
					fprintf(stderr, "[bam_merge_core] different target sequence name: '%s' != '%s' in file '%s'\n",
							hout->target_name[j], hin->target_name[j], fn[i]);
					return -1;
				}

			// If this input file has additional target reference sequences,
			// add them to the headers to be output
			if (hin->n_targets > hout->n_targets) {
				swap_header_targets(hout, hin);
				// FIXME Possibly we should also create @SQ text headers
				// for the newly added reference sequences
			}

			bam_header_destroy(hin);
		}
	}

	if (hheaders) {
		// If the text headers to be swapped in include any @SQ headers,
		// check that they are consistent with the existing binary list
		// of reference information.
		if (hheaders->n_targets > 0) {
			if (hout->n_targets != hheaders->n_targets) {
				fprintf(stderr, "[bam_merge_core] number of @SQ headers in '%s' differs from number of target sequences\n", headers);
				if (!reg) return -1;
			}
			for (j = 0; j < hout->n_targets; ++j)
				if (strcmp(hout->target_name[j], hheaders->target_name[j]) != 0) {
					fprintf(stderr, "[bam_merge_core] @SQ header '%s' in '%s' differs from target sequence\n", hheaders->target_name[j], headers);
					if (!reg) return -1;
				}
		}

		swap_header_text(hout, hheaders);
		bam_header_destroy(hheaders);
	}

	if (reg) {
		int tid, beg, end;
		if (bam_parse_region(hout, reg, &tid, &beg, &end) < 0) {
			fprintf(stderr, "[%s] Malformated region string or undefined reference name\n", __func__);
			return -1;
		}
		for (i = 0; i < n; ++i) {
			bam_index_t *idx;
			idx = bam_index_load(fn[i]);
			iter[i] = bam_iter_query(idx, tid, beg, end);
			bam_index_destroy(idx);
		}
	}

	for (i = 0; i < n; ++i) {
		heap1_t *h = heap + i;
		h->i = i;
		h->b = (bam1_t*)calloc(1, sizeof(bam1_t));
		if (bam_iter_read(fp[i], iter[i], h->b) >= 0) {
			h->pos = ((uint64_t)h->b->core.tid<<32) | (uint32_t)((int32_t)h->b->core.pos+1)<<1 | bam1_strand(h->b);
			h->idx = idx++;
		}
		else h->pos = HEAP_EMPTY;
	}
	if (flag & MERGE_UNCOMP) fpout = strcmp(out, "-")? bam_open(out, "wu") : bam_dopen(fileno(stdout), "wu");
	else if (flag & MERGE_LEVEL1) fpout = strcmp(out, "-")? bam_open(out, "w1") : bam_dopen(fileno(stdout), "w1");
	else fpout = strcmp(out, "-")? bam_open(out, "w") : bam_dopen(fileno(stdout), "w");
	if (fpout == 0) {
		fprintf(stderr, "[%s] fail to create the output file.\n", __func__);
		return -1;
	}
	bam_header_write(fpout, hout);
	bam_header_destroy(hout);

	ks_heapmake(heap, n, heap);
	while (heap->pos != HEAP_EMPTY) {
		bam1_t *b = heap->b;
		if (flag & MERGE_RG) {
			uint8_t *rg = bam_aux_get(b, "RG");
			if (rg) bam_aux_del(b, rg);
			bam_aux_append(b, "RG", 'Z', RG_len[heap->i] + 1, (uint8_t*)RG[heap->i]);
		}
		bam_write1_core(fpout, &b->core, b->data_len, b->data);
		if ((j = bam_iter_read(fp[heap->i], iter[heap->i], b)) >= 0) {
			heap->pos = ((uint64_t)b->core.tid<<32) | (uint32_t)((int)b->core.pos+1)<<1 | bam1_strand(b);
			heap->idx = idx++;
		} else if (j == -1) {
			heap->pos = HEAP_EMPTY;
			free(heap->b->data); free(heap->b);
			heap->b = 0;
		} else fprintf(stderr, "[bam_merge_core] '%s' is truncated. Continue anyway.\n", fn[heap->i]);
		ks_heapadjust(heap, 0, n, heap);
	}

	if (flag & MERGE_RG) {
		for (i = 0; i != n; ++i) free(RG[i]);
		free(RG); free(RG_len);
	}
	for (i = 0; i != n; ++i) {
		bam_iter_destroy(iter[i]);
		bam_close(fp[i]);
	}
	bam_close(fpout);
	free(fp); free(heap); free(iter);
	return 0;
}

// Assembly:
subq $0xf8, %rsp
movq 0x100(%rsp), %rax
movl %edi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movl %ecx, 0xdc(%rsp)
movq %r8, 0xd0(%rsp)
movl %r9d, 0xcc(%rsp)
movq $0x0, 0xa8(%rsp)
movq $0x0, 0xa0(%rsp)
movq $0x0, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
cmpq $0x0, 0xe0(%rsp)
je 0x4868c9
movq 0xe0(%rsp), %rdi
callq 0x46e8a0
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x4868ad
callq 0x32640
movl (%rax), %edi
callq 0x319e0
movq %rax, 0x68(%rsp)
movq 0x175749(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xe0(%rsp), %rdx
movq 0x68(%rsp), %rcx
leaq 0xf495a(%rip), %rsi     # 0x57b1f0
movb $0x0, %al
callq 0x33960
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
movq 0x70(%rsp), %rdi
callq 0x46c370
movq %rax, 0xa0(%rsp)
movq 0x70(%rsp), %rdi
callq 0x46e980
movl 0xf0(%rsp), %eax
movl %eax, 0x18142e(%rip)    # 0x607d04
movslq 0xdc(%rsp), %rdi
movl $0x8, %esi
callq 0x32f50
movq %rax, 0xb8(%rsp)
movslq 0xdc(%rsp), %rdi
movl $0x20, %esi
callq 0x32f50
movq %rax, 0xb0(%rsp)
movslq 0xdc(%rsp), %rdi
movl $0x8, %esi
callq 0x32f50
movq %rax, 0x78(%rsp)
movl 0xcc(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x486ae0
movslq 0xdc(%rsp), %rdi
movl $0x8, %esi
callq 0x32f50
movq %rax, 0x80(%rsp)
movslq 0xdc(%rsp), %rdi
movl $0x4, %esi
callq 0x32f50
movq %rax, 0x90(%rsp)
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
je 0x486ade
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x30e70
movl %eax, 0x64(%rsp)
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x58(%rsp)
cmpl $0x4, 0x64(%rsp)
jle 0x4869f1
movq 0x58(%rsp), %rdi
movslq 0x64(%rsp), %rax
addq %rax, %rdi
addq $-0x4, %rdi
leaq 0xf4d6d(%rip), %rsi     # 0x57b749
callq 0x32950
cmpl $0x0, %eax
jne 0x4869f1
movl 0x64(%rsp), %eax
subl $0x4, %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x98(%rsp)
cmpl $0x0, 0x98(%rsp)
jl 0x486a36
movq 0x58(%rsp), %rax
movslq 0x98(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x486a21
jmp 0x486a36
jmp 0x486a23
movl 0x98(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x4869ff
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
movl 0x98(%rsp), %ecx
movl 0x64(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x32f50
movq %rax, %rdx
movq 0x80(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x64(%rsp), %edx
movq 0x90(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x80(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x58(%rsp), %rsi
movslq 0x98(%rsp), %rax
addq %rax, %rsi
movslq 0x64(%rsp), %rdx
callq 0x33190
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x486973
jmp 0x486ae0
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
je 0x486d5a
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x78821(%rip), %rsi     # 0x4ff33b
callq 0x464500
movq %rax, %rdx
movq 0xb8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0xb8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x486bdf
movq 0x175470(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xf46a1(%rip), %rsi     # 0x57b217
movb $0x0, %al
callq 0x33960
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x486bb5
movq 0xb8(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4646c0
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x486b85
movq 0xb8(%rsp), %rdi
callq 0x34078
movq 0xb0(%rsp), %rdi
callq 0x34078
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
movq 0xb8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4691e0
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x9c(%rsp)
jne 0x486c19
movq 0x50(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x486d42
movq 0xa8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x48(%rsp)
movq 0x50(%rsp), %rax
movl (%rax), %eax
cmpl 0x48(%rsp), %eax
jge 0x486c3f
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x48(%rsp)
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
cmpl 0x48(%rsp), %eax
jge 0x486d13
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x32950
cmpl $0x0, %eax
je 0x486cfb
movq 0x17532f(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rsi
movq (%rax,%rsi,8), %r8
leaq 0xf455a(%rip), %rsi     # 0x57b23e
movb $0x0, %al
callq 0x33960
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
jmp 0x486cfd
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x486c4a
movq 0x50(%rsp), %rax
movl (%rax), %eax
movq 0xa8(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x486d38
movq 0xa8(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x4875e0
movq 0x50(%rsp), %rdi
callq 0x469100
jmp 0x486d44
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x486aeb
cmpq $0x0, 0xa0(%rsp)
je 0x486eba
movq 0xa0(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x486e98
movq 0xa8(%rsp), %rax
movl (%rax), %eax
movq 0xa0(%rsp), %rcx
cmpl (%rcx), %eax
je 0x486dcd
movq 0x175231(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xe0(%rsp), %rdx
leaq 0xf44e1(%rip), %rsi     # 0x57b28a
movb $0x0, %al
callq 0x33960
cmpq $0x0, 0x100(%rsp)
jne 0x486dcb
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
jmp 0x486dcd
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
movq 0xa8(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x486e96
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0xa0(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x32950
cmpl $0x0, %eax
je 0x486e7e
movq 0x175198(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xa0(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0xe0(%rsp), %rcx
leaq 0xf4488(%rip), %rsi     # 0x57b2e2
movb $0x0, %al
callq 0x33960
cmpq $0x0, 0x100(%rsp)
jne 0x486e7c
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
jmp 0x486e7e
jmp 0x486e80
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x486dd8
jmp 0x486e98
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x487670
movq 0xa0(%rsp), %rdi
callq 0x469100
cmpq $0x0, 0x100(%rsp)
je 0x486fa3
movq 0xa8(%rsp), %rdi
movq 0x100(%rsp), %rsi
leaq 0x44(%rsp), %rdx
leaq 0x40(%rsp), %rcx
leaq 0x3c(%rsp), %r8
callq 0x468450
cmpl $0x0, %eax
jge 0x486f21
movq 0x1750cf(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf4426(%rip), %rsi     # 0x57b329
leaq 0xf445b(%rip), %rdx     # 0x57b365
movb $0x0, %al
callq 0x33960
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
jge 0x486fa1
movq 0xd0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x472ce0
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
callq 0x4733a0
movq %rax, %rdx
movq 0x78(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x30(%rsp), %rdi
callq 0x472020
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x486f2c
jmp 0x486fa3
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
jge 0x4870df
movq 0xb0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x9c(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, %edi
movl $0x38, %esi
callq 0x32f50
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0xb8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x78(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdx
callq 0x473cd0
cmpl $0x0, %eax
jl 0x4870ba
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movslq (%rax), %rcx
shlq $0x20, %rcx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
shll %eax
movl %eax, %eax
orq %rax, %rcx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x10, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
orq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0x28(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x4870c7
movq 0x28(%rsp), %rax
movq $-0x1, 0x8(%rax)
jmp 0x4870c9
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x486fae
movl 0xcc(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x487156
movq 0xe8(%rsp), %rdi
leaq 0xf04d2(%rip), %rsi     # 0x5775cf
callq 0x32950
cmpl $0x0, %eax
je 0x487122
movq 0xe8(%rsp), %rdi
leaq 0xf425e(%rip), %rsi     # 0x57b374
callq 0x464500
movq %rax, 0x10(%rsp)
jmp 0x487144
movq 0x174ec7(%rip), %rax    # 0x5fbff0
movq (%rax), %rdi
callq 0x2f230
movl %eax, %edi
leaq 0xf423a(%rip), %rsi     # 0x57b374
callq 0x464980
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x48722c
movl 0xcc(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4871ca
movq 0xe8(%rsp), %rdi
leaq 0xf045b(%rip), %rsi     # 0x5775cf
callq 0x32950
cmpl $0x0, %eax
je 0x487199
movq 0xe8(%rsp), %rdi
leaq 0xf41ea(%rip), %rsi     # 0x57b377
callq 0x464500
movq %rax, 0x8(%rsp)
jmp 0x4871bb
movq 0x174e50(%rip), %rax    # 0x5fbff0
movq (%rax), %rdi
callq 0x2f230
movl %eax, %edi
leaq 0xf41c6(%rip), %rsi     # 0x57b377
callq 0x464980
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x48722a
movq 0xe8(%rsp), %rdi
leaq 0xf03f6(%rip), %rsi     # 0x5775cf
callq 0x32950
cmpl $0x0, %eax
je 0x4871fd
movq 0xe8(%rsp), %rdi
leaq 0xb0f80(%rip), %rsi     # 0x538172
callq 0x464500
movq %rax, (%rsp)
jmp 0x48721e
movq 0x174dec(%rip), %rax    # 0x5fbff0
movq (%rax), %rdi
callq 0x2f230
movl %eax, %edi
leaq 0xb0f5d(%rip), %rsi     # 0x538172
callq 0x464980
movq %rax, (%rsp)
movq (%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x48722c
cmpq $0x0, 0xc0(%rsp)
jne 0x487266
movq 0x174d8a(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
leaq 0xf4132(%rip), %rsi     # 0x57b37a
leaq 0xf4116(%rip), %rdx     # 0x57b365
movb $0x0, %al
callq 0x33960
movl $0xffffffff, 0xf4(%rsp) # imm = 0xFFFFFFFF
jmp 0x4875c9
movq 0xc0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x4694a0
movq 0xa8(%rsp), %rdi
callq 0x469100
movslq 0xdc(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x484fc0
movq 0xb0(%rsp), %rax
cmpq $-0x1, 0x8(%rax)
je 0x4874c0
movq 0xb0(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
movl 0xcc(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x487343
movq 0x20(%rsp), %rdi
leaq 0xf00fc(%rip), %rsi     # 0x5773d8
callq 0x467810
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x4872fd
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x467a40
movq 0x20(%rsp), %rdi
movq 0x90(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %ecx
addl $0x1, %ecx
movq 0x80(%rsp), %rax
movq 0xb0(%rsp), %rdx
movslq (%rdx), %rdx
movq (%rax,%rdx,8), %r8
leaq 0xf009f(%rip), %rsi     # 0x5773d8
movl $0x5a, %edx
callq 0x467640
movq 0xc0(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x20(%rsp), %rax
movl 0x24(%rax), %edx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rcx
callq 0x469dc0
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x78(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x20(%rsp), %rdx
callq 0x473cd0
movl %eax, 0x98(%rsp)
cmpl $0x0, %eax
jl 0x48741f
movq 0x20(%rsp), %rax
movslq (%rax), %rcx
shlq $0x20, %rcx
movq 0x20(%rsp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
shll %eax
movl %eax, %eax
orq %rax, %rcx
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x10, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
orq %rax, %rcx
movq 0xb0(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq %rcx, %rax
addq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0xb0(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x4874a2
cmpl $-0x1, 0x98(%rsp)
jne 0x487471
movq 0xb0(%rsp), %rax
movq $-0x1, 0x8(%rax)
movq 0xb0(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rax), %rdi
callq 0x34078
movq 0xb0(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x34078
movq 0xb0(%rsp), %rax
movq $0x0, 0x18(%rax)
jmp 0x4874a0
movq 0x174b50(%rip), %rax    # 0x5fbfc8
movq (%rax), %rdi
movq 0xd0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xf3f07(%rip), %rsi     # 0x57b3a0
movb $0x0, %al
callq 0x33960
jmp 0x4874a2
movslq 0xdc(%rsp), %rsi
movq 0xb0(%rsp), %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0x484db0
jmp 0x48729d
movl 0xcc(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x487530
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
je 0x487516
movq 0x80(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x34078
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x4874da
movq 0x80(%rsp), %rdi
callq 0x34078
movq 0x90(%rsp), %rdi
callq 0x34078
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
je 0x48758d
movq 0x78(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x473ca0
movq 0xb8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4646c0
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x48753b
movq 0xc0(%rsp), %rdi
callq 0x4646c0
movq 0xb8(%rsp), %rdi
callq 0x34078
movq 0xb0(%rsp), %rdi
callq 0x34078
movq 0x78(%rsp), %rdi
callq 0x34078
movl $0x0, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq
nopl (%rax,%rax)