// File: /workspace/github_c_makefile_star2_O1/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 0x321f
movq %rdi, %r14
movq 0x18(%rdi), %rax
testq %rax, %rax
je 0x321f
movq %r14, %rdi
xorl %esi, %esi
callq *%rax
testl %eax, %eax
je 0x322c
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x321f
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
movl $0x4, %edx
callq *%rax
cmpl $0x4, %eax
jl 0x321f
cmpb $0x57, -0x2f(%rbp)
jne 0x321f
cmpb $0x53, -0x2e(%rbp)
jne 0x321f
leaq -0x3b7(%rip), %rax      # 0x2ea4
movq %rax, 0x28(%r14)
leaq -0x393(%rip), %rax      # 0x2ed3
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 0x2a4f
movl (%r15), %eax
movl %eax, 0x3c(%r14)
movzbl -0x30(%rbp), %eax
cmpl $0x5a, %eax
je 0x3308
cmpl $0x43, %eax
jne 0x3349
movl $0x1000, %edi           # imm = 0x1000
callq 0x51a7
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x33e1
movl $0x4000, %edi           # imm = 0x4000
callq 0x51a7
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x33f5
movq %r14, %rdi
callq 0x4b34
testl %eax, %eax
je 0x3349
callq 0x12e0
jmp 0x321f
movl $0x1000, %edi           # imm = 0x1000
callq 0x51a7
movq %rax, 0x78(%r14)
testq %rax, %rax
je 0x33eb
movl $0x4000, %edi           # imm = 0x4000
callq 0x51a7
movq %rax, 0x80(%r14)
testq %rax, %rax
je 0x33ff
movq %r14, %rdi
callq 0x4624
testl %eax, %eax
jne 0x3409
movzbl -0x2d(%rbp), %edx
leal -0x15(%rdx), %eax
cmpb $-0x15, %al
jbe 0x33c4
leaq 0x40(%r14), %rsi
movq %r14, %rdi
callq 0x2d5f
xorl %ebx, %ebx
movw %bx, (%r15)
movb %bl, 0x59(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x2a4f
movzwl (%r15), %eax
movw %ax, 0x54(%r14)
movw %bx, (%r15)
movb %bl, 0x59(%r14)
movq %r14, %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x2a4f
movzwl (%r15), %eax
movw %ax, 0x56(%r14)
movq 0x8(%r14), %rax
movl %eax, 0x5c(%r14)
movq %rax, 0x68(%r14)
cmpb %bl, 0x71(%r14)
je 0x321f
callq 0x13ac
jmp 0x321f
movq 0x6c2d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x3f40(%rip), %rsi      # 0x7315
xorl %eax, %eax
callq 0x10e0
jmp 0x321f
callq 0x1324
jmp 0x321f
callq 0x138a
jmp 0x321f
callq 0x1302
jmp 0x321f
callq 0x1368
jmp 0x321f
callq 0x1346
jmp 0x321f