#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 /*<<< orphan*/ encode_alpha_block_DXT5(unsigned char *, unsigned char *,
                                           int);
int /*<<< orphan*/ extract_block(unsigned char const *, int, int, int, int,
                                 unsigned char *);
void compress_BC5(unsigned char *dst, const unsigned char *src, int w, int h) {
  unsigned char block[64];
  int x, y;
  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, -2);
      encode_alpha_block_DXT5(dst + 8, block, -1);
      dst += 16;
    }
  }
}


x86 assembly (clang, -O0):
<compress_BC5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11cb <compress_BC5+0xab>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b8 <compress_BC5+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x64(%rbp),%esi
mov    -0x68(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    -0x60(%rbp),%r9
call   1040 <extract_block@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xfffffffe,%edx
call   1030 <encode_alpha_block_DXT5@plt>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
lea    -0x60(%rbp),%rsi
mov    $0xffffffff,%edx
call   1030 <encode_alpha_block_DXT5@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x64(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x64(%rbp)
jmp    1150 <compress_BC5+0x30>
jmp    11bd <compress_BC5+0x9d>
mov    -0x68(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x68(%rbp)
jmp    113d <compress_BC5+0x1d>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_BC5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %ecx,%ecx
jle    11bc <compress_BC5+0x9c>
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rdi,%rbx
xor    %r13d,%r13d
lea    0x10(%rsp),%rbp
mov    %rsi,0x8(%rsp)
jmp    1159 <compress_BC5+0x39>
xchg   %ax,%ax
add    $0x4,%r13d
cmp    %r12d,%r13d
jge    11bc <compress_BC5+0x9c>
test   %r15d,%r15d
jle    1150 <compress_BC5+0x30>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %rbp,%r9
call   1040 <extract_block@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0xfffffffe,%edx
call   1030 <encode_alpha_block_DXT5@plt>
lea    0x8(%rbx),%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
call   1030 <encode_alpha_block_DXT5@plt>
mov    0x8(%rsp),%rsi
add    $0x10,%rbx
add    $0x4,%r14d
cmp    %r15d,%r14d
jl     1170 <compress_BC5+0x50>
jmp    1150 <compress_BC5+0x30>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compress_BC5(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 i32
%11 = 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* %11
br label %12
12: ; preds = %42, %4
%13 = load i32, i32* %11
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %12
store i32 0, i32* %10
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i32, i32* %10
%24 = load i32, i32* %11
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%28 = call i32 @extract_block(i8* %22, i32 %23, i32 %24, i32 %25, i32 %26, i8* %27)
%29 = load i8*, i8** %5
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%31 = call i32 @encode_alpha_block_DXT5(i8* %29, i8* %30, i32 -2)
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 8
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%35 = call i32 @encode_alpha_block_DXT5(i8* %33, i8* %34, i32 -1)
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 16
store i8* %37, i8** %5
br label %38
38: ; preds = %21
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 4
store i32 %40, i32* %10
br label %17
41: ; preds = %17
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 4
store i32 %44, i32* %11
br label %12
45: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @compress_BC5(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %27
8: ; preds = %4
%9 = icmp sgt i32 %2, 0
br label %10
10: ; preds = %8, %23
%11 = phi i32 [ 0, %8 ], [ %25, %23 ]
%12 = phi i8* [ %0, %8 ], [ %24, %23 ]
br i1 %9, label %13, label %23
13: ; preds = %10, %13
%14 = phi i32 [ %21, %13 ], [ 0, %10 ]
%15 = phi i8* [ %20, %13 ], [ %12, %10 ]
%16 = call i32 @extract_block(i8* %1, i32 %14, i32 %11, i32 %2, i32 %3, i8* %6)
%17 = call i32 @encode_alpha_block_DXT5(i8* %15, i8* %6, i32 -2)
%18 = getelementptr inbounds i8, i8* %15, i64 8
%19 = call i32 @encode_alpha_block_DXT5(i8* %18, i8* %6, i32 -1)
%20 = getelementptr inbounds i8, i8* %15, i64 16
%21 = add nuw nsw i32 %14, 4
%22 = icmp slt i32 %21, %2
br i1 %22, label %13, label %23
23: ; preds = %13, %10
%24 = phi i8* [ %12, %10 ], [ %20, %13 ]
%25 = add nuw nsw i32 %11, 4
%26 = icmp slt i32 %25, %3
br i1 %26, label %10, label %27
27: ; preds = %23, %4
ret void
}