// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x2, %edi
jle 0x13bb
movq %rsi, %r14
movq 0x8(%rsi), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x1180
testl %eax, %eax
js 0x13d0
movl %eax, %r15d
movq 0x10(%r14), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x1180
testl %eax, %eax
js 0x13e7
movl %eax, %ebx
xorl %eax, %eax
callq 0x1979
testq %rax, %rax
je 0x1405
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x1a9c
testl %eax, %eax
jne 0x141a
movq %r14, %rdi
callq 0x19b9
movq %r14, %rdi
callq 0x1ae2
testl %eax, %eax
jne 0x142f
movzbl 0x3b(%r14), %esi
movzbl 0x38(%r14), %edx
movzbl 0x39(%r14), %ecx
movzbl 0x3a(%r14), %r8d
movl 0x3c(%r14), %r9d
leaq 0x2d56(%rip), %rdi      # 0x40ac
xorl %eax, %eax
callq 0x1080
movq %r14, %rdi
xorl %esi, %esi
callq 0x14d9
testl %eax, %eax
je 0x137c
leaq 0x2d64(%rip), %rdi      # 0x40d6
callq 0x1060
jmp 0x144b
leaq 0x5dfd(%rip), %r15      # 0x7180
movq %r14, %rdi
movq %r15, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x14f9
testl %eax, %eax
jle 0x13a5
movl %eax, %edx
movl %ebx, %edi
movq %r15, %rsi
callq 0x1070
jmp 0x1383
movq %r14, %rdi
callq 0x1995
movl %ebx, %edi
callq 0x10c0
xorl %eax, %eax
jmp 0x144e
movq 0x5c36(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2c38(%rip), %rdi      # 0x4004
pushq $0x2c
jmp 0x1442
movq 0x5c21(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x2c4c(%rip), %rsi      # 0x4031
jmp 0x13fc
movq 0x5c0a(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x2c4d(%rip), %rsi      # 0x4049
xorl %eax, %eax
callq 0x10f0
jmp 0x144b
movq 0x5bec(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2c4d(%rip), %rdi      # 0x4063
pushq $0x19
jmp 0x1442
movq 0x5bd7(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2c52(%rip), %rdi      # 0x407d
pushq $0x11
jmp 0x1442
movq 0x5bc2(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2c4f(%rip), %rdi      # 0x408f
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x11a0
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)