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


x86 assembly (clang, -O0):
<compress_DXT1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%eax
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    11c5 <compress_DXT1+0xa5>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b2 <compress_DXT1+0x92>
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    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    0x10(%rbp),%r8d
call   1030 <encode_color_block@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x64(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x64(%rbp)
jmp    115b <compress_DXT1+0x3b>
jmp    11b7 <compress_DXT1+0x97>
mov    -0x68(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x68(%rbp)
jmp    1148 <compress_DXT1+0x28>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_DXT1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %ecx,%ecx
jle    11a9 <compress_DXT1+0x89>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    %r9d,0x4(%rsp)
mov    %r8d,(%rsp)
mov    %rsi,0x8(%rsp)
jmp    1159 <compress_DXT1+0x39>
nopl   (%rax)
add    $0x4,%r15d
cmp    %r14d,%r15d
jge    11a9 <compress_DXT1+0x89>
test   %ebp,%ebp
jle    1150 <compress_DXT1+0x30>
xor    %r12d,%r12d
mov    %rsi,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
lea    0x10(%rsp),%r13
mov    %r13,%r9
call   1040 <extract_block@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x90(%rsp),%r8d
call   1030 <encode_color_block@plt>
mov    0x8(%rsp),%rsi
add    $0x8,%rbx
add    $0x4,%r12d
cmp    %ebp,%r12d
jl     1160 <compress_DXT1+0x40>
jmp    1150 <compress_DXT1+0x30>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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