#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 */
scalar_t__ complement3bitshifted(unsigned char const);
int draw_block4x4_etc1(unsigned char const *, unsigned int *, int);
int /*<<< orphan*/ draw_block4x4_rgb8_etc2_T_or_H_mode(unsigned char const *,
                                                       unsigned int *, int);
int /*<<< orphan*/ draw_block4x4_rgb8_etc2_planar_mode(unsigned char const *,
                                                       unsigned int *);
int draw_block4x4_rgb8_etc2(const unsigned char *bitstring,
                            unsigned int *image_buffer, int modes_allowed) {
  if ((bitstring[3] & 2) == 0) {
    return draw_block4x4_etc1(bitstring, image_buffer, modes_allowed);
  }
  if ((modes_allowed & ~1) == 0)
    return 0;
  int R = (bitstring[0] & 0xF8);
  R += complement3bitshifted(bitstring[0] & 7);
  int G = (bitstring[1] & 0xF8);
  G += complement3bitshifted(bitstring[1] & 7);
  int B = (bitstring[2] & 0xF8);
  B += complement3bitshifted(bitstring[2] & 7);
  if (R & 0xFF07) {
    if ((modes_allowed & 4) == 0)
      return 0;
    draw_block4x4_rgb8_etc2_T_or_H_mode(bitstring, image_buffer, 0);
    return 1;
  } else if (G & 0xFF07) {
    if ((modes_allowed & 8) == 0)
      return 0;
    draw_block4x4_rgb8_etc2_T_or_H_mode(bitstring, image_buffer, 1);
    return 1;
  } else if (B & 0xFF07) {
    if ((modes_allowed & 16) == 0)
      return 0;
    draw_block4x4_rgb8_etc2_planar_mode(bitstring, image_buffer);
    return 1;
  } else {
    return draw_block4x4_etc1(bitstring, image_buffer, modes_allowed);
  }
}


