// File: /workspace/github_c_makefile_star2_O0/TurkeyMcMac[P]ts3d/src/load-texture.c
// Function: load_texture
d3d_texture *load_texture(struct loader *ldr, const char *name)
{
	FILE *file;
	d3d_texture *txtr = NULL, **txtrp;
	txtrp = loader_texture(ldr, name, &file);
	if (!txtrp) return NULL;
	txtr = *txtrp;
	if (txtr) return txtr;
	size_t width;
	size_t height;
	struct string *lines = read_lines(file, &height);
	if (!lines) {
		logger_printf(loader_logger(ldr), LOGGER_ERROR,
			"Error while reading lines: %s\n", strerror(errno));
		return NULL;
	}
	width = 0;
	for (size_t y = 0; y < height; ++y) {
		if (lines[y].len > width) width = lines[y].len;
	}
	struct color_map *colors = loader_color_map(ldr);
	if (width > 0 && height > 0) {
		txtr = assert_alloc(d3d_new_texture(width, height,
			TRANSPARENT_PIXEL));
		for (size_t y = 0; y < height; ++y) {
			struct string *line = &lines[y];
			size_t x;
			for (x = 0; x < line->len; ++x) {
				d3d_pixel pix = pixel_from_char(line->text[x]);
				int pair = color_map_add_pair(colors, pix);
				if (pair <= 0 && pix != TRANSPARENT_PIXEL)
					logger_printf(loader_logger(ldr),
						LOGGER_WARNING,
						"Pixel not registered: %c\n",
						line->text[x]);
				*d3d_texture_get(txtr, x, y) = pix;
			}
		}
	} else {
		txtr = new_empty_texture();
	}
	for (size_t i = 0; i < height; ++i) {
		free(lines[i].text);
	}
	free(lines);
	*txtrp = txtr;
	return txtr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0x9b40
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x9614
movq $0x0, -0x8(%rbp)
jmp 0x987a
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x9633
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x987a
movq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xef70
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x9691
movq -0x10(%rbp), %rdi
callq 0x9da0
movq %rax, -0x88(%rbp)
callq 0x2320
movl (%rax), %edi
callq 0x2260
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl $0x4, %esi
leaq 0x8023(%rip), %rdx      # 0x116a0
movb $0x0, %al
callq 0xa260
movq $0x0, -0x8(%rbp)
jmp 0x987a
movq $0x0, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x96e9
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x38(%rbp), %rax
jbe 0x96d9
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x96db
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x96a1
movq -0x10(%rbp), %rdi
callq 0x9d80
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0x981d
cmpq $0x0, -0x40(%rbp)
jbe 0x981d
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0xff, %edx
callq 0x2d60
movq %rax, %rdi
callq 0x10d50
movq %rax, -0x28(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x981b
movq -0x48(%rbp), %rax
movq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x9808
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movzbl (%rax,%rcx), %eax
subl $0x20, %eax
subl $0x1, %eax
movb %al, -0x71(%rbp)
movq -0x58(%rbp), %rdi
movzbl -0x71(%rbp), %esi
callq 0xff10
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
jg 0x97d5
movzbl -0x71(%rbp), %eax
cmpl $0xff, %eax
je 0x97d5
movq -0x10(%rbp), %rdi
callq 0x9da0
movq %rax, %rdi
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x70(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x2, %esi
leaq 0x7ef1(%rip), %rdx      # 0x116bf
movb $0x0, %al
callq 0xa260
movb -0x71(%rbp), %al
movb %al, -0x89(%rbp)
movq -0x28(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x3ca0
movb -0x89(%rbp), %cl
movb %cl, (%rax)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x975b
jmp 0x980a
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x9732
jmp 0x9826
callq 0x9890
movq %rax, -0x28(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x985e
movq -0x48(%rbp), %rax
movq -0x80(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x2580
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x982e
movq -0x48(%rbp), %rdi
callq 0x2580
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)