// File: /workspace/github_c_makefile_star2_O0/Hazematman[P]BSP-Renderer/texture.c
// Function: readPltTex
Texture *readPltTex(uint8_t *texData, int width, int height, Palette *plt, const char *name){
	Texture *tex = malloc(sizeof(Texture));
	tex->width = width;
	tex->height = height;
	tex->data = malloc(sizeof(colour3UByte)*width*height);
	tex->name = malloc(strlen(name)+1);

	// Copy name
	strcpy(tex->name, name);

	// Load and convert all paletted colour data	
	for(int i = 0; i < width*height; i++){
		tex->data[i] = getPaletteColour(plt, texData[i]);
	}

	glGenTextures(1, &tex->glId);
	glBindTexture(GL_TEXTURE_2D, tex->glId);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,
			0,
			GL_RGB,
			width,
			height,
			0,
			GL_RGB,
			GL_UNSIGNED_BYTE,
			tex->data);


	return tex;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl $0x20, %edi
callq 0x1170
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movslq -0xc(%rbp), %rax
imulq $0x3, %rax, %rdi
movslq -0x10(%rbp), %rax
imulq %rax, %rdi
callq 0x1170
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rdi
callq 0x1080
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1170
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1100
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x5e43
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rdx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movzbl (%rax,%rcx), %esi
callq 0x5b50
movl %eax, %ecx
movq -0x38(%rbp), %rax
movw %cx, %dx
movw %dx, -0x2f(%rbp)
shrl $0x10, %ecx
movb %cl, -0x2d(%rbp)
movw -0x2f(%rbp), %cx
movw %cx, (%rax)
movb -0x2d(%rbp), %cl
movb %cl, 0x2(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5de2
leaq 0x6506(%rip), %rax      # 0xc350
movq (%rax), %rax
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
movl $0x1, %edi
callq *%rax
leaq 0x64ad(%rip), %rax      # 0xc310
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movl 0x8(%rcx), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *%rax
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
leaq 0x646e(%rip), %rax      # 0xc2f8
callq *(%rax)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
leaq 0x6456(%rip), %rax      # 0xc2f8
callq *(%rax)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2802, %esi           # imm = 0x2802
movl $0x2901, %edx           # imm = 0x2901
leaq 0x643e(%rip), %rax      # 0xc2f8
callq *(%rax)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2803, %esi           # imm = 0x2803
movl $0x2901, %edx           # imm = 0x2901
leaq 0x6426(%rip), %rax      # 0xc2f8
callq *(%rax)
leaq 0x6405(%rip), %rax      # 0xc2e0
movq (%rax), %rax
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %r8d
movq -0x28(%rbp), %rdx
movq 0x18(%rdx), %r10
movl $0xde1, %edi            # imm = 0xDE1
xorl %r9d, %r9d
movl $0x1907, %edx           # imm = 0x1907
movl %r9d, %esi
movl $0x1907, (%rsp)         # imm = 0x1907
movl $0x1401, 0x8(%rsp)      # imm = 0x1401
movq %r10, 0x10(%rsp)
callq *%rax
movq -0x28(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)