// File: /workspace/github_c_makefile_star2_O2/ender672[P]liboil/imgscale.c
// Function: png
static void png(FILE *input, FILE *output, int width, int height)
{
	int i, in_width, in_height, ret;
	png_structp rpng, wpng;
	png_infop rinfo, winfo;
	png_byte ctype;
	struct oil_libpng ol;
	unsigned char *outbuf;

	rpng = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

	if (setjmp(png_jmpbuf(rpng))) {
		fprintf(stderr, "PNG Decoding Error.\n");
		exit(1);
	}

	rinfo = png_create_info_struct(rpng);
	png_init_io(rpng, input);
	png_read_info(rpng, rinfo);

	png_set_packing(rpng);
	png_set_strip_16(rpng);
	png_set_expand(rpng);
	png_set_interlace_handling(rpng);
	png_read_update_info(rpng, rinfo);

	in_width = png_get_image_width(rpng, rinfo);
	in_height = png_get_image_height(rpng, rinfo);
	oil_fix_ratio(in_width, in_height, &width, &height);

	wpng = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	winfo = png_create_info_struct(wpng);
	png_init_io(wpng, output);

	ret = oil_libpng_init(&ol, rpng, rinfo, width, height);
	if (ret!=0) {
		fprintf(stderr, "Unable to allocate buffers.\n");
		exit(1);
	}

	ctype = png_get_color_type(rpng, rinfo);
	png_set_IHDR(wpng, winfo, width, height, 8, ctype, PNG_INTERLACE_NONE,
		PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);

	png_write_info(wpng, winfo);

	outbuf = malloc(width * OIL_CMP(ol.os.cs));
	if (!outbuf) {
		fprintf(stderr, "Unable to allocate buffers.\n");
		exit(1);
	}

	for(i=0; i<height; i++) {
		oil_libpng_read_scanline(&ol, outbuf);
		png_write_row(wpng, outbuf);
	}

	png_write_end(wpng, winfo);
	png_destroy_write_struct(&wpng, &winfo);
	png_destroy_read_struct(&rpng, &rinfo, NULL);

	free(outbuf);
	oil_libpng_free(&ol);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
movl %edx, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
leaq 0x78b(%rip), %rdi       # 0x51d8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x2230
movq %rax, %r14
movq %rax, 0x30(%rsp)
movq 0x2575(%rip), %rsi      # 0x6fe0
movl $0xc8, %edx
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x2090
testl %eax, %eax
jne 0x4c4e
movq %r14, %rdi
callq 0x2250
movq %rax, %r15
movq %rax, 0x20(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x22c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x22a0
movq %r14, %rdi
callq 0x2210
movq %r14, %rdi
callq 0x2190
movq %r14, %rdi
callq 0x2140
movq %r14, %rdi
movq %r15, %rsi
callq 0x21b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2120
movl %eax, %ebp
movq %r14, %rdi
movq %r15, %rsi
callq 0x22f0
leaq 0xc(%rsp), %rbx
leaq 0x8(%rsp), %r13
movl %ebp, %edi
movl %eax, %esi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x3f1c
leaq 0x6c7(%rip), %rdi       # 0x51d8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x2380
movq %rax, %rbp
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x2250
movq %rax, %r12
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x22c0
movl (%rbx), %ecx
movl (%r13), %r8d
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4338
testl %eax, %eax
jne 0x4c39
movq %r15, %rsi
movq %rbp, %rbx
movq %r12, %r15
movq %r14, %rdi
callq 0x2130
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movzbl %al, %r9d
subq $0x8, %rsp
pushq $0x8
popq %r8
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x0
pushq $0x0
pushq $0x0
callq 0x2360
addq $0x20, %rsp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x22b0
movzbl 0x48(%rsp), %eax
imull 0xc(%rsp), %eax
movl %eax, %edi
callq 0x20d0
testq %rax, %rax
je 0x4c39
movq %rax, %r14
xorl %ebp, %ebp
leaq 0x38(%rsp), %r12
cmpl 0x8(%rsp), %ebp
jge 0x4be8
movq %r12, %rdi
movq %r14, %rsi
callq 0x4540
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21d0
incl %ebp
jmp 0x4bc8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x20a0
leaq 0x28(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2320
xorl %eax, %eax
movl %eax, %edx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2070
movq %r14, %rdi
callq 0x21a0
leaq 0x38(%rsp), %rdi
callq 0x44e8
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x23a8(%rip), %rax      # 0x6fe8
movq (%rax), %rcx
leaq 0x5aa(%rip), %rdi       # 0x51f4
pushq $0x1c
jmp 0x4c61
movq 0x2393(%rip), %rax      # 0x6fe8
movq (%rax), %rcx
leaq 0x580(%rip), %rdi       # 0x51df
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
pushq $0x1
popq %rdi
callq 0x20c0