#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 uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ DecompressBlockDXT1Internal(int const *, int *, int, int *);
void DecompressBlockDXT3(uint32_t x, uint32_t y, uint32_t width,
                         const uint8_t *blockStorage, uint32_t *image) {
  int i;
  uint8_t alphaValues[16] = {0};
  for (i = 0; i < 4; ++i) {
    const uint16_t *alphaData = (const uint16_t *)(blockStorage);
    alphaValues[i * 4 + 0] = (((*alphaData) >> 0) & 0xF) * 17;
    alphaValues[i * 4 + 1] = (((*alphaData) >> 4) & 0xF) * 17;
    alphaValues[i * 4 + 2] = (((*alphaData) >> 8) & 0xF) * 17;
    alphaValues[i * 4 + 3] = (((*alphaData) >> 12) & 0xF) * 17;
    blockStorage += 2;
  }
  DecompressBlockDXT1Internal(blockStorage, image + x + (y * width), width,
                              alphaValues);
}


x86 assembly (clang, -O0):
<DecompressBlockDXT3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11f7 <DecompressBlockDXT3+0xd7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    (%rax),%eax
sar    $0x0,%eax
and    $0xf,%eax
imul   $0x11,%eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
add    $0x0,%eax
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x78(%rbp),%rax
mov    (%rax),%eax
sar    $0x4,%eax
and    $0xf,%eax
imul   $0x11,%eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
add    $0x1,%eax
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x78(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
and    $0xf,%eax
imul   $0x11,%eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
add    $0x2,%eax
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x78(%rbp),%rax
mov    (%rax),%eax
sar    $0xc,%eax
and    $0xf,%eax
imul   $0x11,%eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
add    $0x3,%eax
cltq
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <DecompressBlockDXT3+0x33>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
lea    -0x70(%rbp),%rcx
call   1040 <DecompressBlockDXT1Internal@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecompressBlockDXT3>:
sub    $0x48,%rsp
mov    (%rcx),%r10d
mov    %r10d,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,(%rsp)
mov    %r10d,%r9d
shr    $0x4,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x4(%rsp)
mov    %r10d,%r9d
shr    $0x8,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x8(%rsp)
shr    $0xc,%r10d
and    $0xf,%r10d
mov    %r10d,%eax
shl    $0x4,%eax
or     %r10d,%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rcx),%r10d
mov    %r10d,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x10(%rsp)
mov    %r10d,%r9d
shr    $0x4,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x14(%rsp)
mov    %r10d,%r9d
shr    $0x8,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x18(%rsp)
shr    $0xc,%r10d
and    $0xf,%r10d
mov    %r10d,%eax
shl    $0x4,%eax
or     %r10d,%eax
mov    %eax,0x1c(%rsp)
mov    0x10(%rcx),%r10d
mov    %r10d,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x20(%rsp)
mov    %r10d,%r9d
shr    $0x4,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x24(%rsp)
mov    %r10d,%r9d
shr    $0x8,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x28(%rsp)
shr    $0xc,%r10d
and    $0xf,%r10d
mov    %r10d,%eax
shl    $0x4,%eax
or     %r10d,%eax
mov    %eax,0x2c(%rsp)
mov    0x18(%rcx),%r10d
mov    %r10d,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x30(%rsp)
mov    %r10d,%r9d
shr    $0x4,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x34(%rsp)
mov    %r10d,%r9d
shr    $0x8,%r9d
and    $0xf,%r9d
mov    %r9d,%eax
shl    $0x4,%eax
or     %r9d,%eax
mov    %eax,0x38(%rsp)
shr    $0xc,%r10d
and    $0xf,%r10d
mov    %r10d,%eax
shl    $0x4,%eax
or     %r10d,%eax
mov    %eax,0x3c(%rsp)
lea    0x20(%rcx),%rax
movslq %edi,%rcx
lea    (%r8,%rcx,4),%rcx
imul   %edx,%esi
movslq %esi,%rsi
lea    (%rcx,%rsi,4),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
call   1030 <DecompressBlockDXT1Internal@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
define void @DecompressBlockDXT3(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [16 x i32]
%13 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%14 = bitcast [16 x i32]* %12 to i8*
store i32 0, i32* %11
br label %15
15: ; preds = %62, %5
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %65
18: ; preds = %15
%19 = load i32*, i32** %9
store i32* %19, i32** %13
%20 = load i32*, i32** %13
%21 = load i32, i32* %20
%22 = ashr i32 %21, 0
%23 = and i32 %22, 15
%24 = mul nsw i32 %23, 17
%25 = load i32, i32* %11
%26 = mul nsw i32 %25, 4
%27 = add nsw i32 %26, 0
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 %28
store i32 %24, i32* %29
%30 = load i32*, i32** %13
%31 = load i32, i32* %30
%32 = ashr i32 %31, 4
%33 = and i32 %32, 15
%34 = mul nsw i32 %33, 17
%35 = load i32, i32* %11
%36 = mul nsw i32 %35, 4
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 %38
store i32 %34, i32* %39
%40 = load i32*, i32** %13
%41 = load i32, i32* %40
%42 = ashr i32 %41, 8
%43 = and i32 %42, 15
%44 = mul nsw i32 %43, 17
%45 = load i32, i32* %11
%46 = mul nsw i32 %45, 4
%47 = add nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 %48
store i32 %44, i32* %49
%50 = load i32*, i32** %13
%51 = load i32, i32* %50
%52 = ashr i32 %51, 12
%53 = and i32 %52, 15
%54 = mul nsw i32 %53, 17
%55 = load i32, i32* %11
%56 = mul nsw i32 %55, 4
%57 = add nsw i32 %56, 3
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 %58
store i32 %54, i32* %59
%60 = load i32*, i32** %9
%61 = getelementptr inbounds i32, i32* %60, i64 2
store i32* %61, i32** %9
br label %62
62: ; preds = %18
%63 = load i32, i32* %11
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
br label %15
65: ; preds = %15
%66 = load i32*, i32** %9
%67 = load i32*, i32** %10
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %7
%72 = load i32, i32* %8
%73 = mul nsw i32 %71, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %70, i64 %74
%76 = load i32, i32* %8
%77 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
%78 = call i32 @DecompressBlockDXT1Internal(i32* %66, i32* %75, i32 %76, i32* %77)
ret void
}

