// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x31d3
movq %rdi, %r14
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x31d3
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
testl %eax, %eax
je 0x31e0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x31d3
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
movl $0x4, %edx
callq *%rax
cmpl $0x4, %eax
jl 0x31d3
cmpb $0x57, -0x2f(%rbp)
jne 0x31d3
cmpb $0x53, -0x2e(%rbp)
jne 0x31d3
leaq -0x392(%rip), %rax      # 0x2e7d
movq %rax, 0x28(%r14)
leaq -0x36e(%rip), %rax      # 0x2eac
movq %rax, 0x30(%r14)
movq (%r14), %rax
movq %rax, 0x8(%r14)
movzwl -0x30(%rbp), %eax
movw %ax, 0x38(%r14)
movb -0x2e(%rbp), %al
movb %al, 0x3a(%r14)
movb -0x2d(%rbp), %al
movb %al, 0x3b(%r14)
leaq -0x1c(%rbp), %r15
movl $0x0, (%r15)
movb $0x0, 0x59(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x4, %edx
callq 0x2a27
movl (%r15), %eax
movl %eax, 0x3c(%r14)
movzbl -0x30(%rbp), %eax
cmpl $0x5a, %eax
je 0x32bc
cmpl $0x43, %eax
jne 0x32fd
movl $0x1000, %edi           # imm = 0x1000
callq 0x514a
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x3395
movl $0x4000, %edi           # imm = 0x4000
callq 0x514a
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x33a9
movq %r14, %rdi
callq 0x4af8
testl %eax, %eax
je 0x32fd
callq 0x12f0
jmp 0x31d3
movl $0x1000, %edi           # imm = 0x1000
callq 0x514a
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x339f
movl $0x4000, %edi           # imm = 0x4000
callq 0x514a
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x33b3
movq %r14, %rdi
callq 0x45ec
testl %eax, %eax
jne 0x33bd
movzbl -0x2d(%rbp), %edx
leal -0x15(%rdx), %eax
cmpb $-0x15, %al
jbe 0x3378
leaq 0x40(%r14), %rsi
movq %r14, %rdi
callq 0x2d38
xorl %ebx, %ebx
movw %bx, (%r15)
movb %bl, 0x59(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x2a27
movzwl (%r15), %eax
movw %ax, 0x54(%r14)
movw %bx, (%r15)
movb %bl, 0x59(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x2a27
movzwl (%r15), %eax
movw %ax, 0x56(%r14)
movq 0x8(%r14), %rax
movl %eax, 0x5c(%r14)
movq %rax, 0x68(%r14)
cmpb %bl, 0x71(%r14)
je 0x31d3
callq 0x13bc
jmp 0x31d3
movq 0x6c79(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x3f8c(%rip), %rsi      # 0x7315
xorl %eax, %eax
callq 0x10f0
jmp 0x31d3
callq 0x1334
jmp 0x31d3
callq 0x139a
jmp 0x31d3
callq 0x1312
jmp 0x31d3
callq 0x1378
jmp 0x31d3
callq 0x1356
jmp 0x31d3