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

/* Variables and functions */
int /*<<< orphan*/ color(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, int);
int /*<<< orphan*/ copy_block_buffer(long, long, long const, long const, int,
                                     int, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ decode_eac_signed_block(int /*<<< orphan*/ const *, int,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int decode_eacrg_signed(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];
  uint32_t base_buffer[16];
  for (int i = 0; i < 16; i++)
    base_buffer[i] = color(0, 0, 0, 255);
  for (long by = 0; by < num_blocks_y; by++) {
    for (long bx = 0; bx < num_blocks_x; bx++, data += 16) {
      memcpy(buffer, base_buffer, sizeof(buffer));
      decode_eac_signed_block(data, 0, buffer);
      decode_eac_signed_block(data + 8, 1, buffer);
      copy_block_buffer(bx, by, w, h, 4, 4, buffer, image);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<decode_eacrg_signed>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%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)
movl   $0x0,-0xb4(%rbp)
cmpl   $0x10,-0xb4(%rbp)
jge    11d2 <decode_eacrg_signed+0x92>
xor    %edx,%edx
mov    $0xff,%ecx
mov    %edx,%edi
mov    %edx,%esi
call   1060 <color@plt>
mov    %eax,%ecx
movslq -0xb4(%rbp),%rax
mov    %ecx,-0xb0(%rbp,%rax,4)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1191 <decode_eacrg_signed+0x51>
movq   $0x0,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    12b8 <decode_eacrg_signed+0x178>
movq   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    129c <decode_eacrg_signed+0x15c>
lea    -0x70(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rdx
xor    %esi,%esi
call   1030 <decode_eac_signed_block@plt>
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
lea    -0x70(%rbp),%rdx
mov    $0x1,%esi
call   1030 <decode_eac_signed_block@plt>
mov    -0xc8(%rbp),%rdi
mov    -0xc0(%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   1040 <copy_block_buffer@plt>
mov    -0xc8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x8(%rbp)
jmp    11f9 <decode_eacrg_signed+0xb9>
jmp    12a1 <decode_eacrg_signed+0x161>
mov    -0xc0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc0(%rbp)
jmp    11dd <decode_eacrg_signed+0x9d>
mov    $0x1,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_eacrg_signed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x10(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x14(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x18(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x1c(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x20(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x24(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x28(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x2c(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x30(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x34(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x38(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x3c(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x40(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x44(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x48(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xff,%ecx
call   1060 <color@plt>
mov    %eax,0x4c(%rsp)
test   %r14,%r14
jle    139b <decode_eacrg_signed+0x25b>
lea    0x3(%r14),%rax
shr    $0x2,%rax
mov    %rax,0x58(%rsp)
lea    0x3(%r13),%rax
lea    0x6(%r13),%rcx
test   %rax,%rax
cmovns %rax,%rcx
sar    $0x2,%rcx
cmp    $0x2,%rcx
mov    $0x1,%eax
cmovge %rcx,%rax
xor    %r12d,%r12d
lea    0x70(%rsp),%rbp
lea    0x10(%rsp),%rcx
mov    %r13,0x8(%rsp)
mov    %r14,0x68(%rsp)
mov    %r15,0x60(%rsp)
jmp    130f <decode_eacrg_signed+0x1cf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    0x58(%rsp),%r12
je     139b <decode_eacrg_signed+0x25b>
test   %r13,%r13
jle    1300 <decode_eacrg_signed+0x1c0>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rcx,%r14
mov    %rcx,%rsi
mov    $0x40,%edx
mov    %rax,%r13
call   1050 <memcpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1030 <decode_eac_signed_block@plt>
lea    0x20(%rbx),%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
call   1030 <decode_eac_signed_block@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    0x8(%rsp),%rdx
mov    0x68(%rsp),%rcx
mov    $0x4,%r8d
mov    $0x4,%r9d
push   0x60(%rsp)
push   %rbp
call   1040 <copy_block_buffer@plt>
mov    %r14,%rcx
mov    %r13,%rax
add    $0x10,%rsp
add    $0x1,%r15
add    $0x40,%rbx
cmp    %r15,%r13
jne    1320 <decode_eacrg_signed+0x1e0>
mov    0x8(%rsp),%r13
jmp    1300 <decode_eacrg_signed+0x1c0>
mov    $0x1,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode_eacrg_signed(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 [16 x i32]
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%16 = load i64, i64* %6
%17 = add nsw i64 %16, 3
%18 = sdiv i64 %17, 4
store i64 %18, i64* %9
%19 = load i64, i64* %7
%20 = add nsw i64 %19, 3
%21 = sdiv i64 %20, 4
store i64 %21, i64* %10
store i32 0, i32* %13
br label %22
22: ; preds = %30, %4
%23 = load i32, i32* %13
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = call i32 @color(i32 0, i32 0, i32 0, i32 255)
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 %28
store i32 %26, i32* %29
br label %30
30: ; preds = %25
%31 = load i32, i32* %13
%32 = add nsw i32 %31, 1
store i32 %32, i32* %13
br label %22
33: ; preds = %22
store i64 0, i64* %14
br label %34
34: ; preds = %67, %33
%35 = load i64, i64* %14
%36 = load i64, i64* %10
%37 = icmp slt i64 %35, %36
br i1 %37, label %38, label %70
38: ; preds = %34
store i64 0, i64* %15
br label %39
39: ; preds = %61, %38
%40 = load i64, i64* %15
%41 = load i64, i64* %9
%42 = icmp slt i64 %40, %41
br i1 %42, label %43, label %66
43: ; preds = %39
%44 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%45 = getelementptr inbounds [16 x i32], [16 x i32]* %12, i64 0, i64 0
%46 = call i32 @memcpy(i32* %44, i32* %45, i32 64)
%47 = load i32*, i32** %5
%48 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%49 = call i32 @decode_eac_signed_block(i32* %47, i32 0, i32* %48)
%50 = load i32*, i32** %5
%51 = getelementptr inbounds i32, i32* %50, i64 8
%52 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%53 = call i32 @decode_eac_signed_block(i32* %51, i32 1, i32* %52)
%54 = load i64, i64* %15
%55 = load i64, i64* %14
%56 = load i64, i64* %6
%57 = load i64, i64* %7
%58 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%59 = load i32*, i32** %8
%60 = call i32 @copy_block_buffer(i64 %54, i64 %55, i64 %56, i64 %57, i32 4, i32 4, i32* %58, i32* %59)
br label %61
61: ; preds = %43
%62 = load i64, i64* %15
%63 = add nsw i64 %62, 1
store i64 %63, i64* %15
%64 = load i32*, i32** %5
%65 = getelementptr inbounds i32, i32* %64, i64 16
store i32* %65, i32** %5
br label %39
66: ; preds = %39
br label %67
67: ; preds = %66
%68 = load i64, i64* %14
%69 = add nsw i64 %68, 1
store i64 %69, i64* %14
br label %34
70: ; preds = %34
ret i32 1
}

LLVM IR (-O2):
define i32 @decode_eacrg_signed(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca [16 x i32]
%6 = alloca [16 x i32]
%7 = bitcast [16 x i32]* %5 to i8*
%8 = bitcast [16 x i32]* %6 to i8*
%9 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
store i32 %9, i32* %10
%11 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 1
store i32 %11, i32* %12
%13 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 2
store i32 %13, i32* %14
%15 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 3
store i32 %15, i32* %16
%17 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 4
store i32 %17, i32* %18
%19 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 5
store i32 %19, i32* %20
%21 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%22 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 6
store i32 %21, i32* %22
%23 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%24 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 7
store i32 %23, i32* %24
%25 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%26 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 8
store i32 %25, i32* %26
%27 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 9
store i32 %27, i32* %28
%29 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%30 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 10
store i32 %29, i32* %30
%31 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%32 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 11
store i32 %31, i32* %32
%33 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%34 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 12
store i32 %33, i32* %34
%35 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%36 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 13
store i32 %35, i32* %36
%37 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%38 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 14
store i32 %37, i32* %38
%39 = tail call i32 @color(i32 0, i32 0, i32 0, i32 255)
%40 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 15
store i32 %39, i32* %40
%41 = icmp sgt i64 %2, 0
br i1 %41, label %42, label %53
42: ; preds = %4
%43 = add nuw nsw i64 %2, 3
%44 = lshr i64 %43, 2
%45 = add nsw i64 %1, 3
%46 = sdiv i64 %45, 4
%47 = icmp sgt i64 %1, 0
%48 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%49 = call i64 @llvm.smax.i64(i64 %46, i64 1)
br label %50
50: ; preds = %42, %54
%51 = phi i64 [ 0, %42 ], [ %56, %54 ]
%52 = phi i32* [ %0, %42 ], [ %55, %54 ]
br i1 %47, label %58, label %54
53: ; preds = %54, %4
ret i32 1
54: ; preds = %58, %50
%55 = phi i32* [ %52, %50 ], [ %67, %58 ]
%56 = add nuw nsw i64 %51, 1
%57 = icmp eq i64 %56, %44
br i1 %57, label %53, label %50
58: ; preds = %50, %58
%59 = phi i64 [ %66, %58 ], [ 0, %50 ]
%60 = phi i32* [ %67, %58 ], [ %52, %50 ]
%61 = call i32 @memcpy(i32* %48, i32* %10, i32 64)
%62 = call i32 @decode_eac_signed_block(i32* %60, i32 0, i32* %48)
%63 = getelementptr inbounds i32, i32* %60, i64 8
%64 = call i32 @decode_eac_signed_block(i32* %63, i32 1, i32* %48)
%65 = call i32 @copy_block_buffer(i64 %59, i64 %51, i64 %1, i64 %2, i32 4, i32 4, i32* %48, i32* %3)
%66 = add nuw nsw i64 %59, 1
%67 = getelementptr inbounds i32, i32* %60, i64 16
%68 = icmp eq i64 %66, %49
br i1 %68, label %54, label %58
}