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

/* Variables and functions */
int /*<<< orphan*/ MEDIA_ENT_TYPE_MASK;
#define MEDIA_ENT_T_DEVNODE 129
#define MEDIA_ENT_T_V4L2_SUBDEV 128
const char *media_entity_type_to_string(unsigned type) {
  static const struct {
    __u32 type;
    const char *name;
  } types[] = {
      {MEDIA_ENT_T_DEVNODE, "Node"},
      {MEDIA_ENT_T_V4L2_SUBDEV, "V4L2 subdev"},
  };
  unsigned int i;
  type &= MEDIA_ENT_TYPE_MASK;
  for (i = 0; i < (sizeof(types) / sizeof((types)[0])); i++) {
    if (types[i].type == type)
      return types[i].name;
  }
  return "Unknown";
}


x86 assembly (clang, -O0):
<media_entity_type_to_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    0x2eda(%rip),%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    $0x2,%rax
jae    117b <media_entity_type_to_string+0x7b>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2cea(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jne    1168 <media_entity_type_to_string+0x68>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2ccc(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <media_entity_type_to_string+0x86>
jmp    116d <media_entity_type_to_string+0x6d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    111d <media_entity_type_to_string+0x1d>
lea    0xe8f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<media_entity_type_to_string>:
mov    0x2ee1(%rip),%rax
and    (%rax),%edi
cmp    $0x81,%edi
je     1120 <media_entity_type_to_string+0x20>
cmp    $0x80,%edi
jne    1133 <media_entity_type_to_string+0x33>
mov    $0x1,%eax
jmp    1122 <media_entity_type_to_string+0x22>
xor    %eax,%eax
shl    $0x4,%rax
lea    0x2cf3(%rip),%rcx
mov    0x8(%rax,%rcx,1),%rax
ret
lea    0xed7(%rip),%rax
ret

LLVM IR (-O0):
%struct.anon = type { i32, i8* }
@media_entity_type_to_string.types = internal constant [2 x %struct.anon] [%struct.anon { i32 129, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [5 x i8] c"Node\00"
@.str.1 = [12 x i8] c"V4L2 subdev\00"
@MEDIA_ENT_TYPE_MASK = global i32 0
@.str.2 = [8 x i8] c"Unknown\00"
define i8* @media_entity_type_to_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @MEDIA_ENT_TYPE_MASK
%6 = load i32, i32* %3
%7 = and i32 %6, %5
store i32 %7, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %27, %1
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = icmp ult i64 %10, 2
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_entity_type_to_string.types, i64 0, i64 %14
%16 = getelementptr inbounds %struct.anon, %struct.anon* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_entity_type_to_string.types, i64 0, i64 %22
%24 = getelementptr inbounds %struct.anon, %struct.anon* %23, i32 0, i32 1
%25 = load i8*, i8** %24
store i8* %25, i8** %2
br label %31
26: ; preds = %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %8
30: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %31
31: ; preds = %30, %20
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
%struct.anon = type { i32, i8* }
@media_entity_type_to_string.types = internal unnamed_addr constant [2 x %struct.anon] [%struct.anon { i32 129, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0) }, %struct.anon { i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [5 x i8] c"Node\00"
@.str.1 = [12 x i8] c"V4L2 subdev\00"
@MEDIA_ENT_TYPE_MASK = global i32 0
@.str.2 = [8 x i8] c"Unknown\00"
define i8* @media_entity_type_to_string(i32 %0) {
%2 = load i32, i32* @MEDIA_ENT_TYPE_MASK
%3 = and i32 %2, %0
switch i32 %3, label %9 [
i32 129, label %5
i32 128, label %4
]
4: ; preds = %1
br label %5
5: ; preds = %1, %4
%6 = phi i64 [ 0, %1 ], [ 1, %4 ]
%7 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_entity_type_to_string.types, i64 0, i64 %6, i32 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %1 ]
ret i8* %10
}