// File: /workspace/github_c_makefile_star2_O2/lh3[P]bgt/pbwt.c
// Function: pbf_open_r
pbf_t *pbf_open_r(const char *fn)
{
	pbf_t *pb;
	FILE *fp;
	int32_t i, v[3];
	char magic[4];
	if (fn && strcmp(fn, "-") != 0) {
		if ((fp = fopen(fn, "rb")) == 0)
			return 0;
	} else fp = stdin;
	fread(magic, 1, 4, fp);
	if (strncmp(magic, "PBF\1", 4) != 0) {
		fclose(fp);
		return 0;
	}
	pb = (pbf_t*)calloc(1, sizeof(pbf_t));
	fread(v, 4, 3, fp);
	pb->m = v[0], pb->g = v[1], pb->shift = v[2];
	pb->pb = (pbc_t**)calloc(pb->g, sizeof(void*));
	for (i = 0; i < pb->g; ++i)
		pb->pb[i] = pbc_init(pb->m);
	pb->buf = (uint8_t*)calloc(pb->m + 1, 1);
	pb->invS = (int32_t*)calloc(pb->m, 4);
	pb->ret = (const uint8_t**)calloc(pb->g, sizeof(uint8_t*));
	for (i = 0; i < pb->g; ++i) pb->ret[i] = pb->pb[i]->u;
	pb->sub = (pbs_dat_t**)calloc(pb->g, sizeof(pbs_dat_t*));
	if (fseek(fp, -8, SEEK_END) >= 0) {
		uint64_t off;
		uint8_t t;
		fread(&off, 8, 1, fp);
		fseek(fp, off, SEEK_SET);
		fread(&t, 1, 1, fp);
		fread(&pb->n, 8, 1, fp);
		fread(&pb->n_idx, 4, 1, fp);
		pb->m_idx = pb->n_idx;
		pb->idx = (uint64_t*)calloc(pb->n_idx, 8);
		fread(pb->idx, 8, pb->n_idx, fp);
		fseek(fp, 16, SEEK_SET);
	}
	pb->fp = fp;
	return pb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rdi, %rdi
je 0x10a7a
cmpb $0x2d, (%rdi)
jne 0x10a64
cmpb $0x0, 0x1(%rdi)
je 0x10a7a
leaq 0x85a5(%rip), %rsi      # 0x19010
callq 0x23c0
movq %rax, %rbx
testq %rax, %rax
jne 0x10a84
jmp 0x10aab
movq 0x10507(%rip), %rax     # 0x20f88
movq (%rax), %rbx
leaq 0x1c(%rsp), %r14
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x20f0
cmpl $0x1464250, (%r14)      # imm = 0x1464250
je 0x10ab3
movq %rbx, %rdi
callq 0x2160
xorl %r14d, %r14d
jmp 0x10c3b
pushq $0x1
popq %rdi
pushq $0x70
popq %rsi
callq 0x2220
movq %rax, %r14
leaq 0x2c(%rsp), %r15
pushq $0x4
popq %rsi
pushq $0x3
popq %rdx
movq %r15, %rdi
movq %rbx, 0x8(%rsp)
movq %rbx, %rcx
callq 0x20f0
movslq (%r15), %r13
movl %r13d, 0x8(%r14)
movq 0x4(%r15), %rax
movq %rax, 0xc(%r14)
movslq %eax, %rbx
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x2220
movq %rax, %r12
movq %rax, 0x20(%r14)
xorl %r15d, %r15d
testl %ebx, %ebx
movl $0x0, %ebp
movq %rbx, 0x10(%rsp)
cmovgl %ebx, %ebp
cmpq %r15, %rbp
je 0x10b28
movl %r13d, %edi
callq 0x1047e
movq %rax, (%r12,%r15,8)
incq %r15
jmp 0x10b12
leaq 0x1(%r13), %rdi
pushq $0x1
popq %rsi
callq 0x2220
movq %rax, 0x60(%r14)
pushq $0x4
popq %rsi
movq %r13, %rdi
callq 0x2220
movq %rax, 0x68(%r14)
pushq $0x8
popq %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x2220
movq %rax, 0x28(%r14)
xorl %ecx, %ecx
movq 0x8(%rsp), %rbx
cmpq %rcx, %rbp
je 0x10b78
movq (%r12,%rcx,8), %rdx
movq 0x18(%rdx), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
jmp 0x10b62
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x2220
movq %rax, 0x48(%r14)
pushq $-0x8
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x2320
testl %eax, %eax
js 0x10c38
leaq 0x20(%rsp), %r13
pushq $0x8
popq %r15
pushq $0x1
popq %r12
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20f0
movq (%r13), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2320
leaq 0x7(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20f0
leaq 0x18(%r14), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20f0
movq %r14, %rdi
addq $0x30, %rdi
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20f0
movslq 0x30(%r14), %r12
movl %r12d, 0x34(%r14)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, 0x38(%r14)
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x20f0
pushq $0x10
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2320
movq %rbx, (%r14)
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq