#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_DXT3(unsigned char *, unsigned char *);
int /*<<< orphan*/ encode_color_block(unsigned char *, unsigned char *, int,
                                      int, int /*<<< orphan*/);
int /*<<< orphan*/ extract_block(unsigned char const *, int, int, int, int,
                                 unsigned char *);
void compress_DXT3(unsigned char *dst, const unsigned char *src, int w, int h,
                   int type, int dither) {
  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_DXT3(dst, block);
      encode_color_block(dst + 8, block, type, dither, 0);
      dst += 16;
    }
  }
}


x86 assembly (clang, -O0):
<compress_DXT3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e2 <compress_DXT3+0xb2>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cf <compress_DXT3+0x9f>
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   1050 <extract_block@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <encode_alpha_block_DXT3@plt>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
lea    -0x60(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
xor    %r8d,%r8d
call   1040 <encode_color_block@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x64(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x64(%rbp)
jmp    1168 <compress_DXT3+0x38>
jmp    11d4 <compress_DXT3+0xa4>
mov    -0x68(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x68(%rbp)
jmp    1155 <compress_DXT3+0x25>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_DXT3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %ecx,%ecx
jle    11dc <compress_DXT3+0xac>
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %rdi,%rbx
xor    %r15d,%r15d
lea    0x10(%rsp),%rbp
mov    %rsi,0x8(%rsp)
mov    %r9d,0x4(%rsp)
mov    %r8d,(%rsp)
jmp    1179 <compress_DXT3+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x4,%r15d
cmp    %r14d,%r15d
jge    11dc <compress_DXT3+0xac>
test   %r13d,%r13d
jle    1170 <compress_DXT3+0x40>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r13d,%ecx
mov    %r14d,%r8d
mov    %rbp,%r9
call   1050 <extract_block@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <encode_alpha_block_DXT3@plt>
lea    0x8(%rbx),%rdi
mov    %rbp,%rsi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
xor    %r8d,%r8d
call   1040 <encode_color_block@plt>
mov    0x8(%rsp),%rsi
add    $0x10,%rbx
add    $0x4,%r12d
cmp    %r13d,%r12d
jl     1190 <compress_DXT3+0x60>
jmp    1170 <compress_DXT3+0x40>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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