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

	if (parse_argv(argc,argv))
		return 1;

	fd = open(swf_file,O_RDONLY);
	if (fd < 0) {
		fprintf(stderr,"Unable to open file %s\n",argv[1]);
		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;
	}

	while (swf_reader_read_record(swf,&tag)) {
		/* set read stop, so we can read the bitfields */
		swf->read_stop = swf->next_tag;

		switch (tag.record.TagCode) {
			case swftag_JPEGTables:
				/* NTS: Flash 8 and later will apparently emit Flash movies with
				 *      JPEGTables tags of zero length, followed by DefineBits
				 *      tags that contain a whole JPEG. Ooookay then... */
				if (JPEGTables == NULL) {
					JPEGTables_size = tag.record.Length;
					if (JPEGTables_size != 0) {
						JPEGTables = malloc(JPEGTables_size);
						if (JPEGTables) swf_reader_read(swf,JPEGTables,JPEGTables_size);
					}
				}
				else {
					fprintf(stderr,"WARNING: JPEGTables already defined\n");
				}

				break;
			case swftag_DefineBits: {
				swf_UI16 CharacterID;

				CharacterID = swf_reader_read_UI16(swf);
				do_definebits(swf,CharacterID);
				} break;
			case swftag_DefineBitsJPEG2: {
				swf_UI16 CharacterID;

				CharacterID = swf_reader_read_UI16(swf);
				do_definebits_jpeg2(swf,CharacterID);
				} break;
			case swftag_DefineBitsJPEG3: {
				swf_UI32 AlphaDataOffset;
				swf_UI16 CharacterID;

				CharacterID = swf_reader_read_UI16(swf);
				AlphaDataOffset = swf_reader_read_UI32(swf);
				do_definebits_jpeg3(swf,CharacterID,AlphaDataOffset);
				} break;
		}

		assert(swf->current_pos <= swf->read_stop);

		/* clear read stop */
		swf->read_stop = 0;
	}

	swf = swf_reader_destroy(swf);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1570
cmpl $0x0, %eax
je 0x12f3
movl $0x1, -0x4(%rbp)
jmp 0x1559
movq 0x9e7e(%rip), %rdi      # 0xb178
xorl %esi, %esi
movb $0x0, %al
callq 0x1170
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x1338
movq 0x9ce5(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x5d57(%rip), %rsi      # 0x707c
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1559
movb $0x0, %al
callq 0x30c0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x136d
movq 0x9ca8(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x5d3a(%rip), %rsi      # 0x7094
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1559
movq -0x18(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x32e0
cmpl $0x0, %eax
je 0x13a2
movq 0x9c73(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x5d1f(%rip), %rsi      # 0x70ae
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1559
movq -0x18(%rbp), %rdi
callq 0x3150
movq -0x18(%rbp), %rdi
callq 0x3360
cmpl $0x0, %eax
je 0x13dd
movq 0x9c38(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x5cf6(%rip), %rsi      # 0x70c0
movb $0x0, %al
callq 0x10e0
movl $0x1, -0x4(%rbp)
jmp 0x1559
jmp 0x13df
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3170
cmpl $0x0, %eax
je 0x1545
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rcx
movq %rcx, 0x60(%rax)
movzwl -0x30(%rbp), %eax
addl $-0x6, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x1d, %eax
ja 0x1501
movq -0x48(%rbp), %rax
leaq 0x5be2(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpq $0x0, 0x9d4d(%rip)      # 0xb180
jne 0x1483
movl -0x2c(%rbp), %eax
movq %rax, 0x9d49(%rip)      # 0xb188
cmpq $0x0, 0x9d41(%rip)      # 0xb188
je 0x1481
movq 0x9d38(%rip), %rdi      # 0xb188
callq 0x1130
movq %rax, 0x9d24(%rip)      # 0xb180
cmpq $0x0, 0x9d1c(%rip)      # 0xb180
je 0x147f
movq -0x18(%rbp), %rdi
movq 0x9d0f(%rip), %rsi      # 0xb180
movq 0x9d10(%rip), %rax      # 0xb188
movl %eax, %edx
callq 0x27e0
jmp 0x1481
jmp 0x149b
movq 0x9b6e(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x5c49(%rip), %rsi      # 0x70dd
movb $0x0, %al
callq 0x10e0
jmp 0x1501
movq -0x18(%rbp), %rdi
callq 0x2c20
movw %ax, -0x36(%rbp)
movq -0x18(%rbp), %rdi
movzwl -0x36(%rbp), %esi
callq 0x16c0
jmp 0x1501
movq -0x18(%rbp), %rdi
callq 0x2c20
movw %ax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movzwl -0x38(%rbp), %esi
callq 0x1ab0
jmp 0x1501
movq -0x18(%rbp), %rdi
callq 0x2c20
movw %ax, -0x3e(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2c90
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movw -0x3e(%rbp), %ax
movl -0x3c(%rbp), %edx
movzwl %ax, %esi
callq 0x1d30
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x60(%rcx), %rax
ja 0x1515
jmp 0x1534
leaq 0x5be6(%rip), %rdi      # 0x7102
leaq 0x5c02(%rip), %rsi      # 0x7125
movl $0x180, %edx            # imm = 0x180
leaq 0x5c04(%rip), %rcx      # 0x7133
callq 0x1080
movq -0x18(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x13df
movq -0x18(%rbp), %rdi
callq 0x3120
movq %rax, -0x18(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)