// File: /workspace/github_c_makefile_star2_O1/kyx0r[P]xkeyboard/xkeyboard.c
// Function: scale_pic
Pixmap scale_pic(struct scaledata *p, int kw, int kh, int num)
{
	Pixmap px;
	int x, y, w, h, pel, bpp, sx, sy, o, r, g, b;
	XImage *myimage;

	w = kw * sn / sd;
	h = kh * sn / sd;

	px = XCreatePixmap(dpy, mywindow, w, h,
		DefaultDepth(dpy, myscreen));
	if(!(myimage = XGetImage(dpy, px,
	   0, 0, w, h, AllPlanes, ZPixmap))) {
		fprintf(stderr, "XGetImage failed for num %d {%d, %d}\n", num, kw, kh);
		exit(1);
	}
	/* 
	   to not resize
	   sx = sy = 256;
	 */
	sx = p->pgm->width * 256 / w;
	sy = p->pgm->height * 256 / h; 
	bpp = myimage->bits_per_pixel / 8;

	for (y = 0; y < h; y++)
		for (x = 0; x < w; x++) {
			o = myimage->bytes_per_line * y + x * bpp;
			pel = p->pgm->data[((sy * y)>>8) * p->pgm->width +
				((sx * x)>>8)];
			if (getenv("COLORKEYS") &&
			    (!num || num == 6 || num == 9 || num == 11)) {
				r = pel * 9 / 8;
				g = pel * 9 / 8;
				b = pel * 11 / 8;
				if (b > 255)
					b = 255;
				if (r > 255)
					r = 255;
				if (g > 255)
					g = 255;
			} else {
				r = g = b = pel;
			}
			if (myimage->depth == 16) {
				pel = ((r<<8)&63488)|((g<<3)&2016)|
					((b>>3)&31);
				myimage->data[o] = pel;
				myimage->data[o + 1] = (pel >> 8);
			} else if (myimage->depth == 15) {
				pel = ((r<<7)&31744)|((g<<2)&992)|
					((b>>3)&31);
				myimage->data[o] = pel;
				myimage->data[o + 1] = (pel >> 8);
			} else if (myimage->depth >= 24 ) {	/* 24/32 bpp */
				myimage->data[o] = r;
				myimage->data[o + 1] = g;
				myimage->data[o + 2] = b;
			} else {	/* 8bpp */
				myimage->data[o] = pel;
			}
	}
	XPutImage(dpy, px, mygc, myimage, 0, 0, 0, 0, w, h);
	XDestroyImage(myimage);
	return px;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, 0x14(%rsp)
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %rbp
movl 0x160b1(%rip), %ecx     # 0x18a30
movl %ecx, %eax
imull %esi, %eax
movl 0x160aa(%rip), %esi     # 0x18a34
cltd
idivl %esi
movl %eax, %ebx
imull %r12d, %ecx
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %r14d
movq 0x15e56(%rip), %rdi     # 0x187f8
movq 0x15fc7(%rip), %rsi     # 0x18970
movq 0xe8(%rdi), %rax
movslq 0x15e49(%rip), %rcx     # 0x18800
shlq $0x7, %rcx
movl 0x38(%rax,%rcx), %r8d
movl %ebx, %edx
movl %r14d, %ecx
callq 0x2390
movq 0x15e27(%rip), %rdi     # 0x187f8
movq %rax, 0x30(%rsp)
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebx, %r8d
movl %r14d, %r9d
pushq $0x2
pushq $-0x1
callq 0x23a0
addq $0x10, %rsp
testq %rax, %rax
je 0x2c17
movq %rax, %r8
movq 0x8(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
shll $0x8, %eax
cltd
idivl %ebx
movl %eax, 0x20(%rsp)
shll $0x8, %ecx
movl %ecx, %eax
cltd
idivl %r14d
movl %eax, 0x1c(%rsp)
movl 0x30(%r8), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
movl %ecx, 0x18(%rsp)
testl %r14d, %r14d
jle 0x2bcb
sarl $0x3, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbp, 0x40(%rsp)
movq %r14, 0x38(%rsp)
testl %ebx, %ebx
jle 0x2bae
movl 0xc(%rsp), %eax
imull 0x1c(%rsp), %eax
sarl $0x8, %eax
movl %eax, 0x24(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movl %eax, 0x10(%rsp)
movq %r8, %r14
movl 0x2c(%r8), %r15d
imull 0xc(%rsp), %r15d
movq 0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movl (%rax), %eax
imull 0x24(%rsp), %eax
movl %r13d, %edx
sarl $0x8, %edx
addl %eax, %edx
movslq %edx, %rax
movb (%rcx,%rax), %bpl
movzbl %bpl, %r12d
leaq 0x35fe(%rip), %rdi      # 0x60ab
callq 0x2040
testq %rax, %rax
je 0x2afd
movl 0x14(%rsp), %eax
cmpl $0xb, %eax
movq %r14, %r8
ja 0x2b05
movl $0xa41, %ecx            # imm = 0xA41
btl %eax, %ecx
jae 0x2b05
leal (%r12,%r12,4), %eax
leal (%r12,%rax,2), %eax
shrl $0x3, %eax
movl $0xff, %ecx
cmpl %ecx, %eax
jb 0x2ae6
movl $0xff, %eax
movl %r12d, %edx
shrl $0x3, %edx
addl %r12d, %edx
cmpl %ecx, %edx
jb 0x2af8
movl $0xff, %edx
movl %edx, %r12d
jmp 0x2b08
movl %r12d, %eax
movq %r14, %r8
jmp 0x2b08
movl %r12d, %eax
addl %ebx, %r15d
movl 0x28(%r8), %edx
cmpl $0xf, %edx
je 0x2b37
cmpl $0x10, %edx
jne 0x2b81
movl %r12d, %ecx
shll $0x8, %ecx
andl $0xf800, %ecx           # imm = 0xF800
movl %r12d, %edx
andl $0x1c, %edx
leal (%rcx,%r12,8), %ecx
shrl $0x3, %eax
leal (%rax,%rdx,8), %eax
jmp 0x2b53
movl %r12d, %ecx
shll $0x7, %ecx
andl $0x7c00, %ecx           # imm = 0x7C00
movl %r12d, %edx
andl $0x38, %edx
leal (%rcx,%r12,4), %ecx
shrl $0x3, %eax
leal (%rax,%rdx,4), %eax
movq 0x10(%r8), %rdx
movslq %r15d, %rsi
movb %al, (%rdx,%rsi)
movq 0x10(%r8), %rax
movb %ch, 0x1(%rax,%rsi)
movl 0x10(%rsp), %eax
addl 0x20(%rsp), %r13d
addl 0x18(%rsp), %ebx
decl %eax
movq 0x40(%rsp), %rbp
jne 0x2a73
jmp 0x2bae
movslq %r15d, %rcx
cmpl $0x18, %edx
jl 0x2ba4
movq 0x10(%r8), %rdx
movb %r12b, (%rdx,%rcx)
movq 0x10(%r8), %rdx
movb %r12b, 0x1(%rdx,%rcx)
movq 0x10(%r8), %rdx
movb %al, 0x2(%rdx,%rcx)
jmp 0x2b65
movq 0x10(%r8), %rax
movb %bpl, (%rax,%rcx)
jmp 0x2b65
movl 0xc(%rsp), %eax
incl %eax
movq 0x38(%rsp), %r14
movl %eax, 0xc(%rsp)
cmpl %r14d, %eax
movq 0x28(%rsp), %rbx
jne 0x2a51
movq 0x15c26(%rip), %rdi     # 0x187f8
movq 0x15e37(%rip), %rdx     # 0x18a10
xorl %eax, %eax
movq 0x30(%rsp), %r15
movq %r15, %rsi
movq %r8, %rcx
movq %r8, %r12
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %rbx
pushq %rax
pushq %rax
callq 0x2310
addq $0x20, %rsp
movq %r12, %rdi
callq *0x60(%r12)
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x53da(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x345d(%rip), %rsi      # 0x6085
movl 0x14(%rsp), %edx
movl %r13d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x2190
movl $0x1, %edi
callq 0x2350