// File: /workspace/github_c_makefile_star2_O0/FirestonnneTFM[P]tfm_key_parser/src/swf_file.cpp
// Function: swf_file::swf_file(char*)
swf_file::swf_file(char *fname) {
	std::ifstream file;
	file.open(fname, std::ios::in | std::ios::binary | std::ios::ate);
	int fsize = file.tellg();
	file.close();
	
	file.open(fname, std::ios::in | std::ios::binary);
	if (! file.is_open())
		fatal("Could not open file");
	file.read((char*)&header, sizeof(cwf_header));
	if (! header.is_sig_valid()) {
		header.print();
		fatal("Header is not valid");
	}
	fsize -= sizeof(cwf_header);
	char *in_data = new char[fsize];
	file.read(in_data, fsize);
	file.close();
	handle = new uint8_t[header.file_size];
	
	z_stream stream;
	stream.zalloc = Z_NULL;
	stream.zfree = Z_NULL;
	stream.opaque = Z_NULL;
	stream.avail_in = (uInt)fsize;
	stream.next_in = (Bytef*)in_data;
	stream.avail_out = header.file_size;
	stream.next_out = (Bytef*)handle;

	inflateInit(&stream);
	inflate(&stream, Z_NO_FLUSH);
	inflateEnd(&stream);

	// read tags
	uint8_t *raw = handle;
	uint16_t bit_size = *raw >> 3;
	bit_size = bit_size * 4 + 5;
	for ( ; bit_size < 200; bit_size -= 8) {
		++raw;
	}
	// frame rate and frame count
	raw += 4;
	for ( ; ; ) {
		swf_tag tag(&raw);
		tags.push_back(tag);
		if (tag.kind == 0)
			break;
	}
	swf_tag abc_tag;
	get_tags(82, &abc_tag, 1);
	abc = abc_file::factory_from_bytes(abc_tag.get_handle());
	/*
	do {
		
		uint16_t header_0 = conv_copy<uint16_t>(raw);
		uint16_t tag_type = header_0 >> 6;
		uint32_t tag_len = header_0 & 63;
		if (tag_len == 0x3f) {
			tag_len = conv_copy<uint32_t>(swf);
		}
		if (tag_type == 87) {
			uint16_t tag = conv_copy<uint16_t>(swf);
			// skip ahead 4 bytes (reserved data)
			btags[i] = swf + 4;
			btag_lens[i] = tag_len - 6;
			// undo the read (length is not from this point)
			swf -= 2;
			++i;
			if (tag != i)
				throw "Tag and position mismatch";
		}
		if (tag_type == 76) {
			sym = swf;
		}
		swf += tag_len;
	} while (sym == nullptr || i < 12);
	*/

	delete [] in_data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
addq $0x18, %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x7d90
leaq -0x218(%rbp), %rdi
callq 0x21e0
jmp 0x777c
movq -0x10(%rbp), %rax
movq %rax, -0x300(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x7db0
movl %eax, -0x2f4(%rbp)
jmp 0x779e
movl -0x2f4(%rbp), %edi
movl $0x2, %esi
callq 0x7db0
movl %eax, -0x304(%rbp)
jmp 0x77b6
movl -0x304(%rbp), %edx
movq -0x300(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x2100
jmp 0x77d1
leaq -0x218(%rbp), %rdi
callq 0x22d0
movq %rdx, -0x318(%rbp)
movq %rax, -0x310(%rbp)
jmp 0x77ed
movq -0x318(%rbp), %rax
movq -0x310(%rbp), %rcx
movq %rcx, -0x238(%rbp)
movq %rax, -0x230(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x7dd0
movq %rax, -0x320(%rbp)
jmp 0x781e
movq -0x320(%rbp), %rax
movl %eax, -0x228(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x2060
jmp 0x7839
movq -0x10(%rbp), %rax
movq %rax, -0x330(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x7db0
movl %eax, -0x324(%rbp)
jmp 0x785b
movl -0x324(%rbp), %edx
movq -0x330(%rbp), %rsi
leaq -0x218(%rbp), %rdi
callq 0x2100
jmp 0x7876
leaq -0x218(%rbp), %rdi
callq 0x2280
movb %al, -0x331(%rbp)
jmp 0x788a
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0x7938
jmp 0x789a
movl $0x18, %edi
callq 0x20e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x340(%rbp)
leaq 0x2cf1(%rip), %rsi      # 0xa5a9
leaq 0x2cfe(%rip), %rdx      # 0xa5bd
movl $0x18, %ecx
callq 0x2f30
jmp 0x78cb
movq -0x340(%rbp), %rdi
leaq 0x74af(%rip), %rsi      # 0xed88
xorl %eax, %eax
movl %eax, %edx
callq 0x22b0
jmp 0x7c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x7c63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x7c57
movq -0x340(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
callq 0x2110
jmp 0x7c57
movq -0x2f0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x2210
jmp 0x7956
movq -0x2f0(%rbp), %rdi
addq $0x8, %rdi
callq 0x76f0
testb $0x1, %al
jne 0x79f0
movq -0x2f0(%rbp), %rdi
addq $0x8, %rdi
callq 0x7620
jmp 0x7980
movl $0x18, %edi
callq 0x20e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x348(%rbp)
leaq 0x2c30(%rip), %rsi      # 0xa5ce
leaq 0x2c18(%rip), %rdx      # 0xa5bd
movl $0x1c, %ecx
callq 0x2f30
jmp 0x79b1
movq -0x348(%rbp), %rdi
leaq 0x73c9(%rip), %rsi      # 0xed88
xorl %eax, %eax
movl %eax, %edx
callq 0x22b0
jmp 0x7c7b
movq -0x348(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
callq 0x2110
jmp 0x7c57
movl -0x228(%rbp), %eax
addl $-0x8, %eax
movl %eax, -0x228(%rbp)
movslq -0x228(%rbp), %rdi
callq 0x2030
movq %rax, -0x350(%rbp)
jmp 0x7a14
movq -0x350(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rsi
movslq -0x228(%rbp), %rdx
leaq -0x218(%rbp), %rdi
callq 0x2210
jmp 0x7a3e
leaq -0x218(%rbp), %rdi
callq 0x2060
jmp 0x7a4c
movq -0x2f0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
callq 0x2030
movq %rax, -0x358(%rbp)
jmp 0x7a66
movq -0x2f0(%rbp), %rax
movq -0x358(%rbp), %rcx
movq %rcx, (%rax)
movq $0x0, -0x270(%rbp)
movq $0x0, -0x268(%rbp)
movq $0x0, -0x260(%rbp)
movl -0x228(%rbp), %ecx
movl %ecx, -0x2a8(%rbp)
movq -0x240(%rbp), %rcx
movq %rcx, -0x2b0(%rbp)
movl 0xc(%rax), %ecx
movl %ecx, -0x290(%rbp)
movq (%rax), %rax
movq %rax, -0x298(%rbp)
leaq 0x2b16(%rip), %rsi      # 0xa5e2
leaq -0x2b0(%rbp), %rdi
movl $0x70, %edx
callq 0x2160
jmp 0x7adf
leaq -0x2b0(%rbp), %rdi
xorl %esi, %esi
callq 0x2130
jmp 0x7aef
leaq -0x2b0(%rbp), %rdi
callq 0x21d0
jmp 0x7afd
movq -0x2f0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b8(%rbp), %rax
movzbl (%rax), %eax
sarl $0x3, %eax
movw %ax, -0x2ba(%rbp)
movzwl -0x2ba(%rbp), %eax
shll $0x2, %eax
addl $0x5, %eax
movw %ax, -0x2ba(%rbp)
movzwl -0x2ba(%rbp), %eax
cmpl $0xc8, %eax
jge 0x7b69
movq -0x2b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2b8(%rbp)
movzwl -0x2ba(%rbp), %eax
subl $0x8, %eax
movw %ax, -0x2ba(%rbp)
jmp 0x7b36
movq -0x2b8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x2b8(%rbp)
leaq -0x2d0(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x8a00
jmp 0x7b90
movq -0x2f0(%rbp), %rdi
addq $0x18, %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x7df0
jmp 0x7ba9
movzwl -0x2c8(%rbp), %eax
cmpl $0x0, %eax
jne 0x7bb7
jmp 0x7bb9
jmp 0x7b7b
leaq -0x2e0(%rbp), %rdi
callq 0x89d0
jmp 0x7bc7
movq -0x2f0(%rbp), %rdi
movl $0x52, %esi
leaq -0x2e0(%rbp), %rdx
movl $0x1, %ecx
callq 0x7c80
jmp 0x7be6
leaq -0x2e0(%rbp), %rdi
callq 0x2950
movq %rax, -0x360(%rbp)
jmp 0x7bfb
movq -0x360(%rbp), %rdi
callq 0x30a0
movq %rax, -0x368(%rbp)
jmp 0x7c10
movq -0x2f0(%rbp), %rax
movq -0x368(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x240(%rbp), %rax
movq %rax, -0x370(%rbp)
cmpq $0x0, %rax
je 0x7c42
movq -0x370(%rbp), %rdi
callq 0x2220
leaq -0x218(%rbp), %rdi
callq 0x2070
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x2070
movq -0x2e8(%rbp), %rdi
callq 0x7e60
movq -0x220(%rbp), %rdi
callq 0x22e0
nopl (%rax,%rax)