// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movl %ecx, 0x34(%rsp)
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbp
movl 0x15155(%rip), %ecx     # 0x17a30
movl %ecx, %eax
imull %esi, %eax
movl 0x1514e(%rip), %esi     # 0x17a34
cltd
idivl %esi
movl %eax, %ebx
imull %r12d, %ecx
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %r14d
movq 0x14efa(%rip), %rdi     # 0x177f8
movq 0x1506b(%rip), %rsi     # 0x17970
movq 0xe8(%rdi), %rax
movslq 0x14eed(%rip), %rcx     # 0x17800
shlq $0x7, %rcx
movl 0x38(%rax,%rcx), %r8d
movl %ebx, %edx
movl %r14d, %ecx
callq 0x2390
movq 0x14ecb(%rip), %rdi     # 0x177f8
orq $-0x1, (%rsp)
movl $0x2, 0x8(%rsp)
xorl %r13d, %r13d
movq %rax, 0x58(%rsp)
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebx, %r8d
movl %r14d, %r9d
callq 0x23a0
testq %rax, %rax
je 0x2b78
movq %rax, %r8
movq 0x8(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
shll $0x8, %eax
cltd
idivl %ebx
movl %eax, 0x50(%rsp)
shll $0x8, %ecx
movl %ecx, %eax
cltd
idivl %r14d
movl %eax, 0x3c(%rsp)
movl 0x30(%r8), %eax
pushq $0x8
popq %rcx
cltd
idivl %ecx
movl %eax, 0x4c(%rsp)
testl %ebx, %ebx
movl %ebx, %eax
cmovlel %r13d, %eax
movl %eax, 0x38(%rsp)
testl %r14d, %r14d
movl %r14d, %eax
cmovlel %r13d, %eax
movl %eax, 0x48(%rsp)
xorl %eax, %eax
movl %ebx, 0x44(%rsp)
movq %rbp, 0x60(%rsp)
movl %r14d, 0x40(%rsp)
cmpl 0x48(%rsp), %eax
je 0x2b26
movl %eax, %ecx
imull 0x3c(%rsp), %ecx
sarl $0x8, %ecx
movl %ecx, 0x54(%rsp)
xorl %edx, %edx
xorl %r12d, %r12d
movl 0x38(%rsp), %r14d
movl %eax, 0x2c(%rsp)
subl $0x1, %r14d
jb 0x2b16
movq %r8, %rbx
movl 0x2c(%r8), %r13d
imull %eax, %r13d
movq 0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movl (%rax), %eax
imull 0x54(%rsp), %eax
movl %edx, 0x30(%rsp)
sarl $0x8, %edx
addl %eax, %edx
movslq %edx, %rax
movb (%rcx,%rax), %bpl
movzbl %bpl, %r15d
leaq 0x268e(%rip), %rdi      # 0x50ab
callq 0x2040
testq %rax, %rax
je 0x2a69
movl 0x34(%rsp), %eax
cmpl $0xb, %eax
movq %rbx, %r8
ja 0x2a71
movl $0xa41, %ecx            # imm = 0xA41
btl %eax, %ecx
jae 0x2a71
imull $0xb, %r15d, %eax
shrl $0x3, %eax
movl $0xff, %ecx
cmpl %ecx, %eax
jb 0x2a52
movl $0xff, %eax
movl %r15d, %edx
shrl $0x3, %edx
addl %r15d, %edx
cmpl %ecx, %edx
jb 0x2a64
movl $0xff, %edx
movl %edx, %r15d
jmp 0x2a74
movl %r15d, %eax
movq %rbx, %r8
jmp 0x2a74
movl %r15d, %eax
addl %r12d, %r13d
movl 0x28(%r8), %edx
movslq %r13d, %rcx
cmpl $0xf, %edx
je 0x2aa6
cmpl $0x10, %edx
jne 0x2aec
movl %r15d, %edx
shll $0x8, %edx
andl $0xf800, %edx           # imm = 0xF800
movl %r15d, %esi
andl $0x1c, %esi
leal (%rdx,%r15,8), %edx
shrl $0x3, %eax
leal (%rax,%rsi,8), %eax
jmp 0x2ac2
movl %r15d, %edx
shll $0x7, %edx
andl $0x7c00, %edx           # imm = 0x7C00
movl %r15d, %esi
andl $0x38, %esi
leal (%rdx,%r15,4), %edx
shrl $0x3, %eax
leal (%rax,%rsi,4), %eax
movq 0x10(%r8), %rsi
movb %al, (%rsi,%rcx)
movq 0x10(%r8), %rax
movb %dh, 0x1(%rax,%rcx)
movl 0x2c(%rsp), %eax
movl 0x30(%rsp), %edx
addl 0x4c(%rsp), %r12d
addl 0x50(%rsp), %edx
movq 0x60(%rsp), %rbp
jmp 0x29de
cmpl $0x18, %edx
jl 0x2b0c
movq 0x10(%r8), %rdx
movb %r15b, (%rdx,%rcx)
movq 0x10(%r8), %rdx
movb %r15b, 0x1(%rdx,%rcx)
movq 0x10(%r8), %rdx
movb %al, 0x2(%rdx,%rcx)
jmp 0x2ad1
movq 0x10(%r8), %rax
movb %bpl, (%rax,%rcx)
jmp 0x2ad1
incl %eax
movl 0x44(%rsp), %ebx
movl 0x40(%rsp), %r14d
jmp 0x29b8
movq 0x14ccb(%rip), %rdi     # 0x177f8
movq 0x14edc(%rip), %rdx     # 0x17a10
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movl %r14d, 0x18(%rsp)
movl %ebx, 0x10(%rsp)
movq 0x58(%rsp), %rbx
movq %rbx, %rsi
movq %r8, %rcx
movq %r8, %r14
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2310
movq %r14, %rdi
callq *0x60(%r14)
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4479(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x24fc(%rip), %rsi      # 0x5085
movl 0x34(%rsp), %edx
movl %r15d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x2190
pushq $0x1
popq %rdi
callq 0x2350