// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/libsmacker/smacker.c
// Function: smk_render
static char smk_render(smk s)
{
	unsigned long i, size;
	unsigned char * buffer = NULL, * p, track;
	/* null check */
	assert(s);

	/* Retrieve current chunk_size for this frame. */
	if (!(i = s->chunk_size[s->cur_frame])) {
		fprintf(stderr, "libsmacker::smk_render(s) - Warning: frame %lu: chunk_size is 0.\n", s->cur_frame);
		goto error;
	}

	if (s->mode == SMK_MODE_DISK) {
		/* Skip to frame in file */
		if (fseek(s->source.file.fp, s->source.file.chunk_offset[s->cur_frame], SEEK_SET)) {
			fprintf(stderr, "libsmacker::smk_render(s) - ERROR: fseek to frame %lu (offset %lu) failed.\n", s->cur_frame, s->source.file.chunk_offset[s->cur_frame]);
			perror("\tError reported was");
			goto error;
		}

		/* In disk-streaming mode: make way for our incoming chunk buffer */
		if ((buffer = malloc(i)) == NULL) {
			perror("libsmacker::smk_render() - ERROR: failed to malloc() buffer");
			return -1;
		}

		/* Read into buffer */
		if (smk_read_file(buffer, s->chunk_size[s->cur_frame], s->source.file.fp) < 0) {
			fprintf(stderr, "libsmacker::smk_render(s) - ERROR: frame %lu (offset %lu): smk_read had errors.\n", s->cur_frame, s->source.file.chunk_offset[s->cur_frame]);
			goto error;
		}
	} else {
		/* Just point buffer at the right place */
		if (!s->source.chunk_data[s->cur_frame]) {
			fprintf(stderr, "libsmacker::smk_render(s) - ERROR: frame %lu: memory chunk is a NULL pointer.\n", s->cur_frame);
			goto error;
		}

		buffer = s->source.chunk_data[s->cur_frame];
	}

	p = buffer;

	/* Palette record first */
	if (s->frame_type[s->cur_frame] & 0x01) {
		/* need at least 1 byte to process */
		if (!i) {
			fprintf(stderr, "libsmacker::smk_render(s) - ERROR: frame %lu: insufficient data for a palette rec.\n", s->cur_frame);
			goto error;
		}

		/* Byte 1 in block, times 4, tells how many
			subsequent bytes are present */
		size = 4 * (*p);

		/* If video rendering enabled, kick this off for decode. */
		if (s->video.enable)
			smk_render_palette(&(s->video), p + 1, size - 1);

		p += size;
		i -= size;
	}

	/* Unpack audio chunks */
	for (track = 0; track < 7; track ++) {
		if (s->frame_type[s->cur_frame] & (0x02 << track)) {
			/* need at least 4 byte to process */
			if (i < 4) {
				fprintf(stderr, "libsmacker::smk_render(s) - ERROR: frame %lu: insufficient data for audio[%u] rec.\n", s->cur_frame, track);
				goto error;
			}

			/* First 4 bytes in block tell how many
				subsequent bytes are present */
			size = (((unsigned int) p[3] << 24) |
					((unsigned int) p[2] << 16) |
					((unsigned int) p[1] << 8) |
					((unsigned int) p[0]));

			/* If audio rendering enabled, kick this off for decode. */
			if (s->audio[track].enable)
				smk_render_audio(&s->audio[track], p + 4, size - 4);

			p += size;
			i -= size;
		} else
			s->audio[track].buffer_size = 0;
	}

	/* Unpack video chunk */
	if (s->video.enable) {
		if (smk_render_video(&(s->video), p, i) < 0) {
			fprintf(stderr, "libsmacker::smk_render(s) - ERROR: frame %lu: failed to render video.\n", s->cur_frame);
			goto error;
		}
	}

	if (s->mode == SMK_MODE_DISK) {
		/* Remember that buffer we allocated?  Trash it */
		smk_free(buffer);
	}

	return 0;
error:

	if (s->mode == SMK_MODE_DISK) {
		/* Remember that buffer we allocated?  Trash it */
		smk_free(buffer);
	}

	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x46ead
jmp 0x46ecc
leaq 0xa889b(%rip), %rdi     # 0xef74f
leaq 0xa6408(%rip), %rsi     # 0xed2c3
movl $0x646, %edx            # imm = 0x646
leaq 0xa7d82(%rip), %rcx     # 0xeec49
callq 0x8230
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x46f0f
movq 0xd20e7(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xa7d5b(%rip), %rsi     # 0xeec5e
movb $0x0, %al
callq 0x8280
jmp 0x472da
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x4701c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
xorl %edx, %edx
callq 0x9080
cmpl $0x0, %eax
je 0x46f8c
movq 0xd208a(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xa7d2c(%rip), %rsi     # 0xeeca0
movb $0x0, %al
callq 0x8280
leaq 0xa62f0(%rip), %rdi     # 0xed272
callq 0x83d0
jmp 0x472da
movq -0x18(%rbp), %rdi
callq 0x8ca0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x46fb4
leaq 0xa7d46(%rip), %rdi     # 0xeecec
callq 0x83d0
movb $-0x1, -0x1(%rbp)
jmp 0x47323
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x47610
movsbl %al, %eax
cmpl $0x0, %eax
jge 0x4701a
movq 0xd1ff0(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xa7d1a(%rip), %rsi     # 0xeed28
movb $0x0, %al
callq 0x8280
jmp 0x472da
jmp 0x47070
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x47058
movq 0xd1f9e(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xa7d2d(%rip), %rsi     # 0xeed79
movb $0x0, %al
callq 0x8280
jmp 0x472da
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x47112
cmpq $0x0, -0x18(%rbp)
jne 0x470c0
movq 0xd1f36(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xa7d14(%rip), %rsi     # 0xeedc8
movb $0x0, %al
callq 0x8280
jmp 0x472da
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
shll $0x2, %eax
cltq
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x470f7
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
callq 0x484f0
movq -0x20(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movb $0x0, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x7, %eax
jge 0x47242
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movzbl -0x31(%rbp), %ecx
movl $0x2, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x47216
cmpq $0x4, -0x18(%rbp)
jae 0x4717f
movq 0xd1e7b(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movzbl -0x31(%rbp), %ecx
leaq 0xa7ca9(%rip), %rsi     # 0xeee1c
movb $0x0, %al
callq 0x8280
jmp 0x472da
movq -0x30(%rbp), %rax
movzbl 0x3(%rax), %eax
shll $0x18, %eax
movq -0x30(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x30(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x30(%rbp), %rcx
movzbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x3f8, %rax            # imm = 0x3F8
movzbl -0x31(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x1(%rax)
je 0x471f9
movq -0x10(%rbp), %rdi
addq $0x3f8, %rdi            # imm = 0x3F8
movzbl -0x31(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
addq $0x4, %rsi
movq -0x20(%rbp), %rdx
subq $0x4, %rdx
callq 0x48880
movq -0x20(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x47233
movq -0x10(%rbp), %rax
addq $0x3f8, %rax            # imm = 0x3F8
movzbl -0x31(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x28(%rax)
jmp 0x47235
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x47116
movq -0x10(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x4728f
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movl %eax, %edx
callq 0x48db0
movsbl %al, %eax
cmpl $0x0, %eax
jge 0x4728d
movq 0xd1d66(%rip), %rax     # 0x118fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xa7bec(%rip), %rsi     # 0xeee70
movb $0x0, %al
callq 0x8280
jmp 0x472da
jmp 0x4728f
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x472d4
cmpq $0x0, -0x28(%rbp)
je 0x472a4
jmp 0x472c3
leaq 0xa7a76(%rip), %rdi     # 0xeed21
leaq 0xa6011(%rip), %rsi     # 0xed2c3
movl $0x6a5, %edx            # imm = 0x6A5
leaq 0xa798b(%rip), %rcx     # 0xeec49
callq 0x8230
movq -0x28(%rbp), %rdi
callq 0x8260
movq $0x0, -0x28(%rbp)
movb $0x0, -0x1(%rbp)
jmp 0x47323
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x4731f
cmpq $0x0, -0x28(%rbp)
je 0x472ef
jmp 0x4730e
leaq 0xa7a2b(%rip), %rdi     # 0xeed21
leaq 0xa5fc6(%rip), %rsi     # 0xed2c3
movl $0x6ad, %edx            # imm = 0x6AD
leaq 0xa7940(%rip), %rcx     # 0xeec49
callq 0x8230
movq -0x28(%rbp), %rdi
callq 0x8260
movq $0x0, -0x28(%rbp)
movb $-0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)