#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_etc2_block(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ decode_etc2a8_block(int /*<<< orphan*/ const *,
                                       int /*<<< orphan*/ *);
int decode_etc2a8(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];
  for (long by = 0; by < num_blocks_y; by++) {
    for (long bx = 0; bx < num_blocks_x; bx++, data += 16) {
      decode_etc2_block(data + 8, buffer);
      decode_etc2a8_block(data, buffer);
      copy_block_buffer(bx, by, w, h, 4, 4, buffer, image);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<decode_etc2a8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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)
movq   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1223 <decode_etc2a8+0xf3>
movq   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    120d <decode_etc2a8+0xdd>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
lea    -0x70(%rbp),%rsi
call   1040 <decode_etc2_block@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1050 <decode_etc2a8_block@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%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    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <decode_etc2a8+0x65>
jmp    1212 <decode_etc2a8+0xe2>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    117f <decode_etc2a8+0x4f>
mov    $0x1,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_etc2a8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
test   %rdx,%rdx
jle    11fe <decode_etc2a8+0xce>
mov    %rsi,%r13
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,%r12d
cmovge %rdi,%r12
xor    %r15d,%r15d
lea    0x20(%rsp),%rbp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
jmp    119b <decode_etc2a8+0x6b>
nop
add    $0x1,%r15
cmp    0x8(%rsp),%r15
je     11fe <decode_etc2a8+0xce>
test   %r13,%r13
jle    1190 <decode_etc2a8+0x60>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x20(%rbx),%rdi
mov    %rbp,%rsi
call   1040 <decode_etc2_block@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <decode_etc2a8_block@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    0x10(%rsp),%rcx
mov    $0x4,%r8d
mov    $0x4,%r9d
push   0x18(%rsp)
push   %rbp
call   1030 <copy_block_buffer@plt>
add    $0x10,%rsp
add    $0x1,%r14
add    $0x40,%rbx
cmp    %r14,%r12
jne    11b0 <decode_etc2a8+0x80>
jmp    1190 <decode_etc2a8+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_etc2a8(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 i64
%13 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%14 = load i64, i64* %6
%15 = add nsw i64 %14, 3
%16 = sdiv i64 %15, 4
store i64 %16, i64* %9
%17 = load i64, i64* %7
%18 = add nsw i64 %17, 3
%19 = sdiv i64 %18, 4
store i64 %19, i64* %10
store i64 0, i64* %12
br label %20
20: ; preds = %50, %4
%21 = load i64, i64* %12
%22 = load i64, i64* %10
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %53
24: ; preds = %20
store i64 0, i64* %13
br label %25
25: ; preds = %44, %24
%26 = load i64, i64* %13
%27 = load i64, i64* %9
%28 = icmp slt i64 %26, %27
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = load i32*, i32** %5
%31 = getelementptr inbounds i32, i32* %30, i64 8
%32 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%33 = call i32 @decode_etc2_block(i32* %31, i32* %32)
%34 = load i32*, i32** %5
%35 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%36 = call i32 @decode_etc2a8_block(i32* %34, i32* %35)
%37 = load i64, i64* %13
%38 = load i64, i64* %12
%39 = load i64, i64* %6
%40 = load i64, i64* %7
%41 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%42 = load i32*, i32** %8
%43 = call i32 @copy_block_buffer(i64 %37, i64 %38, i64 %39, i64 %40, i32 4, i32 4, i32* %41, i32* %42)
br label %44
44: ; preds = %29
%45 = load i64, i64* %13
%46 = add nsw i64 %45, 1
store i64 %46, i64* %13
%47 = load i32*, i32** %5
%48 = getelementptr inbounds i32, i32* %47, i64 16
store i32* %48, i32** %5
br label %25
49: ; preds = %25
br label %50
50: ; preds = %49
%51 = load i64, i64* %12
%52 = add nsw i64 %51, 1
store i64 %52, i64* %12
br label %20
53: ; preds = %20
ret i32 1
}

LLVM IR (-O2):
define i32 @decode_etc2a8(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 ], [ %32, %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 [ %31, %24 ], [ 0, %16 ]
%26 = phi i32* [ %32, %24 ], [ %18, %16 ]
%27 = getelementptr inbounds i32, i32* %26, i64 8
%28 = call i32 @decode_etc2_block(i32* %27, i32* %14)
%29 = call i32 @decode_etc2a8_block(i32* %26, i32* %14)
%30 = call i32 @copy_block_buffer(i64 %25, i64 %17, i64 %1, i64 %2, i32 4, i32 4, i32* %14, i32* %3)
%31 = add nuw nsw i64 %25, 1
%32 = getelementptr inbounds i32, i32* %26, i64 16
%33 = icmp eq i64 %31, %15
br i1 %33, label %20, label %24
}