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

/* Variables and functions */
unsigned int MEDIA_ENT_SUBTYPE_MASK;
unsigned int MEDIA_ENT_TYPE_MASK;
#define MEDIA_ENT_T_DEVNODE 129
#define MEDIA_ENT_T_V4L2_SUBDEV 128
const char *media_entity_subtype_to_string(unsigned type) {
  static const char *node_types[] = {
      "Unknown", "V4L", "FB", "ALSA", "DVB",
  };
  static const char *subdev_types[] = {
      "Unknown",
      "Sensor",
      "Flash",
      "Lens",
  };
  unsigned int subtype = type & MEDIA_ENT_SUBTYPE_MASK;
  switch (type & MEDIA_ENT_TYPE_MASK) {
  case MEDIA_ENT_T_DEVNODE:
    if (subtype >= (sizeof(node_types) / sizeof((node_types)[0])))
      subtype = 0;
    return node_types[subtype];
  case MEDIA_ENT_T_V4L2_SUBDEV:
    if (subtype >= (sizeof(subdev_types) / sizeof((subdev_types)[0])))
      subtype = 0;
    return subdev_types[subtype];
  default:
    return node_types[0];
  }
}


x86 assembly (clang, -O0):
<media_entity_subtype_to_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ecf(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ece(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     1179 <media_entity_subtype_to_string+0x79>
jmp    1139 <media_entity_subtype_to_string+0x39>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
jne    11a6 <media_entity_subtype_to_string+0xa6>
jmp    114c <media_entity_subtype_to_string+0x4c>
mov    -0x10(%rbp),%eax
cmp    $0x5,%rax
jb     1160 <media_entity_subtype_to_string+0x60>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2ec4(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <media_entity_subtype_to_string+0xb1>
mov    -0x10(%rbp),%eax
cmp    $0x4,%rax
jb     118d <media_entity_subtype_to_string+0x8d>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2ec7(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <media_entity_subtype_to_string+0xb1>
mov    0x2e83(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<media_entity_subtype_to_string>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    0x2ede(%rip),%rcx
and    (%rcx),%edi
cmp    $0x80,%edi
je     1135 <media_entity_subtype_to_string+0x35>
cmp    $0x81,%edi
jne    114c <media_entity_subtype_to_string+0x4c>
xor    %ecx,%ecx
cmp    $0x5,%eax
cmovb  %eax,%ecx
lea    0x2cbd(%rip),%rax
jmp    1144 <media_entity_subtype_to_string+0x44>
xor    %ecx,%ecx
cmp    $0x4,%eax
cmovb  %eax,%ecx
lea    0x2cdc(%rip),%rax
lea    (%rax,%rcx,8),%rax
mov    (%rax),%rax
ret
lea    0xead(%rip),%rax
ret

LLVM IR (-O0):
@media_entity_subtype_to_string.node_types = internal global [5 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0)]
@.str = [8 x i8] c"Unknown\00"
@.str.1 = [4 x i8] c"V4L\00"
@.str.2 = [3 x i8] c"FB\00"
@.str.3 = [5 x i8] c"ALSA\00"
@.str.4 = [4 x i8] c"DVB\00"
@media_entity_subtype_to_string.subdev_types = internal global [4 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0)]
@.str.5 = [7 x i8] c"Sensor\00"
@.str.6 = [6 x i8] c"Flash\00"
@.str.7 = [5 x i8] c"Lens\00"
@MEDIA_ENT_SUBTYPE_MASK = global i32 0
@MEDIA_ENT_TYPE_MASK = global i32 0
define i8* @media_entity_subtype_to_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @MEDIA_ENT_SUBTYPE_MASK
%7 = and i32 %5, %6
store i32 %7, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* @MEDIA_ENT_TYPE_MASK
%10 = and i32 %8, %9
switch i32 %10, label %31 [
i32 129, label %11
i32 128, label %21
]
11: ; preds = %1
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = icmp uge i64 %13, 5
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 0, i32* %4
br label %16
16: ; preds = %15, %11
%17 = load i32, i32* %4
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* @media_entity_subtype_to_string.node_types, i64 0, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %2
br label %33
21: ; preds = %1
%22 = load i32, i32* %4
%23 = zext i32 %22 to i64
%24 = icmp uge i64 %23, 4
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %4
br label %26
26: ; preds = %25, %21
%27 = load i32, i32* %4
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [4 x i8*], [4 x i8*]* @media_entity_subtype_to_string.subdev_types, i64 0, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %2
br label %33
31: ; preds = %1
%32 = load i8*, i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @media_entity_subtype_to_string.node_types, i64 0, i64 0)
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %26, %16
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@media_entity_subtype_to_string.node_types = internal unnamed_addr constant [5 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0)]
@.str = [8 x i8] c"Unknown\00"
@.str.1 = [4 x i8] c"V4L\00"
@.str.2 = [3 x i8] c"FB\00"
@.str.3 = [5 x i8] c"ALSA\00"
@.str.4 = [4 x i8] c"DVB\00"
@media_entity_subtype_to_string.subdev_types = internal unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0)]
@.str.5 = [7 x i8] c"Sensor\00"
@.str.6 = [6 x i8] c"Flash\00"
@.str.7 = [5 x i8] c"Lens\00"
@MEDIA_ENT_SUBTYPE_MASK = global i32 0
@MEDIA_ENT_TYPE_MASK = global i32 0
define i8* @media_entity_subtype_to_string(i32 %0) {
%2 = load i32, i32* @MEDIA_ENT_SUBTYPE_MASK
%3 = and i32 %2, %0
%4 = load i32, i32* @MEDIA_ENT_TYPE_MASK
%5 = and i32 %4, %0
switch i32 %5, label %19 [
i32 129, label %6
i32 128, label %11
]
6: ; preds = %1
%7 = icmp ugt i32 %3, 4
%8 = select i1 %7, i32 0, i32 %3
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* @media_entity_subtype_to_string.node_types, i64 0, i64 %9
br label %16
11: ; preds = %1
%12 = icmp ugt i32 %3, 3
%13 = select i1 %12, i32 0, i32 %3
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* @media_entity_subtype_to_string.subdev_types, i64 0, i64 %14
br label %16
16: ; preds = %6, %11
%17 = phi i8** [ %15, %11 ], [ %10, %6 ]
%18 = load i8*, i8** %17
br label %19
19: ; preds = %16, %1
%20 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ], [ %18, %16 ]
ret i8* %20
}