#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int abs(unsigned char);
int /*<<< orphan*/ encode_alpha_block_DXT5(unsigned char *, unsigned char *,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ extract_block(unsigned char const *, int, int, int, int,
                                 unsigned char *);
int /*<<< orphan*/ get_min_max_YCoCg(unsigned char *, unsigned char *,
                                     unsigned char *);
int /*<<< orphan*/ inset_bbox_YCoCg(unsigned char *, unsigned char *);
int /*<<< orphan*/ lerp_rgb(unsigned char *, unsigned char *, unsigned char *,
                            int);
int pack_rgb565(unsigned char *);
int /*<<< orphan*/ scale_YCoCg(unsigned char *, unsigned char *,
                               unsigned char *);
int /*<<< orphan*/ select_diagonal_YCoCg(unsigned char *, unsigned char *,
                                         unsigned char *);
void compress_YCoCg(unsigned char *dst, const unsigned char *src, int w,
                    int h) {
  unsigned char block[64], colors[4][3];
  unsigned char *maxcolor, *mincolor;
  unsigned int mask;
  int c0, c1, d0, d1, d2, d3;
  int b0, b1, b2, b3, b4;
  int x0, x1, x2;
  int x, y, i;
  for (y = 0; y < h; y += 4) {
    for (x = 0; x < w; x += 4) {
      extract_block(src, x, y, w, h, block);
      encode_alpha_block_DXT5(dst, block, 0);
      maxcolor = &colors[0][0];
      mincolor = &colors[1][0];
      get_min_max_YCoCg(block, mincolor, maxcolor);
      scale_YCoCg(block, mincolor, maxcolor);
      inset_bbox_YCoCg(mincolor, maxcolor);
      select_diagonal_YCoCg(block, mincolor, maxcolor);
      lerp_rgb(&colors[2][0], maxcolor, mincolor, 0x55);
      lerp_rgb(&colors[3][0], maxcolor, mincolor, 0xaa);
      mask = 0;
      for (i = 15; i >= 0; --i) {
        c0 = block[4 * i + 2];
        c1 = block[4 * i + 1];
        d0 = abs(colors[0][2] - c0) + abs(colors[0][1] - c1);
        d1 = abs(colors[1][2] - c0) + abs(colors[1][1] - c1);
        d2 = abs(colors[2][2] - c0) + abs(colors[2][1] - c1);
        d3 = abs(colors[3][2] - c0) + abs(colors[3][1] - c1);
        b0 = d0 > d3;
        b1 = d1 > d2;
        b2 = d0 > d2;
        b3 = d1 > d3;
        b4 = d2 > d3;
        x0 = b1 & b2;
        x1 = b0 & b3;
        x2 = b0 & b4;
        mask <<= 2;
        mask |= (x2 | ((x0 | x1) << 1));
      }
      (&dst[8])[0] = ((pack_rgb565(maxcolor))) & 0xff;
      (&dst[8])[1] = ((pack_rgb565(maxcolor)) >> 8) & 0xff;
      ;
      (&dst[10])[0] = ((pack_rgb565(mincolor))) & 0xff;
      (&dst[10])[1] = ((pack_rgb565(mincolor)) >> 8) & 0xff;
      ;
      (&dst[12])[0] = ((mask)) & 0xff;
      (&dst[12])[1] = ((mask) >> 8) & 0xff;
      (&dst[12])[2] = ((mask) >> 16) & 0xff;
      (&dst[12])[3] = ((mask) >> 24) & 0xff;
      ;
      dst += 16;
    }
  }
}


x86 assembly (clang, -O0):
<compress_YCoCg>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    15bf <compress_YCoCg+0x42f>
movl   $0x0,-0xc0(%rbp)
mov    -0xc0(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    15a6 <compress_YCoCg+0x416>
mov    -0x10(%rbp),%rdi
mov    -0xc0(%rbp),%esi
mov    -0xc4(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    -0x60(%rbp),%r9
call   10b0 <extract_block@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
xor    %edx,%edx
call   1080 <encode_alpha_block_DXT5@plt>
lea    -0x6c(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x6c(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   1030 <get_min_max_YCoCg@plt>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   10a0 <scale_YCoCg@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1060 <inset_bbox_YCoCg@plt>
lea    -0x60(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   1050 <select_diagonal_YCoCg@plt>
lea    -0x6c(%rbp),%rdi
add    $0x6,%rdi
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
mov    $0x55,%ecx
call   1090 <lerp_rgb@plt>
lea    -0x6c(%rbp),%rdi
add    $0x9,%rdi
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
mov    $0xaa,%ecx
call   1090 <lerp_rgb@plt>
movl   $0x0,-0x84(%rbp)
movl   $0xf,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
jl     14cb <compress_YCoCg+0x33b>
mov    -0xc8(%rbp),%eax
shl    $0x2,%eax
add    $0x2,%eax
cltq
movzbl -0x60(%rbp,%rax,1),%eax
mov    %eax,-0x88(%rbp)
mov    -0xc8(%rbp),%eax
shl    $0x2,%eax
add    $0x1,%eax
cltq
movzbl -0x60(%rbp,%rax,1),%eax
mov    %eax,-0x8c(%rbp)
movzbl -0x6a(%rbp),%eax
sub    -0x88(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,-0xd8(%rbp)
movzbl -0x6b(%rbp),%eax
sub    -0x8c(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x90(%rbp)
movzbl -0x67(%rbp),%eax
sub    -0x88(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,-0xd4(%rbp)
movzbl -0x68(%rbp),%eax
sub    -0x8c(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    -0xd4(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x94(%rbp)
movzbl -0x64(%rbp),%eax
sub    -0x88(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,-0xd0(%rbp)
movzbl -0x65(%rbp),%eax
sub    -0x8c(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    -0xd0(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x98(%rbp)
movzbl -0x61(%rbp),%eax
sub    -0x88(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,-0xcc(%rbp)
movzbl -0x62(%rbp),%eax
sub    -0x8c(%rbp),%eax
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ecx
mov    -0xcc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x9c(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x9c(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xa0(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x98(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x98(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xa8(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x9c(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xac(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x9c(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xb0(%rbp)
mov    -0xa4(%rbp),%eax
and    -0xa8(%rbp),%eax
mov    %eax,-0xb4(%rbp)
mov    -0xa0(%rbp),%eax
and    -0xac(%rbp),%eax
mov    %eax,-0xb8(%rbp)
mov    -0xa0(%rbp),%eax
and    -0xb0(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x84(%rbp)
mov    -0xbc(%rbp),%eax
mov    -0xb4(%rbp),%ecx
or     -0xb8(%rbp),%ecx
shl    $0x1,%ecx
or     %ecx,%eax
or     -0x84(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0xc8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc8(%rbp)
jmp    12a6 <compress_YCoCg+0x116>
mov    -0x78(%rbp),%rdi
call   1070 <pack_rgb565@plt>
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x78(%rbp),%rdi
call   1070 <pack_rgb565@plt>
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x80(%rbp),%rdi
call   1070 <pack_rgb565@plt>
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xa(%rax)
mov    -0x80(%rbp),%rdi
call   1070 <pack_rgb565@plt>
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xb(%rax)
mov    -0x84(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xc(%rax)
mov    -0x84(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xd(%rax)
mov    -0x84(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xe(%rax)
mov    -0x84(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0xf(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc0(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc0(%rbp)
jmp    11cc <compress_YCoCg+0x3c>
jmp    15ab <compress_YCoCg+0x41b>
mov    -0xc4(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc4(%rbp)
jmp    11b3 <compress_YCoCg+0x23>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_YCoCg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,0x28(%rsp)
mov    %ecx,0x18(%rsp)
test   %ecx,%ecx
jle    13fe <compress_YCoCg+0x26e>
mov    %edx,%eax
mov    %rdi,%rbp
lea    0xb(%rsp),%r14
movl   $0x0,0x14(%rsp)
lea    0x8(%rsp),%r15
mov    %edx,0x1c(%rsp)
jmp    11e5 <compress_YCoCg+0x55>
nop
mov    0x14(%rsp),%ecx
add    $0x4,%ecx
mov    %ecx,0x14(%rsp)
cmp    0x18(%rsp),%ecx
jge    13fe <compress_YCoCg+0x26e>
test   %eax,%eax
jle    11d0 <compress_YCoCg+0x40>
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    0x28(%rsp),%rdi
mov    %esi,0x20(%rsp)
mov    0x14(%rsp),%edx
mov    %eax,%ecx
mov    0x18(%rsp),%r8d
lea    0x40(%rsp),%rbx
mov    %rbx,%r9
call   10b0 <extract_block@plt>
mov    %rbp,0x30(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <encode_alpha_block_DXT5@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <get_min_max_YCoCg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10a0 <scale_YCoCg@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <inset_bbox_YCoCg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <select_diagonal_YCoCg@plt>
lea    0xe(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x55,%ecx
call   1090 <lerp_rgb@plt>
lea    0x11(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0xaa,%ecx
call   1090 <lerp_rgb@plt>
mov    $0x3d,%r13d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
mov    %rax,0x38(%rsp)
movzbl 0x40(%rsp,%r13,1),%ebx
movzbl 0x41(%rsp,%r13,1),%r12d
movzbl 0xa(%rsp),%eax
sub    %r12b,%al
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ebp
movzbl 0x9(%rsp),%eax
sub    %bl,%al
movzbl %al,%edi
call   1040 <abs@plt>
add    %ebp,%eax
mov    %eax,0x24(%rsp)
movzbl 0xd(%rsp),%eax
sub    %r12b,%al
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ebp
movzbl 0xc(%rsp),%eax
sub    %bl,%al
mov    %bl,0x7(%rsp)
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%r14d
add    %ebp,%r14d
movzbl 0x10(%rsp),%eax
sub    %r12b,%al
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%r15d
movzbl 0xf(%rsp),%eax
sub    %bl,%al
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ebp
add    %r15d,%ebp
movzbl 0x13(%rsp),%eax
sub    %r12b,%al
movzbl %al,%edi
call   1040 <abs@plt>
mov    %eax,%ebx
movzbl 0x12(%rsp),%eax
sub    0x7(%rsp),%al
movzbl %al,%edi
call   1040 <abs@plt>
add    %ebx,%eax
mov    0x24(%rsp),%edx
cmp    %eax,%edx
setg   %cl
cmp    %ebp,%r14d
setg   %sil
cmp    %ebp,%edx
setg   %bl
cmp    %eax,%r14d
setg   %dl
cmp    %eax,%ebp
setg   %al
and    %sil,%bl
and    %cl,%dl
or     %bl,%dl
and    %cl,%al
movzbl %al,%eax
movzbl %dl,%ecx
lea    (%rax,%rcx,2),%eax
mov    0x38(%rsp),%rdx
lea    (%rax,%rdx,4),%ebx
add    $0xfffffffffffffffc,%r13
cmp    $0xfffffffffffffffd,%r13
jne    1290 <compress_YCoCg+0x100>
mov    %rdx,%r12
shl    $0x2,%r12d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1070 <pack_rgb565@plt>
mov    0x30(%rsp),%rbp
mov    %al,0x8(%rbp)
mov    %r15,%rdi
call   1070 <pack_rgb565@plt>
mov    %ah,0x9(%rbp)
lea    0xb(%rsp),%r14
mov    %r14,%rdi
call   1070 <pack_rgb565@plt>
mov    %al,0xa(%rbp)
mov    %r14,%rdi
call   1070 <pack_rgb565@plt>
mov    %ah,0xb(%rbp)
mov    %bl,0xc(%rbp)
mov    %r12,%rcx
mov    %ch,0xd(%rbp)
mov    %ecx,%eax
shr    $0x10,%eax
mov    %al,0xe(%rbp)
shr    $0x18,%ecx
mov    %cl,0xf(%rbp)
add    $0x10,%rbp
mov    0x20(%rsp),%esi
add    $0x4,%esi
mov    0x1c(%rsp),%eax
cmp    %eax,%esi
jl     11f0 <compress_YCoCg+0x60>
jmp    11d0 <compress_YCoCg+0x40>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compress_YCoCg(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca [4 x [3 x i8]]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %29
br label %31
31: ; preds = %272, %4
%32 = load i32, i32* %29
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %275
35: ; preds = %31
store i32 0, i32* %28
br label %36
36: ; preds = %268, %35
%37 = load i32, i32* %28
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %271
40: ; preds = %36
%41 = load i8*, i8** %6
%42 = load i32, i32* %28
%43 = load i32, i32* %29
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%47 = call i32 @extract_block(i8* %41, i32 %42, i32 %43, i32 %44, i32 %45, i8* %46)
%48 = load i8*, i8** %5
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%50 = call i32 @encode_alpha_block_DXT5(i8* %48, i8* %49, i32 0)
%51 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 0
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %51, i64 0, i64 0
store i8* %52, i8** %11
%53 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 1
%54 = getelementptr inbounds [3 x i8], [3 x i8]* %53, i64 0, i64 0
store i8* %54, i8** %12
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%56 = load i8*, i8** %12
%57 = load i8*, i8** %11
%58 = call i32 @get_min_max_YCoCg(i8* %55, i8* %56, i8* %57)
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%60 = load i8*, i8** %12
%61 = load i8*, i8** %11
%62 = call i32 @scale_YCoCg(i8* %59, i8* %60, i8* %61)
%63 = load i8*, i8** %12
%64 = load i8*, i8** %11
%65 = call i32 @inset_bbox_YCoCg(i8* %63, i8* %64)
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%67 = load i8*, i8** %12
%68 = load i8*, i8** %11
%69 = call i32 @select_diagonal_YCoCg(i8* %66, i8* %67, i8* %68)
%70 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 2
%71 = getelementptr inbounds [3 x i8], [3 x i8]* %70, i64 0, i64 0
%72 = load i8*, i8** %11
%73 = load i8*, i8** %12
%74 = call i32 @lerp_rgb(i8* %71, i8* %72, i8* %73, i32 85)
%75 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 3
%76 = getelementptr inbounds [3 x i8], [3 x i8]* %75, i64 0, i64 0
%77 = load i8*, i8** %11
%78 = load i8*, i8** %12
%79 = call i32 @lerp_rgb(i8* %76, i8* %77, i8* %78, i32 170)
store i32 0, i32* %13
store i32 15, i32* %30
br label %80
80: ; preds = %205, %40
%81 = load i32, i32* %30
%82 = icmp sge i32 %81, 0
br i1 %82, label %83, label %208
83: ; preds = %80
%84 = load i32, i32* %30
%85 = mul nsw i32 4, %84
%86 = add nsw i32 %85, 2
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 %87
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
store i32 %90, i32* %14
%91 = load i32, i32* %30
%92 = mul nsw i32 4, %91
%93 = add nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
store i32 %97, i32* %15
%98 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 0
%99 = getelementptr inbounds [3 x i8], [3 x i8]* %98, i64 0, i64 2
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = load i32, i32* %14
%103 = sub nsw i32 %101, %102
%104 = trunc i32 %103 to i8
%105 = call i32 @abs(i8 zeroext %104)
%106 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 0
%107 = getelementptr inbounds [3 x i8], [3 x i8]* %106, i64 0, i64 1
%108 = load i8, i8* %107
%109 = zext i8 %108 to i32
%110 = load i32, i32* %15
%111 = sub nsw i32 %109, %110
%112 = trunc i32 %111 to i8
%113 = call i32 @abs(i8 zeroext %112)
%114 = add nsw i32 %105, %113
store i32 %114, i32* %16
%115 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 1
%116 = getelementptr inbounds [3 x i8], [3 x i8]* %115, i64 0, i64 2
%117 = load i8, i8* %116
%118 = zext i8 %117 to i32
%119 = load i32, i32* %14
%120 = sub nsw i32 %118, %119
%121 = trunc i32 %120 to i8
%122 = call i32 @abs(i8 zeroext %121)
%123 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 1
%124 = getelementptr inbounds [3 x i8], [3 x i8]* %123, i64 0, i64 1
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
%127 = load i32, i32* %15
%128 = sub nsw i32 %126, %127
%129 = trunc i32 %128 to i8
%130 = call i32 @abs(i8 zeroext %129)
%131 = add nsw i32 %122, %130
store i32 %131, i32* %17
%132 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 2
%133 = getelementptr inbounds [3 x i8], [3 x i8]* %132, i64 0, i64 2
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = load i32, i32* %14
%137 = sub nsw i32 %135, %136
%138 = trunc i32 %137 to i8
%139 = call i32 @abs(i8 zeroext %138)
%140 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 2
%141 = getelementptr inbounds [3 x i8], [3 x i8]* %140, i64 0, i64 1
%142 = load i8, i8* %141
%143 = zext i8 %142 to i32
%144 = load i32, i32* %15
%145 = sub nsw i32 %143, %144
%146 = trunc i32 %145 to i8
%147 = call i32 @abs(i8 zeroext %146)
%148 = add nsw i32 %139, %147
store i32 %148, i32* %18
%149 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 3
%150 = getelementptr inbounds [3 x i8], [3 x i8]* %149, i64 0, i64 2
%151 = load i8, i8* %150
%152 = zext i8 %151 to i32
%153 = load i32, i32* %14
%154 = sub nsw i32 %152, %153
%155 = trunc i32 %154 to i8
%156 = call i32 @abs(i8 zeroext %155)
%157 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %10, i64 0, i64 3
%158 = getelementptr inbounds [3 x i8], [3 x i8]* %157, i64 0, i64 1
%159 = load i8, i8* %158
%160 = zext i8 %159 to i32
%161 = load i32, i32* %15
%162 = sub nsw i32 %160, %161
%163 = trunc i32 %162 to i8
%164 = call i32 @abs(i8 zeroext %163)
%165 = add nsw i32 %156, %164
store i32 %165, i32* %19
%166 = load i32, i32* %16
%167 = load i32, i32* %19
%168 = icmp sgt i32 %166, %167
%169 = zext i1 %168 to i32
store i32 %169, i32* %20
%170 = load i32, i32* %17
%171 = load i32, i32* %18
%172 = icmp sgt i32 %170, %171
%173 = zext i1 %172 to i32
store i32 %173, i32* %21
%174 = load i32, i32* %16
%175 = load i32, i32* %18
%176 = icmp sgt i32 %174, %175
%177 = zext i1 %176 to i32
store i32 %177, i32* %22
%178 = load i32, i32* %17
%179 = load i32, i32* %19
%180 = icmp sgt i32 %178, %179
%181 = zext i1 %180 to i32
store i32 %181, i32* %23
%182 = load i32, i32* %18
%183 = load i32, i32* %19
%184 = icmp sgt i32 %182, %183
%185 = zext i1 %184 to i32
store i32 %185, i32* %24
%186 = load i32, i32* %21
%187 = load i32, i32* %22
%188 = and i32 %186, %187
store i32 %188, i32* %25
%189 = load i32, i32* %20
%190 = load i32, i32* %23
%191 = and i32 %189, %190
store i32 %191, i32* %26
%192 = load i32, i32* %20
%193 = load i32, i32* %24
%194 = and i32 %192, %193
store i32 %194, i32* %27
%195 = load i32, i32* %13
%196 = shl i32 %195, 2
store i32 %196, i32* %13
%197 = load i32, i32* %27
%198 = load i32, i32* %25
%199 = load i32, i32* %26
%200 = or i32 %198, %199
%201 = shl i32 %200, 1
%202 = or i32 %197, %201
%203 = load i32, i32* %13
%204 = or i32 %203, %202
store i32 %204, i32* %13
br label %205
205: ; preds = %83
%206 = load i32, i32* %30
%207 = add nsw i32 %206, -1
store i32 %207, i32* %30
br label %80
208: ; preds = %80
%209 = load i8*, i8** %11
%210 = call i32 @pack_rgb565(i8* %209)
%211 = and i32 %210, 255
%212 = trunc i32 %211 to i8
%213 = load i8*, i8** %5
%214 = getelementptr inbounds i8, i8* %213, i64 8
%215 = getelementptr inbounds i8, i8* %214, i64 0
store i8 %212, i8* %215
%216 = load i8*, i8** %11
%217 = call i32 @pack_rgb565(i8* %216)
%218 = ashr i32 %217, 8
%219 = and i32 %218, 255
%220 = trunc i32 %219 to i8
%221 = load i8*, i8** %5
%222 = getelementptr inbounds i8, i8* %221, i64 8
%223 = getelementptr inbounds i8, i8* %222, i64 1
store i8 %220, i8* %223
%224 = load i8*, i8** %12
%225 = call i32 @pack_rgb565(i8* %224)
%226 = and i32 %225, 255
%227 = trunc i32 %226 to i8
%228 = load i8*, i8** %5
%229 = getelementptr inbounds i8, i8* %228, i64 10
%230 = getelementptr inbounds i8, i8* %229, i64 0
store i8 %227, i8* %230
%231 = load i8*, i8** %12
%232 = call i32 @pack_rgb565(i8* %231)
%233 = ashr i32 %232, 8
%234 = and i32 %233, 255
%235 = trunc i32 %234 to i8
%236 = load i8*, i8** %5
%237 = getelementptr inbounds i8, i8* %236, i64 10
%238 = getelementptr inbounds i8, i8* %237, i64 1
store i8 %235, i8* %238
%239 = load i32, i32* %13
%240 = and i32 %239, 255
%241 = trunc i32 %240 to i8
%242 = load i8*, i8** %5
%243 = getelementptr inbounds i8, i8* %242, i64 12
%244 = getelementptr inbounds i8, i8* %243, i64 0
store i8 %241, i8* %244
%245 = load i32, i32* %13
%246 = lshr i32 %245, 8
%247 = and i32 %246, 255
%248 = trunc i32 %247 to i8
%249 = load i8*, i8** %5
%250 = getelementptr inbounds i8, i8* %249, i64 12
%251 = getelementptr inbounds i8, i8* %250, i64 1
store i8 %248, i8* %251
%252 = load i32, i32* %13
%253 = lshr i32 %252, 16
%254 = and i32 %253, 255
%255 = trunc i32 %254 to i8
%256 = load i8*, i8** %5
%257 = getelementptr inbounds i8, i8* %256, i64 12
%258 = getelementptr inbounds i8, i8* %257, i64 2
store i8 %255, i8* %258
%259 = load i32, i32* %13
%260 = lshr i32 %259, 24
%261 = and i32 %260, 255
%262 = trunc i32 %261 to i8
%263 = load i8*, i8** %5
%264 = getelementptr inbounds i8, i8* %263, i64 12
%265 = getelementptr inbounds i8, i8* %264, i64 3
store i8 %262, i8* %265
%266 = load i8*, i8** %5
%267 = getelementptr inbounds i8, i8* %266, i64 16
store i8* %267, i8** %5
br label %268
268: ; preds = %208
%269 = load i32, i32* %28
%270 = add nsw i32 %269, 4
store i32 %270, i32* %28
br label %36
271: ; preds = %36
br label %272
272: ; preds = %271
%273 = load i32, i32* %29
%274 = add nsw i32 %273, 4
store i32 %274, i32* %29
br label %31
275: ; preds = %31
ret void
}

LLVM IR (-O2):
define void @compress_YCoCg(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = alloca [4 x [3 x i8]]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 0, i64 0
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %124
10: ; preds = %4
%11 = icmp sgt i32 %2, 0
%12 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 1, i64 0
%13 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 2, i64 0
%14 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 3, i64 0
%15 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 0, i64 2
%16 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 0, i64 1
%17 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 1, i64 2
%18 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 1, i64 1
%19 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 2, i64 2
%20 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 2, i64 1
%21 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 3, i64 2
%22 = getelementptr inbounds [4 x [3 x i8]], [4 x [3 x i8]]* %6, i64 0, i64 3, i64 1
br label %23
23: ; preds = %10, %120
%24 = phi i32 [ 0, %10 ], [ %122, %120 ]
%25 = phi i8* [ %0, %10 ], [ %121, %120 ]
br i1 %11, label %26, label %120
26: ; preds = %23, %91
%27 = phi i32 [ %118, %91 ], [ 0, %23 ]
%28 = phi i8* [ %117, %91 ], [ %25, %23 ]
%29 = call i32 @extract_block(i8* %1, i32 %27, i32 %24, i32 %2, i32 %3, i8* %7)
%30 = call i32 @encode_alpha_block_DXT5(i8* %28, i8* %7, i32 0)
%31 = call i32 @get_min_max_YCoCg(i8* %7, i8* %12, i8* %8)
%32 = call i32 @scale_YCoCg(i8* %7, i8* %12, i8* %8)
%33 = call i32 @inset_bbox_YCoCg(i8* %12, i8* %8)
%34 = call i32 @select_diagonal_YCoCg(i8* %7, i8* %12, i8* %8)
%35 = call i32 @lerp_rgb(i8* %13, i8* %8, i8* %12, i32 85)
%36 = call i32 @lerp_rgb(i8* %14, i8* %8, i8* %12, i32 170)
br label %37
37: ; preds = %26, %37
%38 = phi i64 [ 15, %26 ], [ %89, %37 ]
%39 = phi i32 [ 0, %26 ], [ %88, %37 ]
%40 = shl nsw i64 %38, 2
%41 = or i64 %40, 2
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = or i64 %40, 1
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = load i8, i8* %15
%48 = sub i8 %47, %43
%49 = call i32 @abs(i8 zeroext %48)
%50 = load i8, i8* %16
%51 = sub i8 %50, %46
%52 = call i32 @abs(i8 zeroext %51)
%53 = add nsw i32 %52, %49
%54 = load i8, i8* %17
%55 = sub i8 %54, %43
%56 = call i32 @abs(i8 zeroext %55)
%57 = load i8, i8* %18
%58 = sub i8 %57, %46
%59 = call i32 @abs(i8 zeroext %58)
%60 = add nsw i32 %59, %56
%61 = load i8, i8* %19
%62 = sub i8 %61, %43
%63 = call i32 @abs(i8 zeroext %62)
%64 = load i8, i8* %20
%65 = sub i8 %64, %46
%66 = call i32 @abs(i8 zeroext %65)
%67 = add nsw i32 %66, %63
%68 = load i8, i8* %21
%69 = sub i8 %68, %43
%70 = call i32 @abs(i8 zeroext %69)
%71 = load i8, i8* %22
%72 = sub i8 %71, %46
%73 = call i32 @abs(i8 zeroext %72)
%74 = add nsw i32 %73, %70
%75 = icmp sgt i32 %53, %74
%76 = icmp sgt i32 %60, %67
%77 = icmp sgt i32 %53, %67
%78 = icmp sgt i32 %60, %74
%79 = icmp sgt i32 %67, %74
%80 = and i1 %76, %77
%81 = and i1 %75, %78
%82 = and i1 %75, %79
%83 = zext i1 %82 to i32
%84 = shl i32 %39, 2
%85 = or i1 %80, %81
%86 = select i1 %85, i32 2, i32 0
%87 = or i32 %86, %83
%88 = or i32 %87, %84
%89 = add nsw i64 %38, -1
%90 = icmp eq i64 %38, 0
br i1 %90, label %91, label %37
91: ; preds = %37
%92 = call i32 @pack_rgb565(i8* %8)
%93 = trunc i32 %92 to i8
%94 = getelementptr inbounds i8, i8* %28, i64 8
store i8 %93, i8* %94
%95 = call i32 @pack_rgb565(i8* %8)
%96 = lshr i32 %95, 8
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds i8, i8* %28, i64 9
store i8 %97, i8* %98
%99 = call i32 @pack_rgb565(i8* %12)
%100 = trunc i32 %99 to i8
%101 = getelementptr inbounds i8, i8* %28, i64 10
store i8 %100, i8* %101
%102 = call i32 @pack_rgb565(i8* %12)
%103 = lshr i32 %102, 8
%104 = trunc i32 %103 to i8
%105 = getelementptr inbounds i8, i8* %28, i64 11
store i8 %104, i8* %105
%106 = trunc i32 %88 to i8
%107 = getelementptr inbounds i8, i8* %28, i64 12
store i8 %106, i8* %107
%108 = lshr i32 %84, 8
%109 = trunc i32 %108 to i8
%110 = getelementptr inbounds i8, i8* %28, i64 13
store i8 %109, i8* %110
%111 = lshr i32 %84, 16
%112 = trunc i32 %111 to i8
%113 = getelementptr inbounds i8, i8* %28, i64 14
store i8 %112, i8* %113
%114 = lshr i32 %84, 24
%115 = trunc i32 %114 to i8
%116 = getelementptr inbounds i8, i8* %28, i64 15
store i8 %115, i8* %116
%117 = getelementptr inbounds i8, i8* %28, i64 16
%118 = add nuw nsw i32 %27, 4
%119 = icmp slt i32 %118, %2
br i1 %119, label %26, label %120
120: ; preds = %91, %23
%121 = phi i8* [ %25, %23 ], [ %117, %91 ]
%122 = add nuw nsw i32 %24, 4
%123 = icmp slt i32 %122, %3
br i1 %123, label %23, label %124
124: ; preds = %120, %4
ret void
}