// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/mdsprite.c
// Function: gloadtex
unsigned gloadtex (int *picbuf, int xsiz, int ysiz, int is8bit, int dapal)
{
	unsigned rtexid;
	coltype *pic, *pic2;
	unsigned char *cptr;
	int i;

	pic = (coltype *)picbuf; //Correct for GL's RGB order; also apply gamma here..
	pic2 = (coltype *)malloc(xsiz*ysiz*sizeof(coltype)); if (!pic2) return((unsigned)-1);
	cptr = (unsigned char*)&britable[usegammabrightness ? 0 : curbrightness][0];
	if (!is8bit)
	{
		for(i=xsiz*ysiz-1;i>=0;i--)
		{
			pic2[i].b = cptr[pic[i].r];
			pic2[i].g = cptr[pic[i].g];
			pic2[i].r = cptr[pic[i].b];
			pic2[i].a = 255;
		}
	}
	else
	{
		if (palookup[dapal] == 0) dapal = 0;
		for(i=xsiz*ysiz-1;i>=0;i--)
		{
			pic2[i].b = cptr[palette[(int)palookup[dapal][pic[i].a]*3+2]*4];
			pic2[i].g = cptr[palette[(int)palookup[dapal][pic[i].a]*3+1]*4];
			pic2[i].r = cptr[palette[(int)palookup[dapal][pic[i].a]*3+0]*4];
			pic2[i].a = 255;
		}
	}

	glfunc.glGenTextures(1,(GLuint*)&rtexid);
	glfunc.glBindTexture(GL_TEXTURE_2D,rtexid);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glfunc.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glfunc.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,xsiz,ysiz,0,GL_RGBA,GL_UNSIGNED_BYTE,(unsigned char *)pic2);
	free(pic2);
	return(rtexid);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %r12d
movl %ecx, %r13d
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r15
movl %edx, (%rsp)
imull %esi, %ebx
movslq %ebx, %rdi
shlq $0x2, %rdi
callq 0x69a0
testq %rax, %rax
je 0x56ca4
movq %rax, %r14
leaq 0x46b7a(%rip), %rcx     # 0x9d78c
xorl %eax, %eax
cmpl $0x0, (%rcx)
jne 0x56c22
leaq 0x15ade4(%rip), %rax    # 0x1b1a04
movl (%rax), %eax
cltq
shlq $0x8, %rax
addq 0x353a1(%rip), %rax     # 0x8bfd0
testl %r13d, %r13d
je 0x56cac
movslq %r12d, %rcx
leaq 0x33aea2(%rip), %rdx    # 0x391ae0
movq (%rdx,%rcx,8), %rsi
testq %rsi, %rsi
cmoveq %rsi, %rcx
movl %ebx, %esi
leaq 0x21e95e(%rip), %rdi    # 0x2755b0
testl %esi, %esi
jle 0x56ce7
movq (%rdx,%rcx,8), %r8
movzbl -0x1(%r15,%rsi,4), %r9d
movzbl (%r8,%r9), %r8d
leaq (%r8,%r8,2), %r8
movzbl 0x2(%rdi,%r8), %r9d
movb (%rax,%r9,4), %r9b
movb %r9b, -0x2(%r14,%rsi,4)
movzbl 0x1(%rdi,%r8), %r9d
movb (%rax,%r9,4), %r9b
movb %r9b, -0x3(%r14,%rsi,4)
movzbl (%rdi,%r8), %r8d
movb (%rax,%r8,4), %r8b
movb %r8b, -0x4(%r14,%rsi,4)
movb $-0x1, -0x1(%r14,%rsi,4)
decq %rsi
jmp 0x56c52
pushq $-0x1
popq %rax
jmp 0x56d7c
movl %ebx, %ecx
testl %ecx, %ecx
jle 0x56ce7
movzbl -0x4(%r15,%rcx,4), %edx
movb (%rax,%rdx), %dl
movb %dl, -0x2(%r14,%rcx,4)
movzbl -0x3(%r15,%rcx,4), %edx
movb (%rax,%rdx), %dl
movb %dl, -0x3(%r14,%rcx,4)
movzbl -0x2(%r15,%rcx,4), %edx
movb (%rax,%rdx), %dl
movb %dl, -0x4(%r14,%rcx,4)
movb $-0x1, -0x1(%r14,%rcx,4)
decq %rcx
jmp 0x56cae
leaq 0x59ca52(%rip), %r12    # 0x5f3740
pushq $0x1
popq %rdi
leaq 0x4(%rsp), %r15
movq %r15, %rsi
callq *0xb8(%r12)
movl (%r15), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *0xc8(%r12)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
callq *0xe8(%r12)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
callq *0xe8(%r12)
subq $0x8, %rsp
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1908, %edx           # imm = 0x1908
movl %ebp, %ecx
movl 0x8(%rsp), %r8d
xorl %r9d, %r9d
pushq %r14
pushq $0x1401                 # imm = 0x1401
pushq $0x1908                 # imm = 0x1908
callq *0xd0(%r12)
addq $0x20, %rsp
movq %r14, %rdi
callq 0x61c0
movl (%r15), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq