#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 */
int /*<<< orphan*/ cea_audio_block(unsigned char *);
int /*<<< orphan*/ cea_hdmi_block(unsigned char *);
int /*<<< orphan*/ cea_vcdb(unsigned char *);
int /*<<< orphan*/ cea_video_block(unsigned char *);
void cea_block(unsigned char *x) {
  unsigned int oui;
  switch ((x[0] & 0xe0) >> 5) {
  case 0x01:
    (void)("  Audio data block\n");
    cea_audio_block(x);
    break;
  case 0x02:
    (void)("  Video data block\n");
    cea_video_block(x);
    break;
  case 0x03:
    oui = (x[3] << 16) + (x[2] << 8) + x[1];
    (void)("  Vendor-specific data block, OUI %06x", oui);
    if (oui == 0x000c03)
      cea_hdmi_block(x);
    else
      (void)("\n");
    break;
  case 0x04:
    (void)("  Speaker allocation data block\n");
    break;
  case 0x05:
    (void)("  VESA DTC data block\n");
    break;
  case 0x07:
    (void)("  Extended tag: ");
    switch (x[1]) {
    case 0x00:
      (void)("video capability data block\n");
      cea_vcdb(x);
      break;
    case 0x01:
      (void)("vendor-specific video data block\n");
      break;
    case 0x02:
      (void)("VESA video display device information data block\n");
      break;
    case 0x03:
      (void)("VESA video data block\n");
      break;
    case 0x04:
      (void)("HDMI video data block\n");
      break;
    case 0x05:
      (void)("Colorimetry data block\n");
      break;
    case 0x10:
      (void)("CEA miscellaneous audio fields\n");
      break;
    case 0x11:
      (void)("Vendor-specific audio data block\n");
      break;
    case 0x12:
      (void)("HDMI audio data block\n");
      break;
    default:
      if (x[1] >= 6 && x[1] <= 15)
        (void)("Reserved video block (%02x)\n", x[1]);
      else if (x[1] >= 19 && x[1] <= 31)
        (void)("Reserved audio block (%02x)\n", x[1]);
      else
        (void)("Unknown (%02x)\n", x[1]);
      break;
    }
    break;
  default: {
    int tag = (*x & 0xe0) >> 5;
    int length = *x & 0x1f;
    (void)("  Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
    break;
  }
  }
}


x86 assembly (clang, -O0):
<cea_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
shr    $0x5,%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     12a9 <cea_block+0x169>
mov    -0x20(%rbp),%rax
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
call   1030 <cea_audio_block@plt>
jmp    12c8 <cea_block+0x188>
mov    -0x8(%rbp),%rdi
call   1060 <cea_video_block@plt>
jmp    12c8 <cea_block+0x188>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
shl    $0x10,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xc03,-0xc(%rbp)
jne    11d8 <cea_block+0x98>
mov    -0x8(%rbp),%rdi
call   1040 <cea_hdmi_block@plt>
jmp    11dd <cea_block+0x9d>
jmp    11dd <cea_block+0x9d>
jmp    12c8 <cea_block+0x188>
jmp    12c8 <cea_block+0x188>
jmp    12c8 <cea_block+0x188>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %rax,-0x28(%rbp)
sub    $0x12,%rax
ja     124c <cea_block+0x10c>
mov    -0x28(%rbp),%rax
lea    0xe0f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
call   1050 <cea_vcdb@plt>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
jmp    12a4 <cea_block+0x164>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x6,%eax
jl     1273 <cea_block+0x133>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xf,%eax
jg     1273 <cea_block+0x133>
jmp    129f <cea_block+0x15f>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x13,%eax
jl     129a <cea_block+0x15a>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x1f,%eax
jg     129a <cea_block+0x15a>
jmp    129a <cea_block+0x15a>
jmp    129f <cea_block+0x15f>
jmp    12a4 <cea_block+0x164>
jmp    12c8 <cea_block+0x188>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0xe0,%eax
sar    $0x5,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x1f,%eax
mov    %eax,-0x14(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cea_block>:
movzbl (%rdi),%eax
shr    $0x5,%eax
add    $0xffffffff,%eax
cmp    $0x6,%eax
ja     1190 <cea_block+0x50>
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1030 <cea_audio_block@plt>
jmp    1060 <cea_video_block@plt>
movzbl 0x3(%rdi),%eax
shl    $0x10,%eax
movzbl 0x2(%rdi),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl 0x1(%rdi),%eax
or     %ecx,%eax
cmp    $0xc03,%eax
jne    1190 <cea_block+0x50>
jmp    1040 <cea_hdmi_block@plt>
cmpb   $0x0,0x1(%rdi)
je     1191 <cea_block+0x51>
ret
jmp    1050 <cea_vcdb@plt>

LLVM IR (-O0):
@.str = [20 x i8] c" Audio data block\0A\00"
@.str.1 = [20 x i8] c" Video data block\0A\00"
@.str.2 = [39 x i8] c" Vendor-specific data block, OUI %06x\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c" Speaker allocation data block\0A\00"
@.str.5 = [23 x i8] c" VESA DTC data block\0A\00"
@.str.6 = [17 x i8] c" Extended tag: \00"
@.str.7 = [29 x i8] c"video capability data block\0A\00"
@.str.8 = [34 x i8] c"vendor-specific video data block\0A\00"
@.str.9 = [50 x i8] c"VESA video display device information data block\0A\00"
@.str.10 = [23 x i8] c"VESA video data block\0A\00"
@.str.11 = [23 x i8] c"HDMI video data block\0A\00"
@.str.12 = [24 x i8] c"Colorimetry data block\0A\00"
@.str.13 = [32 x i8] c"CEA miscellaneous audio fields\0A\00"
@.str.14 = [34 x i8] c"Vendor-specific audio data block\0A\00"
@.str.15 = [23 x i8] c"HDMI audio data block\0A\00"
@.str.16 = [29 x i8] c"Reserved video block (%02x)\0A\00"
@.str.17 = [29 x i8] c"Reserved audio block (%02x)\0A\00"
@.str.18 = [16 x i8] c"Unknown (%02x)\0A\00"
@.str.19 = [40 x i8] c" Unknown tag %d, length %d (raw %02x)\0A\00"
define void @cea_block(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = and i32 %9, 224
%11 = ashr i32 %10, 5
switch i32 %11, label %100 [
i32 1, label %12
i32 2, label %15
i32 3, label %18
i32 4, label %43
i32 5, label %44
i32 7, label %45
]
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @cea_audio_block(i8* %13)
br label %114
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @cea_video_block(i8* %16)
br label %114
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 16
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = shl i32 %27, 8
%29 = add nsw i32 %23, %28
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = add nsw i32 %29, %33
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 3075
br i1 %37, label %38, label %41
38: ; preds = %18
%39 = load i8*, i8** %2
%40 = call i32 @cea_hdmi_block(i8* %39)
br label %42
41: ; preds = %18
br label %42
42: ; preds = %41, %38
br label %114
43: ; preds = %1
br label %114
44: ; preds = %1
br label %114
45: ; preds = %1
%46 = load i8*, i8** %2
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
switch i32 %49, label %61 [
i32 0, label %50
i32 1, label %53
i32 2, label %54
i32 3, label %55
i32 4, label %56
i32 5, label %57
i32 16, label %58
i32 17, label %59
i32 18, label %60
]
50: ; preds = %45
%51 = load i8*, i8** %2
%52 = call i32 @cea_vcdb(i8* %51)
br label %99
53: ; preds = %45
br label %99
54: ; preds = %45
br label %99
55: ; preds = %45
br label %99
56: ; preds = %45
br label %99
57: ; preds = %45
br label %99
58: ; preds = %45
br label %99
59: ; preds = %45
br label %99
60: ; preds = %45
br label %99
61: ; preds = %45
%62 = load i8*, i8** %2
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = icmp sge i32 %65, 6
br i1 %66, label %67, label %77
67: ; preds = %61
%68 = load i8*, i8** %2
%69 = getelementptr inbounds i8, i8* %68, i64 1
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = icmp sle i32 %71, 15
br i1 %72, label %73, label %77
73: ; preds = %67
%74 = load i8*, i8** %2
%75 = getelementptr inbounds i8, i8* %74, i64 1
%76 = load i8, i8* %75
br label %98
77: ; preds = %67, %61
%78 = load i8*, i8** %2
%79 = getelementptr inbounds i8, i8* %78, i64 1
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = icmp sge i32 %81, 19
br i1 %82, label %83, label %93
83: ; preds = %77
%84 = load i8*, i8** %2
%85 = getelementptr inbounds i8, i8* %84, i64 1
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp sle i32 %87, 31
br i1 %88, label %89, label %93
89: ; preds = %83
%90 = load i8*, i8** %2
%91 = getelementptr inbounds i8, i8* %90, i64 1
%92 = load i8, i8* %91
br label %97
93: ; preds = %83, %77
%94 = load i8*, i8** %2
%95 = getelementptr inbounds i8, i8* %94, i64 1
%96 = load i8, i8* %95
br label %97
97: ; preds = %93, %89
br label %98
98: ; preds = %97, %73
br label %99
99: ; preds = %98, %60, %59, %58, %57, %56, %55, %54, %53, %50
br label %114
100: ; preds = %1
%101 = load i8*, i8** %2
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = and i32 %103, 224
%105 = ashr i32 %104, 5
store i32 %105, i32* %4
%106 = load i8*, i8** %2
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = and i32 %108, 31
store i32 %109, i32* %5
%110 = load i32, i32* %4
%111 = load i32, i32* %5
%112 = load i8*, i8** %2
%113 = load i8, i8* %112
br label %114
114: ; preds = %100, %99, %44, %43, %42, %15, %12
ret void
}

LLVM IR (-O2):
define void @cea_block(i8* %0) {
%2 = load i8, i8* %0
%3 = lshr i8 %2, 5
%4 = zext i8 %3 to i32
switch i32 %4, label %32 [
i32 1, label %5
i32 2, label %7
i32 3, label %9
i32 7, label %26
]
5: ; preds = %1
%6 = tail call i32 @cea_audio_block(i8* %0)
br label %32
7: ; preds = %1
%8 = tail call i32 @cea_video_block(i8* %0)
br label %32
9: ; preds = %1
%10 = getelementptr inbounds i8, i8* %0, i64 3
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl nuw nsw i32 %12, 16
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = or i32 %17, %13
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %18, %21
%23 = icmp eq i32 %22, 3075
br i1 %23, label %24, label %32
24: ; preds = %9
%25 = tail call i32 @cea_hdmi_block(i8* %0)
br label %32
26: ; preds = %1
%27 = getelementptr inbounds i8, i8* %0, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @cea_vcdb(i8* %0)
br label %32
32: ; preds = %26, %1, %30, %24, %9, %7, %5
ret void
}