// File: /workspace/github_c_makefile_star2_O2/joncampbell123[P]swfhax/swf.c
// Function: swf_reader_get_file_header
int swf_reader_get_file_header(swf_reader *swf) {
	unsigned char tmp[16];

	if (swf == NULL) return -1;
	if (swf_reader_raw_seek(swf,0)) return -1;
	if (swf_reader_raw_read(swf,tmp,4) < 4) return -1;

	/* should be "FWS" (SWF backwards) or "CWS" or "ZWS" */
	if (tmp[1] != 'W' || tmp[2] != 'S') return -1;

	swf->seek = swf_reader_uncompressed_seek;
	swf->read = swf_reader_uncompressed_read;
	swf->current_pos = swf->raw_current_pos;

	memcpy(swf->header.Signature,tmp,3);
	swf->header.Version = tmp[3];
	swf->header.FileLength = swf_reader_read_UI32(swf);

	/* check compression */
	if (tmp[0] == 'F') {
	}
	else if (tmp[0] == 'C') {
		swf->decom_buf = sliding_window_v4_create_buffer(4096);
		if (swf->decom_buf == NULL) {
			fprintf(stderr,"Unable to init decompression buffer\n");
			return -1;
		}
		swf->out_buf = sliding_window_v4_create_buffer(16384);
		if (swf->out_buf == NULL) {
			fprintf(stderr,"Unable to init decompression buffer\n");
			return -1;
		}

		/* Init zlib decoder. Also assigns zlib reader to read/seek. */
		if (swf_reader_init_zlib(swf)) {
			fprintf(stderr,"Failed to initialize ZLIB stream decompressor\n");
			return -1;
		}
	}
	else if (tmp[0] == 'Z') {
		swf->decom_buf = sliding_window_v4_create_buffer(4096);
		if (swf->decom_buf == NULL) {
			fprintf(stderr,"Unable to init decompression buffer\n");
			return -1;
		}
		swf->out_buf = sliding_window_v4_create_buffer(16384);
		if (swf->out_buf == NULL) {
			fprintf(stderr,"Unable to init decompression buffer\n");
			return -1;
		}

		/* Init LZMA decoder. Also assigns zlib reader to read/seek. */
		if (swf_reader_init_lzma(swf)) {
			fprintf(stderr,"Failed to initialize LZMA stream decompressor\n");
			return -1;
		}
	}

	/* check version */
	if (tmp[3] == 0x00 || tmp[3] > 20) { /* Adobe's up to version 20 */
		fprintf(stderr,"Unsupported SWF version %u\n",tmp[3]);
		return -1;
	}

	swf_reader_read_RECT(swf,&swf->header.FrameSize);
	swf->header.FrameRate = (swf_UFIXED8)swf_reader_read_UI16(swf);
	swf->header.FrameCount = swf_reader_read_UI16(swf);
	swf->header_end = swf->current_pos;
	swf->next_tag = swf->current_pos;
	if (swf->eof) fprintf(stderr,"WARNING: Just read header, already an eof\n");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
pushq $-0x1
popq %rbx
testq %rdi, %rdi
je 0x2b84
movq %rdi, %r14
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x2b84
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
testl %eax, %eax
je 0x2b8f
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x2b84
leaq -0x20(%rbp), %rsi
pushq $0x4
popq %rdx
movq %r14, %rdi
callq *%rax
cmpl $0x4, %eax
jl 0x2b84
cmpb $0x57, -0x1f(%rbp)
jne 0x2b84
cmpb $0x53, -0x1e(%rbp)
jne 0x2b84
leaq -0x340(%rip), %rax      # 0x287c
movq %rax, 0x28(%r14)
leaq -0x31e(%rip), %rax      # 0x28a9
movq %rax, 0x30(%r14)
movq (%r14), %rax
movq %rax, 0x8(%r14)
movzwl -0x20(%rbp), %eax
movw %ax, 0x38(%r14)
movb -0x1e(%rbp), %al
movb %al, 0x3a(%r14)
movb -0x1d(%rbp), %al
movb %al, 0x3b(%r14)
movq %r14, %rdi
callq 0x27ca
movl %eax, 0x3c(%r14)
movzbl -0x20(%rbp), %eax
cmpl $0x5a, %eax
je 0x2c5a
cmpl $0x43, %eax
jne 0x2c97
movl $0x1000, %edi           # imm = 0x1000
callq 0x47c5
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x2cf6
movl $0x4000, %edi           # imm = 0x4000
callq 0x47c5
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x2cf6
movq %r14, %rdi
callq 0x414c
testl %eax, %eax
je 0x2c97
movq 0x63ad(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x3662(%rip), %rdi      # 0x62b7
jmp 0x2d39
movl $0x1000, %edi           # imm = 0x1000
callq 0x47c5
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x2cf6
movl $0x4000, %edi           # imm = 0x4000
callq 0x47c5
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x2cf6
movq %r14, %rdi
callq 0x3c08
testl %eax, %eax
jne 0x2d28
movzbl -0x1d(%rbp), %edx
leal -0x15(%rdx), %eax
cmpb $-0x15, %al
jbe 0x2d0b
leaq 0x40(%r14), %rsi
movq %r14, %rdi
callq 0x274b
movq %r14, %rdi
callq 0x27a3
movw %ax, 0x54(%r14)
movq %r14, %rdi
callq 0x27a3
movw %ax, 0x56(%r14)
movq 0x8(%r14), %rax
movl %eax, 0x5c(%r14)
movq %rax, 0x68(%r14)
xorl %ebx, %ebx
cmpb $0x0, 0x71(%r14)
je 0x2b84
movq 0x6310(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x363f(%rip), %rdi      # 0x6331
pushq $0x2a
jmp 0x2d3b
movq 0x62fb(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x358b(%rip), %rdi      # 0x6292
pushq $0x24
jmp 0x2d3b
movq 0x62e6(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x35f9(%rip), %rsi      # 0x6315
xorl %eax, %eax
callq 0x10f0
jmp 0x2b84
movq 0x62c9(%rip), %rax      # 0x8ff8
movq (%rax), %rcx
leaq 0x35ad(%rip), %rdi      # 0x62e6
pushq $0x2e
popq %rsi
pushq $0x1
popq %rdx
callq 0x11a0
jmp 0x2b84