// File: /workspace/github_cpp_makefile_star2_O3/Alcaro[P]bridges/obj/resources.cpp
// Function: resources::init_inner_core()
static void decomp_images(image * imgs, uint8_t * inflate_buf, uint8_t * inflate_buf_end, const uint8_t * deflated, size_t deflated_size)
{
	__asm__("" : "+r"(imgs)); // iterating a pointer to a single object is undefined behavior, force gcc to forget it's not an array
	uint32_t palette[(IMG_8F || IMG_87) ? 256 : 16];
	inflator::inflate(bytesw(inflate_buf, inflate_buf_end-inflate_buf), bytesr(deflated, deflated_size));
	while (inflate_buf != inflate_buf_end)
	{
		uint8_t head = *inflate_buf++;
		
		uint32_t transp = 0;
		
		// these IMG_ constants allow dead code elimination of unused image formats
		// they're also why this function is in a Python string rather than a normal cpp - can't DCE across files
		if (head&0x80)
		{
			if (IMG_8F && head == 0x8F) // grayscale
			{
				for (int i=0;i<256;i++) palette[i] = 0xFF000000 + i*0x010101;
			}
			else if (IMG_80 || IMG_81 || IMG_83 || IMG_87)
			{
				int len;
				if (IMG_87 && head == 0x87) len = *inflate_buf++;
				else if (IMG_80 || IMG_81 || IMG_83) len = (head&0x7F)>>3;
				else __builtin_unreachable();
				
				for (int i=0;i<=len;i++)
				{
					palette[i] = readu_le32(inflate_buf);
					inflate_buf += 4;
				}
			}
			else __builtin_unreachable();
			head &= 0x87; // mask out palette length
		}
		else if (IMG_BARGB && imgs->fmt == ifmt_bargb8888)
		{
			transp = readu_le32(inflate_buf);
			inflate_buf += 4;
		}
		else if (IMG_NOT_BARGB) {}
		else __builtin_unreachable();
		
		size_t line_size_raw = (((head&0x1F)+1) * imgs->width + 7) >> 3;
		size_t filtered_size = (line_size_raw+1) * imgs->height;
		size_t defiltered_line_size = line_size_raw+4;
		size_t defiltered_size = defiltered_line_size * imgs->height;
		
		uint8_t * defilter_start = inflate_buf + filtered_size - defiltered_size;
		
		image::png_defilter(defilter_start, defiltered_line_size, inflate_buf, ((head&0x1F)+7)>>3, line_size_raw, imgs->height);
		defilter_start += 4;
		
		if(0);
		else if (IMG_0F && head == 0x0F) imgs->png_unpack_rgb<4>(defilter_start, defiltered_line_size);
		else if (IMG_17 && head == 0x17) imgs->png_unpack_rgb<2>(defilter_start, defiltered_line_size);
		else if (IMG_1F && head == 0x1F) imgs->png_unpack_rgb<6>(defilter_start, defiltered_line_size);
		else if (IMG_80 && head == 0x80) imgs->png_unpack_plte<1>(defilter_start, defiltered_line_size, palette, -1);
		else if (IMG_81 && head == 0x81) imgs->png_unpack_plte<2>(defilter_start, defiltered_line_size, palette, -1);
		else if (IMG_83 && head == 0x83) imgs->png_unpack_plte<4>(defilter_start, defiltered_line_size, palette, -1);
		else if ((IMG_87 || IMG_8F) && head == 0x87) imgs->png_unpack_plte<8>(defilter_start, defiltered_line_size, palette, -1);
		else __builtin_unreachable();
		
		if (transp != 0)
		{
			uint32_t * px = imgs->pixels32;
			size_t n = imgs->width * imgs->height;
			while (n--)
			{
				if (px[n] == transp) px[n] &= 0x00FFFFFF;
			}
		}
		
		inflate_buf += filtered_size;
		imgs++;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
leaq 0x28a65(%rip), %rbx     # 0x46010
movl $0x252e1, %ebp          # imm = 0x252E1
addq 0x28a29(%rip), %rbp     # 0x45fe0
leaq 0x10(%rsp), %rdi
movq %rbp, (%rdi)
movq $0xbce7, 0x8(%rdi)      # imm = 0xBCE7
leaq 0x12c72(%rip), %rsi     # 0x30240
movl $0x1a36, %edx           # imm = 0x1A36
callq 0x9306
movl $0x30fc8, %eax          # imm = 0x30FC8
addq 0x289fc(%rip), %rax     # 0x45fe0
movq %rax, 0x8(%rsp)
movdqa 0x1469f(%rip), %xmm3    # 0x31c90
movdqa 0x12397(%rip), %xmm4    # 0x2f990
movdqa 0x1469f(%rip), %xmm5    # 0x31ca0
leaq 0x1(%rbp), %rdx
movb (%rbp), %r13b
testb %r13b, %r13b
js 0x1d628
xorl %r14d, %r14d
cmpl $0x8, 0x8(%rbx)
jne 0x1d6a3
movl 0x1(%rbp), %r14d
addq $0x5, %rbp
movq %rbp, %rdx
jmp 0x1d6a3
cmpb $-0x71, %r13b
jne 0x1d673
xorl %eax, %eax
movdqa 0x14648(%rip), %xmm0    # 0x31c80
movdqa %xmm0, %xmm1
pmuludq %xmm3, %xmm1
pshufd $0xe8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,2,3]
pshufd $0xf5, %xmm0, %xmm2     # xmm2 = xmm0[1,1,3,3]
pmuludq %xmm3, %xmm2
pshufd $0xe8, %xmm2, %xmm2     # xmm2 = xmm2[0,2,2,3]
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
paddd %xmm4, %xmm1
movdqa %xmm1, 0x20(%rsp,%rax,4)
addq $0x4, %rax
paddd %xmm5, %xmm0
cmpq $0x100, %rax            # imm = 0x100
jne 0x1d638
jmp 0x1d69c
movl %r13d, %eax
shrb $0x3, %al
movzbl %al, %eax
andl $0xf, %eax
leaq 0x4(,%rax,4), %rcx
xorl %eax, %eax
movl (%rdx,%rax), %esi
movl %esi, 0x20(%rsp,%rax)
addq $0x4, %rax
cmpq %rax, %rcx
jne 0x1d689
addq %rax, %rdx
andb $-0x79, %r13b
xorl %r14d, %r14d
movl %r13d, %eax
andb $0x1f, %al
movzbl %al, %ecx
leal 0x1(%rcx), %r8d
imull (%rbx), %r8d
addl $0x7, %r8d
shrl $0x3, %r8d
leaq 0x1(%r8), %rbp
movl 0x4(%rbx), %r9d
imulq %r9, %rbp
leaq 0x4(%r8), %r15
addq %rdx, %rbp
movq %r15, %rax
imulq %r9, %rax
movq %rbp, %r12
subq %rax, %r12
addl $0x7, %ecx
shrl $0x3, %ecx
movq %r12, %rdi
movq %r15, %rsi
callq 0xb786
addq $0x4, %r12
movzbl %r13b, %eax
cmpl $0x1e, %eax
jle 0x1d727
cmpl $0x1f, %eax
je 0x1d741
cmpl $0x80, %eax
je 0x1d751
cmpl $0x83, %eax
jne 0x1d77c
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x20(%rsp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x3cae
jmp 0x1d795
cmpl $0xf, %eax
je 0x1d76c
cmpl $0x17, %eax
jne 0x1d77c
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xbcac
jmp 0x1d795
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xbd50
jmp 0x1d795
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x20(%rsp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0xbb88
jmp 0x1d795
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xbcfa
jmp 0x1d795
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x20(%rsp), %rcx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x3d60
testl %r14d, %r14d
movdqa 0x144f0(%rip), %xmm3    # 0x31c90
movdqa 0x121e8(%rip), %xmm4    # 0x2f990
movdqa 0x144f0(%rip), %xmm5    # 0x31ca0
je 0x1d7db
movl 0x4(%rbx), %ecx
imull (%rbx), %ecx
testl %ecx, %ecx
je 0x1d7db
movq 0x10(%rbx), %rax
movl %ecx, %ecx
movl %r14d, %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
cmpl %r14d, -0x4(%rax,%rcx,4)
jne 0x1d7d6
movl %edx, -0x4(%rax,%rcx,4)
decq %rcx
jne 0x1d7cb
addq $0x18, %rbx
cmpq 0x8(%rsp), %rbp
jne 0x1d601
leaq 0x59c17(%rip), %rdi     # 0x77408
leaq 0x28aa0(%rip), %rsi     # 0x46298
callq 0x1d850
movb $0x2, 0x5a08c(%rip)     # 0x77890
movb $0x9, 0x5a07d(%rip)     # 0x77888
addb $0x2, 0x5a016(%rip)     # 0x77828
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq