// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl %edx, 0x24(%rsp)
movl %ecx, 0x14(%rsp)
leaq 0x4b0(%rip), %rdi       # 0x5218
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x2240
movq %rax, 0x8(%rsp)
movq 0x225d(%rip), %rsi      # 0x6fe0
movl $0xc8, %edx
movq %rax, %rdi
callq 0x21f0
movq %rax, %rdi
callq 0x20a0
testl %eax, %eax
jne 0x4f80
movq 0x8(%rsp), %rdi
callq 0x2260
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x22d0
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
callq 0x22b0
movq 0x8(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %rdi
callq 0x21a0
movq 0x8(%rsp), %rdi
callq 0x2150
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x21c0
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2130
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2300
leaq 0x24(%rsp), %r14
leaq 0x14(%rsp), %r15
movl %ebp, %edi
movl %eax, %esi
movq %r14, %rdx
movq %r15, %rcx
callq 0x4322
leaq 0x3d6(%rip), %rdi       # 0x5218
xorl %ebp, %ebp
movl %ebp, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x2390
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x2260
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x22d0
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl (%r14), %ecx
movl (%r15), %r8d
leaq 0x38(%rsp), %rdi
callq 0x4690
testl %eax, %eax
jne 0x4f85
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2140
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x24(%rsp), %edx
movl 0x14(%rsp), %ecx
movzbl %al, %r9d
subq $0x8, %rsp
movl %ebp, %eax
movl $0x8, %r8d
pushq %rax
pushq %rax
pushq %rax
callq 0x2370
addq $0x20, %rsp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x22c0
movzbl 0x48(%rsp), %eax
imull 0x24(%rsp), %eax
movl %eax, %edi
callq 0x20e0
testq %rax, %rax
je 0x4f8a
movq %rax, %rbx
cmpl $0x0, 0x14(%rsp)
jle 0x4f2d
xorl %eax, %eax
leaq 0x38(%rsp), %r14
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x48cf
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x21e0
incl %ebp
movl %ebp, %eax
cmpl 0x14(%rsp), %ebp
jl 0x4f09
leaq 0x28(%rsp), %r14
movq (%r14), %rdi
leaq 0x30(%rsp), %r15
movq (%r15), %rsi
callq 0x20b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2330
xorl %eax, %eax
movl %eax, %edx
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2080
movq %rbx, %rdi
callq 0x21b0
leaq 0x38(%rsp), %rdi
callq 0x4876
addq $0xb8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x24fd
callq 0x2522
callq 0x2547