// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttexcompress.cc
// Function: compressetc1(unsigned char*, int, int, unsigned char*)
static void compressetc1(uint8_t *bgra, int width, int height, uint8_t *out)
{
	rg_etc1::etc1_pack_params params;
	uint8_t block[4][4][4];
	int x, y, s, t, xyoff, stride;

	static int initonce = 0;
	if (!initonce) {
		rg_etc1::pack_etc1_block_init();
		initonce = 1;
	}

	switch (gltexcomprquality) {
		case 2: params.m_quality = rg_etc1::cHighQuality; break;
		case 1: params.m_quality = rg_etc1::cMediumQuality; break;
		default: params.m_quality = rg_etc1::cLowQuality; break;
	}

	stride = width * 4;
	for (y = 0; y < height; y += 4) {
		for (x = 0; x < width; x += 4) {
			xyoff = y * stride + x * 4;

			// Copy the block of pixels to encode, byte swizzling to RGBA order.
			for (t = 0; t < min(4, height - y); t++) {
				for (s = 0; s < min(4, width - x); s++) {
					block[t][s][0] = bgra[xyoff + t * stride + s * 4 + 2];
					block[t][s][1] = bgra[xyoff + t * stride + s * 4 + 1];
					block[t][s][2] = bgra[xyoff + t * stride + s * 4 + 0];
					block[t][s][3] = 255;
				}
				// Repeat the final pixel to pad to 4.
				for (; s < 4; s++) {
					memcpy(&block[t][s][0], &block[t][s-1][0], 4);
				}
			}
			// Repeat the final row to pad to 4.
			for (; t < 4; t++) {
				memcpy(&block[t][0][0], &block[t-1][0][0], 4 * 4);
			}

			rg_etc1::pack_etc1_block(out, (const uint32_t *)block, params);

			out += 8;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x9d4e0
cmpl $0x0, 0x61af67(%rip)    # 0x6b8180
jne 0x9d22a
callq 0x9fd90
movl $0x1, 0x61af56(%rip)    # 0x6b8180
leaq 0x550727(%rip), %rax    # 0x5ed958
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
subl $0x1, %eax
je 0x9d250
jmp 0x9d23d
movl -0x7c(%rbp), %eax
subl $0x2, %eax
jne 0x9d259
jmp 0x9d247
movl $0x2, -0x20(%rbp)
jmp 0x9d260
movl $0x1, -0x20(%rbp)
jmp 0x9d260
movl $0x0, -0x20(%rbp)
movl -0xc(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x78(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9d4d3
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x9d4c3
movl -0x68(%rbp), %eax
imull -0x78(%rbp), %eax
movl -0x64(%rbp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x10(%rbp), %ecx
subl -0x68(%rbp), %ecx
movl $0x4, %eax
cmpl %ecx, %eax
jge 0x9d2ca
movl $0x4, %eax
movl %eax, -0x84(%rbp)
jmp 0x9d2d6
movl -0x10(%rbp), %eax
subl -0x68(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x80(%rbp), %eax
movl -0x84(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9d454
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0xc(%rbp), %ecx
subl -0x64(%rbp), %ecx
movl $0x4, %eax
cmpl %ecx, %eax
jge 0x9d313
movl $0x4, %eax
movl %eax, -0x8c(%rbp)
jmp 0x9d31f
movl -0xc(%rbp), %eax
subl -0x64(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x88(%rbp), %eax
movl -0x8c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x9d400
movq -0x8(%rbp), %rax
movl -0x74(%rbp), %ecx
movl -0x70(%rbp), %edx
imull -0x78(%rbp), %edx
addl %edx, %ecx
movl -0x6c(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movb %dl, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl -0x74(%rbp), %ecx
movl -0x70(%rbp), %edx
imull -0x78(%rbp), %edx
addl %edx, %ecx
movl -0x6c(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movl -0x74(%rbp), %ecx
movl -0x70(%rbp), %edx
imull -0x78(%rbp), %edx
addl %edx, %ecx
movl -0x6c(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movb $-0x1, 0x3(%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x9d2ee
jmp 0x9d402
cmpl $0x4, -0x6c(%rbp)
jge 0x9d444
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movslq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
shlq $0x4, %rsi
addq %rsi, %rdx
movl -0x6c(%rbp), %esi
subl $0x1, %esi
movslq %esi, %rsi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x9d402
jmp 0x9d446
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x9d2a8
jmp 0x9d456
cmpl $0x4, -0x70(%rbp)
jge 0x9d498
movslq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl -0x70(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rdx
leaq -0x60(%rbp), %rcx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x9d456
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0xa00f0
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x64(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x64(%rbp)
jmp 0x9d283
jmp 0x9d4c5
movl -0x68(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x68(%rbp)
jmp 0x9d270
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)