LLVM IR (-O2):
define void @DecompressBlockDXT3(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca [16 x i32]
%7 = bitcast [16 x i32]* %6 to i8*
%8 = load i32, i32* %3
%9 = and i32 %8, 15
%10 = mul nuw nsw i32 %9, 17
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
store i32 %10, i32* %11
%12 = lshr i32 %8, 4
%13 = and i32 %12, 15
%14 = mul nuw nsw i32 %13, 17
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 1
store i32 %14, i32* %15
%16 = lshr i32 %8, 8
%17 = and i32 %16, 15
%18 = mul nuw nsw i32 %17, 17
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 2
store i32 %18, i32* %19
%20 = lshr i32 %8, 12
%21 = and i32 %20, 15
%22 = mul nuw nsw i32 %21, 17
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 3
store i32 %22, i32* %23
%24 = getelementptr inbounds i32, i32* %3, i64 2
%25 = load i32, i32* %24
%26 = and i32 %25, 15
%27 = mul nuw nsw i32 %26, 17
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 4
store i32 %27, i32* %28
%29 = lshr i32 %25, 4
%30 = and i32 %29, 15
%31 = mul nuw nsw i32 %30, 17
%32 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 5
store i32 %31, i32* %32
%33 = lshr i32 %25, 8
%34 = and i32 %33, 15
%35 = mul nuw nsw i32 %34, 17
%36 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 6
store i32 %35, i32* %36
%37 = lshr i32 %25, 12
%38 = and i32 %37, 15
%39 = mul nuw nsw i32 %38, 17
%40 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 7
store i32 %39, i32* %40
%41 = getelementptr inbounds i32, i32* %3, i64 4
%42 = load i32, i32* %41
%43 = and i32 %42, 15
%44 = mul nuw nsw i32 %43, 17
%45 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 8
store i32 %44, i32* %45
%46 = lshr i32 %42, 4
%47 = and i32 %46, 15
%48 = mul nuw nsw i32 %47, 17
%49 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 9
store i32 %48, i32* %49
%50 = lshr i32 %42, 8
%51 = and i32 %50, 15
%52 = mul nuw nsw i32 %51, 17
%53 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 10
store i32 %52, i32* %53
%54 = lshr i32 %42, 12
%55 = and i32 %54, 15
%56 = mul nuw nsw i32 %55, 17
%57 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 11
store i32 %56, i32* %57
%58 = getelementptr inbounds i32, i32* %3, i64 6
%59 = load i32, i32* %58
%60 = and i32 %59, 15
%61 = mul nuw nsw i32 %60, 17
%62 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 12
store i32 %61, i32* %62
%63 = lshr i32 %59, 4
%64 = and i32 %63, 15
%65 = mul nuw nsw i32 %64, 17
%66 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 13
store i32 %65, i32* %66
%67 = lshr i32 %59, 8
%68 = and i32 %67, 15
%69 = mul nuw nsw i32 %68, 17
%70 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 14
store i32 %69, i32* %70
%71 = lshr i32 %59, 12
%72 = and i32 %71, 15
%73 = mul nuw nsw i32 %72, 17
%74 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 15
store i32 %73, i32* %74
%75 = getelementptr inbounds i32, i32* %3, i64 8
%76 = sext i32 %0 to i64
%77 = getelementptr inbounds i32, i32* %4, i64 %76
%78 = mul nsw i32 %2, %1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
%81 = call i32 @DecompressBlockDXT1Internal(i32* %75, i32* %80, i32 %2, i32* %11)
ret void
}