// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x68f0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x8ffdb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x90291
leaq 0x50c9a(%rip), %rax     # 0xe0c7c
cmpl $0x0, (%rax)
je 0x8ffee
xorl %eax, %eax
movl %eax, -0x48(%rbp)
jmp 0x8fffa
leaq 0x16556f(%rip), %rax    # 0x1f5564
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movslq %eax, %rcx
leaq 0x3e19f9(%rip), %rax    # 0x471a00
shlq $0x8, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x900aa
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x900a5
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movzbl (%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movzbl 0x1(%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x44(%rbp), %rdx
movzbl 0x2(%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $-0x1, 0x3(%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x90029
jmp 0x901dd
movslq -0x20(%rbp), %rcx
leaq 0x34558b(%rip), %rax    # 0x3d5640
cmpq $0x0, (%rax,%rcx,8)
jne 0x900c3
movl $0x0, -0x20(%rbp)
movl -0x14(%rbp), %eax
imull -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x901db
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rdx
leaq 0x345557(%rip), %rcx    # 0x3d5640
movq (%rcx,%rdx,8), %rcx
movq -0x30(%rbp), %rdx
movslq -0x44(%rbp), %rsi
movzbl 0x3(%rdx,%rsi,4), %edx
movzbl (%rcx,%rdx), %ecx
imull $0x3, %ecx, %ecx
addl $0x2, %ecx
movslq %ecx, %rdx
leaq 0x229002(%rip), %rcx    # 0x2b9110
movzbl (%rcx,%rdx), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rdx
leaq 0x34550a(%rip), %rcx    # 0x3d5640
movq (%rcx,%rdx,8), %rcx
movq -0x30(%rbp), %rdx
movslq -0x44(%rbp), %rsi
movzbl 0x3(%rdx,%rsi,4), %edx
movzbl (%rcx,%rdx), %ecx
imull $0x3, %ecx, %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x228fb5(%rip), %rcx    # 0x2b9110
movzbl (%rcx,%rdx), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rdx
leaq 0x3454bd(%rip), %rcx    # 0x3d5640
movq (%rcx,%rdx,8), %rcx
movq -0x30(%rbp), %rdx
movslq -0x44(%rbp), %rsi
movzbl 0x3(%rdx,%rsi,4), %edx
movzbl (%rcx,%rdx), %ecx
imull $0x3, %ecx, %ecx
addl $0x0, %ecx
movslq %ecx, %rdx
leaq 0x228f68(%rip), %rcx    # 0x2b9110
movzbl (%rcx,%rdx), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $-0x1, 0x3(%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x900d0
jmp 0x901dd
movl $0x1, %edi
leaq -0x24(%rbp), %rsi
leaq 0x55d523(%rip), %rax    # 0x5ed710
callq *0xb8(%rax)
leaq 0x55d516(%rip), %rax    # 0x5ed710
movq 0xc8(%rax), %rax
movl -0x24(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *%rax
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
leaq 0x55d4ef(%rip), %rax    # 0x5ed710
callq *0xe8(%rax)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
leaq 0x55d4d3(%rip), %rax    # 0x5ed710
callq *0xe8(%rax)
leaq 0x55d4c6(%rip), %rax    # 0x5ed710
movq 0xd0(%rax), %rax
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movq -0x38(%rbp), %r10
movl $0xde1, %edi            # imm = 0xDE1
xorl %r9d, %r9d
movl $0x1908, %edx           # imm = 0x1908
movl %r9d, %esi
movl $0x1908, (%rsp)         # imm = 0x1908
movl $0x1401, 0x8(%rsp)      # imm = 0x1401
movq %r10, 0x10(%rsp)
callq *%rax
movq -0x38(%rbp), %rdi
callq 0x61c0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)