// File: /workspace/github_c_makefile_star2_O0/yui0[P]img2vec/img2vec.c
// Function: img2vec
int img2vec(FILE *fp, uint8_t *s, int w, int h, int r, int g, int b, int flag)
{
	// create a bitmap
	potrace_bitmap_t *bm = bm_new(w, h);
	if (!bm) {
		fprintf(stderr, "Error allocating bitmap: %s\n", strerror(errno));
		return 1;
	}

	for (int y=0; y<h; y++) {
		for (int x=0; x<w; x++) {
			int n = ((h-y)*w+x)*3;
			int c = (s[n]||s[n+1]||s[n+2] ? 255 : 0);
			BM_PUT(bm, x, y, c);
		}
	}

	// set tracing parameters, starting from defaults
	potrace_param_t *param = potrace_param_default();
	if (!param) {
		fprintf(stderr, "Error allocating parameters: %s\n", strerror(errno));
		return 1;
	}
	param->turdsize = 0;

	// trace the bitmap
	potrace_state_t *st = potrace_trace(param, bm);
	if (!st || st->status != POTRACE_STATUS_OK) {
		fprintf(stderr, "Error tracing bitmap: %s\n", strerror(errno));
		return 1;
	}
	bm_free(bm);

	// output vector data, e.g. as a rudimentary EPS file
	//printf("%%!PS-Adobe-3.0 EPSF-3.0\n");
	//printf("%%%%BoundingBox: 0 0 %d %d\n", w, h);
	if (!(flag&32)) fprintf(fp, "gsave\n");
	if (flag&32) fprintf(fp, "<g id=\"#%02x%02x%02x\">\n", r, g, b);
	potrace_path_t *p = st->plist;
	potrace_dpoint_t (*c)[3];
	while (p != NULL) {
		int n = p->curve.n;
		int *tag = p->curve.tag;
		c = p->curve.c;
		if (!(flag&32)) fprintf(fp, "%f %f moveto\n", c[n-1][2].x, c[n-1][2].y);
		//if (flag&32) fprintf(fp, "<path d=\"M%f,%f", c[n-1][2].x, h-c[n-1][2].y);
		if (flag&32) fprintf(fp, "<path d=\"M" ACCURACY "," ACCURACY "", c[n-1][2].x, h-c[n-1][2].y);
		for (int i=0; i<n; i++) {
			switch (tag[i]) {
			case POTRACE_CORNER:
				if (!(flag&32)) fprintf(fp, "%f %f lineto\n", c[i][1].x, c[i][1].y);
				if (!(flag&32)) fprintf(fp, "%f %f lineto\n", c[i][2].x, c[i][2].y);
				//if (flag&32) fprintf(fp, " L%f,%f L%f,%f", c[i][1].x, h-c[i][1].y, c[i][2].x, h-c[i][2].y);
				if (flag&32) fprintf(fp, " L" ACCURACY "," ACCURACY " L" ACCURACY "," ACCURACY "", c[i][1].x, h-c[i][1].y, c[i][2].x, h-c[i][2].y);
				break;
			case POTRACE_CURVETO:
				if (!(flag&32)) fprintf(fp, "%f %f %f %f %f %f curveto\n",
				       c[i][0].x, c[i][0].y,
				       c[i][1].x, c[i][1].y,
				       c[i][2].x, c[i][2].y);
				//if (flag&32) fprintf(fp, " C%f,%f %f,%f %f,%f",
				if (flag&32) fprintf(fp, " C" ACCURACY "," ACCURACY " " ACCURACY "," ACCURACY " " ACCURACY "," ACCURACY "",
					c[i][0].x, h-c[i][0].y, c[i][1].x, h-c[i][1].y, c[i][2].x, h-c[i][2].y);
				break;
			}
		}
		/* at the end of a group of a positive path and its negative
		   children, fill. */
		if (p->next == NULL || p->next->sign == '+') {
			//printf("0 setgray fill\n");
			if (!(flag&32)) fprintf(fp, "%f %f %f setrgbcolor fill\n", r/255.0, g/255.0, b/255.0);
//			if (flag&32) fprintf(fp, "\" stroke=\"#%02x%02x%02x\"/>", r, g, b);
//		} else {
//			if (flag&32) fprintf(fp, "\" fill=\"#%02x%02x%02x\"/>", r, g, b);
		}
		p = p->next;
		if (flag&32) fprintf(fp, "\" fill=\"#%02x%02x%02x\" stroke=\"#%02x%02x%02x", r, g, b, r, g, b);
		if (flag&32) fprintf(fp, "\"/>\n");
//		if (flag&32) fprintf(fp, "\" stroke=\"#%02x%02x%02x\"/>", r, g, b);
//		if (flag&32) fprintf(fp, "\" fill=\"#%02x%02x%02x\"/>", r, g, b);
	}
	if (!(flag&32)) fprintf(fp, "grestore\n");
	if (flag&32) fprintf(fp, "</g>\n");
	//printf("%%EOF\n");

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0xdc10
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xd498
movq 0x2cb94(%rip), %rax     # 0x39ff8
movq (%rax), %rax
movq %rax, -0x80(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x1230
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x24d5f(%rip), %rsi     # 0x321e4
movb $0x0, %al
callq 0x1140
movl $0x1, -0x4(%rbp)
jmp 0xdbfa
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd669
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xd659
movl -0x20(%rbp), %eax
subl -0x34(%rbp), %eax
imull -0x1c(%rbp), %eax
addl -0x38(%rbp), %eax
imull $0x3, %eax, %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
jne 0xd525
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
jne 0xd525
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %dl
xorl %eax, %eax
movl $0xff, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x38(%rbp)
jl 0xd649
movl -0x38(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xd649
cmpl $0x0, -0x34(%rbp)
jl 0xd649
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0xd649
cmpl $0x0, -0x40(%rbp)
je 0xd5d9
movl -0x38(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
shrq %cl, %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x34(%rbp), %rax
movq -0x30(%rbp), %rdx
movslq 0x8(%rdx), %rdx
imulq %rdx, %rax
shlq $0x3, %rax
addq %rax, %rcx
movl -0x38(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x98(%rbp), %rax
movslq %edx, %rdx
orq (%rcx,%rdx,8), %rax
movq %rax, (%rcx,%rdx,8)
movq %rax, -0x90(%rbp)
jmp 0xd640
movl -0x38(%rbp), %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
shrq %cl, %rax
xorq $-0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x34(%rbp), %rax
movq -0x30(%rbp), %rdx
movslq 0x8(%rdx), %rdx
imulq %rdx, %rax
shlq $0x3, %rax
addq %rax, %rcx
movl -0x38(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0xa0(%rbp), %rax
movslq %edx, %rdx
andq (%rcx,%rdx,8), %rax
movq %rax, (%rcx,%rdx,8)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
jmp 0xd64b
jmp 0xd64b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xd4b2
jmp 0xd65b
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd49f
callq 0xd060
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xd6ba
movq 0x2c978(%rip), %rax     # 0x39ff8
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x1230
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
leaq 0x24b5a(%rip), %rsi     # 0x32201
movb $0x0, %al
callq 0x1140
movl $0x1, -0x4(%rbp)
jmp 0xdbfa
movq -0x48(%rbp), %rax
movl $0x0, (%rax)
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xd0b0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xd6e5
movq -0x50(%rbp), %rax
cmpl $0x0, (%rax)
je 0xd726
movq 0x2c90c(%rip), %rax     # 0x39ff8
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x1230
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0x24b0f(%rip), %rsi     # 0x32222
movb $0x0, %al
callq 0x1140
movl $0x1, -0x4(%rbp)
jmp 0xdbfa
movq -0x30(%rbp), %rdi
callq 0xd020
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xd74c
movq -0x10(%rbp), %rdi
leaq 0x24af7(%rip), %rsi     # 0x3223c
movb $0x0, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xd773
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movl 0x10(%rbp), %r8d
leaq 0x24ad7(%rip), %rsi     # 0x32243
movb $0x0, %al
callq 0x1140
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0xdbb9
movq -0x58(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xd7fb
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x28(%rax), %xmm1
leaq 0x24a67(%rip), %rsi     # 0x3225b
movb $0x2, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xd84f
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x28(%rax), %xmm1
leaq 0x24a21(%rip), %rsi     # 0x32269
movb $0x2, %al
callq 0x1140
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0xdae6
movq -0x70(%rbp), %rax
movslq -0x74(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xb4(%rbp)
subl $0x1, %eax
je 0xd995
jmp 0xd87e
movl -0xb4(%rbp), %eax
subl $0x2, %eax
jne 0xdad6
jmp 0xd88f
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xd8d4
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm1
leaq 0x249b0(%rip), %rsi     # 0x3227d
movb $0x2, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xd919
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm0
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x28(%rax), %xmm1
leaq 0x2496b(%rip), %rsi     # 0x3227d
movb $0x2, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xd990
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x18(%rax), %xmm1
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm2
cvtsi2sdl -0x20(%rbp), %xmm3
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x28(%rax), %xmm3
leaq 0x24902(%rip), %rsi     # 0x3228b
movb $0x4, %al
callq 0x1140
jmp 0xdad6
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xda2d
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm2
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm3
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm4
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x28(%rax), %xmm5
leaq 0x2487c(%rip), %rsi     # 0x322a2
movb $0x6, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xdad4
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
cvtsi2sdl -0x20(%rbp), %xmm1
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm2
cvtsi2sdl -0x20(%rbp), %xmm3
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x18(%rax), %xmm3
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x20(%rax), %xmm4
cvtsi2sdl -0x20(%rbp), %xmm5
movq -0x60(%rbp), %rax
movslq -0x74(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
subsd 0x28(%rax), %xmm5
leaq 0x247f0(%rip), %rsi     # 0x322bd
movb $0x6, %al
callq 0x1140
jmp 0xdad6
jmp 0xdad8
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xd856
movq -0x58(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xdaff
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
cmpl $0x2b, 0x4(%rax)
jne 0xdb51
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xdb4f
movq -0x10(%rbp), %rdi
cvtsi2sdl -0x24(%rbp), %xmm0
movsd 0x244f5(%rip), %xmm1    # 0x32010
divsd %xmm1, %xmm0
cvtsi2sdl -0x28(%rbp), %xmm1
movsd 0x244e4(%rip), %xmm2    # 0x32010
divsd %xmm2, %xmm1
cvtsi2sdl 0x10(%rbp), %xmm2
movsd 0x244d3(%rip), %xmm3    # 0x32010
divsd %xmm3, %xmm2
leaq 0x24795(%rip), %rsi     # 0x322dd
movb $0x3, %al
callq 0x1140
jmp 0xdb51
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xdb97
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl -0x24(%rbp), %r9d
movl -0x28(%rbp), %r10d
movl 0x10(%rbp), %eax
leaq 0x24770(%rip), %rsi     # 0x322f8
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xdbb4
movq -0x10(%rbp), %rdi
leaq 0x24778(%rip), %rsi     # 0x32325
movb $0x0, %al
callq 0x1140
jmp 0xd77f
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xdbd6
movq -0x10(%rbp), %rdi
leaq 0x2475b(%rip), %rsi     # 0x3232a
movb $0x0, %al
callq 0x1140
movl 0x18(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xdbf3
movq -0x10(%rbp), %rdi
leaq 0x24748(%rip), %rsi     # 0x32334
movb $0x0, %al
callq 0x1140
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)