// File: /workspace/github_c_makefile_star2_O0/joncampbell123[P]swfhax/swf_zlib_reader.c
// Function: swf_reader_zlib_read
int swf_reader_zlib_read(void *io,void *buf,int len) {
	unsigned char *cbuf = (unsigned char*)buf;
	swf_reader *r = (swf_reader*)io;
	int rd,accum=0;
	size_t cc;

	/* pass back the first 8 bytes uncompressed */
	while (len > 0 && r->current_pos < 8) {
		if (swf_reader_raw_seek((swf_reader*)io,r->current_pos)) return -1;
		cc = (size_t)((uint64_t)8 - r->current_pos);
		if (cc > (size_t)len) cc = (size_t)len;
		r->current_pos = r->raw_current_pos;
		rd = swf_reader_raw_read((swf_reader*)io,cbuf,(int)cc);

		/* need to patch first byte at offset 0 to "FWS" instead of "CWS" */
		if (r->current_pos == 0 && rd > 0) cbuf[0] = 'F';

		r->current_pos = r->raw_current_pos;
		if (rd < (int)cc) return rd;
		accum += rd;
		cbuf += rd;
		len -= rd;
	}

	while (len > 0) {
		assert(sliding_window_v4_is_sane(r->decom_buf));
		assert(sliding_window_v4_is_sane(r->out_buf));
		sliding_window_v4_lazy_flush(r->out_buf);
		sliding_window_v4_lazy_flush(r->decom_buf);
		if ((cc=sliding_window_v4_data_available(r->out_buf)) > 0) {
			if (cc > (size_t)len) cc = (size_t)len;
			memcpy(cbuf,r->out_buf->data,cc);
			r->out_buf->data += cc;
			r->current_pos += cc;
			accum += cc;
			cbuf += cc;
			len -= cc;

			assert(sliding_window_v4_is_sane(r->out_buf));
		}
		else {
			if (r->zlib_eof) {
				r->eof = 1;
				break;
			}

			assert(sliding_window_v4_is_sane(r->decom_buf));
			if ((cc=sliding_window_v4_can_write(r->decom_buf)) > 0) {
				rd = swf_reader_raw_read((swf_reader*)io,r->decom_buf->end,cc);
				if (rd > 0) r->decom_buf->end += rd;
				assert(sliding_window_v4_is_sane(r->decom_buf));
				sliding_window_v4_lazy_flush(r->decom_buf);
			}

			r->zlib.next_in = r->decom_buf->data;
			r->zlib.avail_in = sliding_window_v4_data_available(r->decom_buf);
			r->zlib.next_out = r->out_buf->end;
			r->zlib.avail_out = sliding_window_v4_can_write(r->out_buf);
			rd = inflate(&r->zlib,Z_NO_FLUSH);
			if (rd == Z_STREAM_END) {
				r->zlib_eof = 1;
			}
			else if (rd != Z_OK) {
				fprintf(stderr,"ZLIB error %d\n",rd);
				r->zlib_eof = 1;
				break;
			}
			r->decom_buf->data = r->zlib.next_in;
			r->out_buf->end = r->zlib.next_out;
			assert(sliding_window_v4_is_sane(r->decom_buf));
		}
	}

	return accum;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x41(%rbp)
jle 0x66a4
movq -0x30(%rbp), %rax
cmpq $0x8, 0x8(%rax)
setb %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x66b0
jmp 0x6784
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x30d0
cmpl $0x0, %eax
je 0x66d2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6af6
movq -0x30(%rbp), %rcx
movl $0x8, %eax
subq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x66f8
movslq -0x1c(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rax
movl %eax, %edx
callq 0x37b0
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x6735
cmpl $0x0, -0x34(%rbp)
jle 0x6735
movq -0x28(%rbp), %rax
movb $0x46, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl %ecx, %eax
jge 0x675a
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6af6
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x34(%rbp), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x668a
jmp 0x6786
cmpl $0x0, -0x1c(%rbp)
jle 0x6af0
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x67a4
jmp 0x67c3
leaq 0x3025(%rip), %rdi      # 0x97d0
leaq 0x312e(%rip), %rsi      # 0x98e0
movl $0x6c, %edx
leaq 0x31f7(%rip), %rcx      # 0x99b5
callq 0x1080
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x67da
jmp 0x67f9
leaq 0x3057(%rip), %rdi      # 0x9838
leaq 0x30f8(%rip), %rsi      # 0x98e0
movl $0x6d, %edx
leaq 0x31c1(%rip), %rcx      # 0x99b5
callq 0x1080
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x7280
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7280
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x6520
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jbe 0x68ef
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x6849
movslq -0x1c(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x10(%rax), %rsi
movq -0x40(%rbp), %rdx
callq 0x10d0
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movslq -0x38(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rcx
movslq -0x1c(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x68cb
jmp 0x68ea
leaq 0x2f66(%rip), %rdi      # 0x9838
leaq 0x3007(%rip), %rsi      # 0x98e0
movl $0x79, %edx
leaq 0x30d0(%rip), %rcx      # 0x99b5
callq 0x1080
jmp 0x6aeb
movq -0x30(%rbp), %rax
cmpb $0x0, 0x70(%rax)
je 0x6906
movq -0x30(%rbp), %rax
movb $0x1, 0x71(%rax)
jmp 0x6af0
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x691a
jmp 0x6939
leaq 0x2eaf(%rip), %rdi      # 0x97d0
leaq 0x2fb8(%rip), %rsi      # 0x98e0
movl $0x81, %edx
leaq 0x3081(%rip), %rcx      # 0x99b5
callq 0x1080
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x6500
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jbe 0x69cd
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x18(%rax), %rsi
movq -0x40(%rbp), %rax
movl %eax, %edx
callq 0x37b0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x698d
movl -0x34(%rbp), %edx
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x18(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x69a1
jmp 0x69c0
leaq 0x2e28(%rip), %rdi      # 0x97d0
leaq 0x2f31(%rip), %rsi      # 0x98e0
movl $0x85, %edx
leaq 0x2ffa(%rip), %rcx      # 0x99b5
callq 0x1080
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7280
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x6520
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x6500
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xa8(%rax)
movq -0x30(%rbp), %rdi
addq $0x88, %rdi
xorl %esi, %esi
callq 0x1050
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0x6a58
movq -0x30(%rbp), %rax
movb $0x1, 0x70(%rax)
jmp 0x6a85
cmpl $0x0, -0x34(%rbp)
je 0x6a83
movq 0x5593(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl -0x34(%rbp), %edx
leaq 0x2f71(%rip), %rsi      # 0x99e3
movb $0x0, %al
callq 0x10c0
movq -0x30(%rbp), %rax
movb $0x1, 0x70(%rax)
jmp 0x6af0
jmp 0x6a85
movq -0x30(%rbp), %rax
movq 0x88(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0xa0(%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x7390
cmpl $0x0, %eax
je 0x6aca
jmp 0x6ae9
leaq 0x2cff(%rip), %rdi      # 0x97d0
leaq 0x2e08(%rip), %rsi      # 0x98e0
movl $0x98, %edx
leaq 0x2ed1(%rip), %rcx      # 0x99b5
callq 0x1080
jmp 0x6aeb
jmp 0x6786
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop