#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ copy_block_buffer(long, long, long const, long const, int,
                                     int, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ decode_dxt1_block(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *);
int decode_dxt1(const uint8_t *data, const long w, const long h,
                uint32_t *image) {
  long num_blocks_x = (w + 3) / 4;
  long num_blocks_y = (h + 3) / 4;
  uint32_t buffer[16];
  const uint8_t *d = data;
  for (long by = 0; by < num_blocks_y; by++) {
    for (long bx = 0; bx < num_blocks_x; bx++, d += 8) {
      decode_dxt1_block(d, buffer);
      copy_block_buffer(bx, by, w, h, 4, 4, buffer, image);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<decode_dxt1>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    $0x4,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1219 <decode_dxt1+0xf9>
movq   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    1203 <decode_dxt1+0xe3>
mov    -0x78(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <decode_dxt1_block@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x70(%rbp),%r10
mov    -0x20(%rbp),%rax
mov    $0x4,%r9d
mov    %r9d,%r8d
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <copy_block_buffer@plt>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x78(%rbp)
jmp    1190 <decode_dxt1+0x70>
jmp    1208 <decode_dxt1+0xe8>
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
jmp    1177 <decode_dxt1+0x57>
mov    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_dxt1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
test   %rdx,%rdx
jle    11e3 <decode_dxt1+0xc3>
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x3(%rdx),%rax
shr    $0x2,%rax
mov    %rax,0x8(%rsp)
lea    0x3(%rsi),%rax
lea    0x6(%rsi),%rdi
test   %rax,%rax
cmovns %rax,%rdi
sar    $0x2,%rdi
cmp    $0x2,%rdi
mov    $0x1,%r13d
cmovge %rdi,%r13
xor    %r12d,%r12d
lea    0x20(%rsp),%r15
mov    %rdx,0x18(%rsp)
mov    %rcx,0x10(%rsp)
jmp    118b <decode_dxt1+0x6b>
nop
add    $0x1,%r12
cmp    0x8(%rsp),%r12
je     11e3 <decode_dxt1+0xc3>
test   %rbp,%rbp
jle    1180 <decode_dxt1+0x60>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <decode_dxt1_block@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    0x18(%rsp),%rcx
mov    $0x4,%r8d
mov    $0x4,%r9d
push   0x10(%rsp)
push   %r15
call   1030 <copy_block_buffer@plt>
add    $0x10,%rsp
add    $0x1,%r14
add    $0x20,%rbx
cmp    %r14,%r13
jne    11a0 <decode_dxt1+0x80>
jmp    1180 <decode_dxt1+0x60>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @decode_dxt1(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca [16 x i32]
%6 = bitcast [16 x i32]* %5 to i8*
%7 = icmp sgt i64 %2, 0
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = add nuw nsw i64 %2, 3
%10 = lshr i64 %9, 2
%11 = add nsw i64 %1, 3
%12 = sdiv i64 %11, 4
%13 = icmp sgt i64 %1, 0
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%15 = call i64 @llvm.smax.i64(i64 %12, i64 1)
br label %16
16: ; preds = %8, %20
%17 = phi i64 [ 0, %8 ], [ %22, %20 ]
%18 = phi i32* [ %0, %8 ], [ %21, %20 ]
br i1 %13, label %24, label %20
19: ; preds = %20, %4
ret i32 1
20: ; preds = %24, %16
%21 = phi i32* [ %18, %16 ], [ %30, %24 ]
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %19, label %16
24: ; preds = %16, %24
%25 = phi i64 [ %29, %24 ], [ 0, %16 ]
%26 = phi i32* [ %30, %24 ], [ %18, %16 ]
%27 = call i32 @decode_dxt1_block(i32* %26, i32* %14)
%28 = call i32 @copy_block_buffer(i64 %25, i64 %17, i64 %1, i64 %2, i32 4, i32 4, i32* %14, i32* %3)
%29 = add nuw nsw i64 %25, 1
%30 = getelementptr inbounds i32, i32* %26, i64 8
%31 = icmp eq i64 %29, %15
br i1 %31, label %20, label %24
}