#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_BC4(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, -1);
      dst += 8;
    }
  }
}


x86 assembly (clang, -O0):
<compress_BC4>:
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    11b5 <compress_BC4+0x95>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <compress_BC4+0x82>
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    $0xffffffff,%edx
call   1030 <encode_alpha_block_DXT5@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x64(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x64(%rbp)
jmp    1150 <compress_BC4+0x30>
jmp    11a7 <compress_BC4+0x87>
mov    -0x68(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x68(%rbp)
jmp    113d <compress_BC4+0x1d>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_BC4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %ecx,%ecx
jle    119f <compress_BC4+0x7f>
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    %rsi,0x8(%rsp)
jmp    1158 <compress_BC4+0x38>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%ebp
cmp    %r13d,%ebp
jge    119f <compress_BC4+0x7f>
test   %r12d,%r12d
jle    1150 <compress_BC4+0x30>
xor    %r14d,%r14d
mov    %rsi,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
lea    0x10(%rsp),%r15
mov    %r15,%r9
call   1040 <extract_block@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xffffffff,%edx
call   1030 <encode_alpha_block_DXT5@plt>
mov    0x8(%rsp),%rsi
add    $0x8,%rbx
add    $0x4,%r14d
cmp    %r12d,%r14d
jl     1160 <compress_BC4+0x40>
jmp    1150 <compress_BC4+0x30>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compress_BC4(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 = %38, %4
%13 = load i32, i32* %11
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
store i32 0, i32* %10
br label %17
17: ; preds = %34, %16
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
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 -1)
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 8
store i8* %33, i8** %5
br label %34
34: ; preds = %21
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 4
store i32 %36, i32* %10
br label %17
37: ; preds = %17
br label %38
38: ; preds = %37
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 4
store i32 %40, i32* %11
br label %12
41: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @compress_BC4(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 %25
8: ; preds = %4
%9 = icmp sgt i32 %2, 0
br label %10
10: ; preds = %8, %21
%11 = phi i32 [ 0, %8 ], [ %23, %21 ]
%12 = phi i8* [ %0, %8 ], [ %22, %21 ]
br i1 %9, label %13, label %21
13: ; preds = %10, %13
%14 = phi i32 [ %19, %13 ], [ 0, %10 ]
%15 = phi i8* [ %18, %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 -1)
%18 = getelementptr inbounds i8, i8* %15, i64 8
%19 = add nuw nsw i32 %14, 4
%20 = icmp slt i32 %19, %2
br i1 %20, label %13, label %21
21: ; preds = %13, %10
%22 = phi i8* [ %12, %10 ], [ %18, %13 ]
%23 = add nuw nsw i32 %11, 4
%24 = icmp slt i32 %23, %3
br i1 %24, label %10, label %25
25: ; preds = %21, %4
ret void
}