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

/* Variables and functions */
#define MEDIA_PAD_FL_SINK 129
#define MEDIA_PAD_FL_SOURCE 128
const char *media_pad_type_to_string(unsigned flag) {
  static const struct {
    __u32 flag;
    const char *name;
  } flags[] = {
      {MEDIA_PAD_FL_SINK, "Sink"},
      {MEDIA_PAD_FL_SOURCE, "Source"},
  };
  unsigned int i;
  for (i = 0; i < (sizeof(flags) / sizeof((flags)[0])); i++) {
    if (flags[i].flag & flag)
      return flags[i].name;
  }
  return "Unknown";
}


x86 assembly (clang, -O0):
<media_pad_type_to_string>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    $0x2,%rax
jae    116f <media_pad_type_to_string+0x6f>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2d09(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     115c <media_pad_type_to_string+0x5c>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
lea    0x2ce8(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    117a <media_pad_type_to_string+0x7a>
jmp    1161 <media_pad_type_to_string+0x61>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    110e <media_pad_type_to_string+0xe>
lea    0xe96(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<media_pad_type_to_string>:
test   $0x81,%dil
je     110a <media_pad_type_to_string+0xa>
xor    %eax,%eax
jmp    111d <media_pad_type_to_string+0x1d>
mov    $0x1,%eax
test   $0x80,%dil
jne    111d <media_pad_type_to_string+0x1d>
lea    0xef0(%rip),%rax
ret
shl    $0x4,%rax
lea    0x2d08(%rip),%rcx
mov    0x8(%rax,%rcx,1),%rax
ret

LLVM IR (-O0):
%struct.anon = type { i32, i8* }
@media_pad_type_to_string.flags = 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 ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [5 x i8] c"Sink\00"
@.str.1 = [7 x i8] c"Source\00"
@.str.2 = [8 x i8] c"Unknown\00"
define i8* @media_pad_type_to_string(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %25, %1
%6 = load i32, i32* %4
%7 = zext i32 %6 to i64
%8 = icmp ult i64 %7, 2
br i1 %8, label %9, label %28
9: ; preds = %5
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_pad_type_to_string.flags, i64 0, i64 %11
%13 = getelementptr inbounds %struct.anon, %struct.anon* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* %3
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %9
%19 = load i32, i32* %4
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_pad_type_to_string.flags, i64 0, i64 %20
%22 = getelementptr inbounds %struct.anon, %struct.anon* %21, i32 0, i32 1
%23 = load i8*, i8** %22
store i8* %23, i8** %2
br label %29
24: ; preds = %9
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = add i32 %26, 1
store i32 %27, i32* %4
br label %5
28: ; preds = %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %29
29: ; preds = %28, %18
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
%struct.anon = type { i32, i8* }
@media_pad_type_to_string.flags = 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 ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0) }]
@.str = [5 x i8] c"Sink\00"
@.str.1 = [7 x i8] c"Source\00"
@.str.2 = [8 x i8] c"Unknown\00"
define i8* @media_pad_type_to_string(i32 %0) {
%2 = and i32 %0, 129
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %8, %1
%5 = phi i64 [ 0, %1 ], [ 1, %8 ]
%6 = getelementptr inbounds [2 x %struct.anon], [2 x %struct.anon]* @media_pad_type_to_string.flags, i64 0, i64 %5, i32 1
%7 = load i8*, i8** %6
br label %11
8: ; preds = %1
%9 = and i32 %0, 128
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %4
11: ; preds = %8, %4
%12 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %8 ]
ret i8* %12
}