x86 assembly (clang, -O0):
<draw_block4x4_rgb8_etc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    117f <draw_block4x4_rgb8_etc2+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <draw_block4x4_etc1@plt>
mov    %eax,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x1c(%rbp),%eax
and    $0xfffffffe,%eax
cmp    $0x0,%eax
jne    119a <draw_block4x4_rgb8_etc2+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xf8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x7,%eax
movzbl %al,%edi
call   1040 <complement3bitshifted@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0x7,%eax
movzbl %al,%edi
call   1040 <complement3bitshifted@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0xf8,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x7,%eax
movzbl %al,%edi
call   1040 <complement3bitshifted@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff07,%eax
cmp    $0x0,%eax
je     126f <draw_block4x4_rgb8_etc2+0x12f>
mov    -0x1c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    1254 <draw_block4x4_rgb8_etc2+0x114>
movl   $0x0,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <draw_block4x4_rgb8_etc2_T_or_H_mode@plt>
movl   $0x1,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x24(%rbp),%eax
and    $0xff07,%eax
cmp    $0x0,%eax
je     12b9 <draw_block4x4_rgb8_etc2+0x179>
mov    -0x1c(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    129b <draw_block4x4_rgb8_etc2+0x15b>
movl   $0x0,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <draw_block4x4_rgb8_etc2_T_or_H_mode@plt>
movl   $0x1,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x28(%rbp),%eax
and    $0xff07,%eax
cmp    $0x0,%eax
je     12fe <draw_block4x4_rgb8_etc2+0x1be>
mov    -0x1c(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    12e5 <draw_block4x4_rgb8_etc2+0x1a5>
movl   $0x0,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <draw_block4x4_rgb8_etc2_planar_mode@plt>
movl   $0x1,-0x4(%rbp)
jmp    1311 <draw_block4x4_rgb8_etc2+0x1d1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <draw_block4x4_etc1@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_block4x4_rgb8_etc2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%rbp
testb  $0x2,0x3(%rdi)
jne    1176 <draw_block4x4_rgb8_etc2+0x36>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <draw_block4x4_etc1@plt>
xor    %ebx,%ebx
cmp    $0x2,%r12d
jb     1234 <draw_block4x4_rgb8_etc2+0xf4>
movzbl 0x0(%rbp),%edi
mov    %edi,%ebx
and    $0xfffffff8,%ebx
and    $0x7,%edi
call   1040 <complement3bitshifted@plt>
mov    %rax,%r13
add    %ebx,%r13d
movzbl 0x1(%rbp),%r14d
mov    %r14d,%edi
and    $0x7,%edi
call   1040 <complement3bitshifted@plt>
mov    %rax,(%rsp)
movzbl 0x2(%rbp),%ebx
mov    %ebx,%edi
and    $0x7,%edi
call   1040 <complement3bitshifted@plt>
test   $0xff07,%r13d
je     11e3 <draw_block4x4_rgb8_etc2+0xa3>
test   $0x4,%r12b
mov    $0x0,%ebx
je     1234 <draw_block4x4_rgb8_etc2+0xf4>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <draw_block4x4_rgb8_etc2_T_or_H_mode@plt>
mov    $0x1,%ebx
jmp    1234 <draw_block4x4_rgb8_etc2+0xf4>
and    $0xfffffff8,%r14d
mov    (%rsp),%rdx
add    %r14d,%edx
test   $0xff07,%edx
je     1218 <draw_block4x4_rgb8_etc2+0xd8>
test   $0x8,%r12b
mov    $0x0,%ebx
je     1234 <draw_block4x4_rgb8_etc2+0xf4>
mov    $0x1,%ebx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <draw_block4x4_rgb8_etc2_T_or_H_mode@plt>
jmp    1234 <draw_block4x4_rgb8_etc2+0xf4>
and    $0xfffffff8,%ebx
add    %rbx,%rax
test   $0xff07,%eax
je     115a <draw_block4x4_rgb8_etc2+0x1a>
test   $0x10,%r12b
mov    $0x0,%ebx
jne    1245 <draw_block4x4_rgb8_etc2+0x105>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <draw_block4x4_rgb8_etc2_planar_mode@plt>
jmp    11dc <draw_block4x4_rgb8_etc2+0x9c>

LLVM IR (-O0):
define i32 @draw_block4x4_rgb8_etc2(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 3
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = and i32 %14, 2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = call i32 @draw_block4x4_etc1(i8* %18, i32* %19, i32 %20)
store i32 %21, i32* %4
br label %119
22: ; preds = %3
%23 = load i32, i32* %7
%24 = and i32 %23, -2
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %4
br label %119
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = and i32 %31, 248
store i32 %32, i32* %8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = and i32 %36, 7
%38 = trunc i32 %37 to i8
%39 = call i64 @complement3bitshifted(i8 zeroext %38)
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %8
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = and i32 %47, 248
store i32 %48, i32* %9
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = and i32 %52, 7
%54 = trunc i32 %53 to i8
%55 = call i64 @complement3bitshifted(i8 zeroext %54)
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = add nsw i64 %57, %55
%59 = trunc i64 %58 to i32
store i32 %59, i32* %9
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 2
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = and i32 %63, 248
store i32 %64, i32* %10
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i64 2
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = and i32 %68, 7
%70 = trunc i32 %69 to i8
%71 = call i64 @complement3bitshifted(i8 zeroext %70)
%72 = load i32, i32* %10
%73 = sext i32 %72 to i64
%74 = add nsw i64 %73, %71
%75 = trunc i64 %74 to i32
store i32 %75, i32* %10
%76 = load i32, i32* %8
%77 = and i32 %76, 65287
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %88
79: ; preds = %27
%80 = load i32, i32* %7
%81 = and i32 %80, 4
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %79
store i32 0, i32* %4
br label %119
84: ; preds = %79
%85 = load i8*, i8** %5
%86 = load i32*, i32** %6
%87 = call i32 @draw_block4x4_rgb8_etc2_T_or_H_mode(i8* %85, i32* %86, i32 0)
store i32 1, i32* %4
br label %119
88: ; preds = %27
%89 = load i32, i32* %9
%90 = and i32 %89, 65287
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %101
92: ; preds = %88
%93 = load i32, i32* %7
%94 = and i32 %93, 8
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %92
store i32 0, i32* %4
br label %119
97: ; preds = %92
%98 = load i8*, i8** %5
%99 = load i32*, i32** %6
%100 = call i32 @draw_block4x4_rgb8_etc2_T_or_H_mode(i8* %98, i32* %99, i32 1)
store i32 1, i32* %4
br label %119
101: ; preds = %88
%102 = load i32, i32* %10
%103 = and i32 %102, 65287
%104 = icmp ne i32 %103, 0
br i1 %104, label %105, label %114
105: ; preds = %101
%106 = load i32, i32* %7
%107 = and i32 %106, 16
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %110
109: ; preds = %105
store i32 0, i32* %4
br label %119
110: ; preds = %105
%111 = load i8*, i8** %5
%112 = load i32*, i32** %6
%113 = call i32 @draw_block4x4_rgb8_etc2_planar_mode(i8* %111, i32* %112)
store i32 1, i32* %4
br label %119
114: ; preds = %101
%115 = load i8*, i8** %5
%116 = load i32*, i32** %6
%117 = load i32, i32* %7
%118 = call i32 @draw_block4x4_etc1(i8* %115, i32* %116, i32 %117)
store i32 %118, i32* %4
br label %119
119: ; preds = %114, %110, %109, %97, %96, %84, %83, %26, %17
%120 = load i32, i32* %4
ret i32 %120
}

LLVM IR (-O2):
define i32 @draw_block4x4_rgb8_etc2(i8* %0, i32* %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 3
%5 = load i8, i8* %4
%6 = and i8 %5, 2
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @draw_block4x4_etc1(i8* %0, i32* %1, i32 %2)
br label %58
10: ; preds = %3
%11 = icmp ult i32 %2, 2
br i1 %11, label %58, label %12
12: ; preds = %10
%13 = load i8, i8* %0
%14 = and i8 %13, -8
%15 = zext i8 %14 to i64
%16 = and i8 %13, 7
%17 = tail call i64 @complement3bitshifted(i8 zeroext %16)
%18 = add nsw i64 %17, %15
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = load i8, i8* %19
%21 = and i8 %20, 7
%22 = tail call i64 @complement3bitshifted(i8 zeroext %21)
%23 = getelementptr inbounds i8, i8* %0, i64 2
%24 = load i8, i8* %23
%25 = and i8 %24, -8
%26 = zext i8 %25 to i64
%27 = and i8 %24, 7
%28 = tail call i64 @complement3bitshifted(i8 zeroext %27)
%29 = add nsw i64 %28, %26
%30 = and i64 %18, 65287
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %12
%33 = and i32 %2, 4
%34 = icmp eq i32 %33, 0
br i1 %34, label %58, label %35
35: ; preds = %32
%36 = tail call i32 @draw_block4x4_rgb8_etc2_T_or_H_mode(i8* %0, i32* %1, i32 0)
br label %58
37: ; preds = %12
%38 = and i8 %20, -8
%39 = zext i8 %38 to i64
%40 = add nsw i64 %22, %39
%41 = and i64 %40, 65287
%42 = icmp eq i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %37
%44 = and i32 %2, 8
%45 = icmp eq i32 %44, 0
br i1 %45, label %58, label %46
46: ; preds = %43
%47 = tail call i32 @draw_block4x4_rgb8_etc2_T_or_H_mode(i8* %0, i32* %1, i32 1)
br label %58
48: ; preds = %37
%49 = and i64 %29, 65287
%50 = icmp eq i64 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %48
%52 = and i32 %2, 16
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %51
%55 = tail call i32 @draw_block4x4_rgb8_etc2_planar_mode(i8* %0, i32* %1)
br label %58
56: ; preds = %48
%57 = tail call i32 @draw_block4x4_etc1(i8* %0, i32* %1, i32 %2)
br label %58
58: ; preds = %35, %46, %54, %56, %32, %43, %51, %10, %8
%59 = phi i32 [ %9, %8 ], [ 0, %10 ], [ 1, %35 ], [ 1, %46 ], [ 1, %54 ], [ %57, %56 ], [ 0, %32 ], [ 0, %43 ], [ 0, %51 ]
ret i32 %59
}