// File: /workspace/github_c_makefile_star2_O0/joncampbell123[P]swfhax/c4_swfunzip.c
// Function: main
int main(int argc,char **argv) {
	swf_reader *swf;
	int fd,ofd,rd;

	if (argc < 3) {
		fprintf(stderr,"c4_swfdump <file> <output uncompressed swf>\n");
		return 1;
	}

	fd = open(argv[1],O_RDONLY);
	if (fd < 0) {
		fprintf(stderr,"Unable to open file %s\n",argv[1]);
		return 1;
	}
	ofd = open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0644);
	if (ofd < 0) {
		fprintf(stderr,"Unable to create file %s\n",argv[2]);
		return 1;
	}
	if ((swf=swf_reader_create()) == NULL) {
		fprintf(stderr,"Cannot create SWF reader\n");
		return 1;
	}
	if (swf_reader_assign_fd(swf,fd)) {
		fprintf(stderr,"Cannot assign fd\n");
		return 1;
	}
	swf_reader_assign_fd_ownership(swf);
	if (swf_reader_get_file_header(swf)) {
		fprintf(stderr,"Unable to read file header.\n");
		return 1;
	}

	printf("SWF version %u (%c%c%c), file length %lu\n",
		swf->header.Version,
		swf->header.Signature[0],
		swf->header.Signature[1],
		swf->header.Signature[2],
		(unsigned long)swf->header.FileLength);

	/* copy */
	if (swf_reader_seek(swf,0)) {
		printf("Unable to seek to offset 0\n");
		return 1;
	}

	while ((rd=swf_reader_read(swf,temp,sizeof(temp))) > 0)
		write(ofd,temp,rd);

	swf = swf_reader_destroy(swf);
	close(ofd);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x12c0
movq 0x7d55(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4d57(%rip), %rsi      # 0x6004
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x1160
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x1306
movq 0x7d17(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x4d3e(%rip), %rsi      # 0x6031
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x1160
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x1354
movq 0x7cc9(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x4d08(%rip), %rsi      # 0x6049
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movb $0x0, %al
callq 0x22b0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x1389
movq 0x7c8c(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4ced(%rip), %rsi      # 0x6063
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x24d0
cmpl $0x0, %eax
je 0x13be
movq 0x7c57(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4cd2(%rip), %rsi      # 0x607d
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movq -0x18(%rbp), %rdi
callq 0x2340
movq -0x18(%rbp), %rdi
callq 0x2550
cmpl $0x0, %eax
je 0x13f9
movq 0x7c1c(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x4ca9(%rip), %rsi      # 0x608f
movb $0x0, %al
callq 0x10d0
movl $0x1, -0x4(%rbp)
jmp 0x14ab
movq -0x18(%rbp), %rax
movzbl 0x3b(%rax), %esi
movq -0x18(%rbp), %rax
movzbl 0x38(%rax), %edx
movq -0x18(%rbp), %rax
movzbl 0x39(%rax), %ecx
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %r8d
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, %r9d
leaq 0x4c81(%rip), %rdi      # 0x60ac
movb $0x0, %al
callq 0x1070
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1970
cmpl $0x0, %eax
je 0x145b
leaq 0x4c8b(%rip), %rdi      # 0x60d6
movb $0x0, %al
callq 0x1070
movl $0x1, -0x4(%rbp)
jmp 0x14ab
jmp 0x145d
movq -0x18(%rbp), %rdi
leaq 0x7cf8(%rip), %rsi      # 0x9160
movl $0x1000, %edx           # imm = 0x1000
callq 0x19d0
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jle 0x148f
movl -0x20(%rbp), %edi
movslq -0x24(%rbp), %rdx
leaq 0x7cd8(%rip), %rsi      # 0x9160
callq 0x1060
jmp 0x145d
movq -0x18(%rbp), %rdi
callq 0x2310
movq %rax, -0x18(%rbp)
movl -0x20(%rbp), %edi
callq 0x10b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop