#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*/ sprintf(char *, char *, char *, char *, char *);
char *decode_capab(unsigned char c) {
  static char cstr[50];
  char *arm;
  char *thr;
  char *evt;
  unsigned char b;
  if ((c & 0x40) == 0)
    arm = "man";
  else
    arm = "auto";
  b = ((c & 0x0c) >> 2);
  switch (b) {
  case 0x00:
    thr = "none";
    break;
  case 0x01:
    thr = "read";
    break;
  case 0x02:
    thr = "write";
    break;
  case 0x03:
  default:
    thr = "fixed";
    break;
  }
  b = (c & 0x03);
  switch (b) {
  case 0x00:
    evt = "state";
    break;
  case 0x01:
    evt = "entire";
    break;
  case 0x02:
    evt = "disab";
    break;
  case 0x03:
  default:
    evt = "none";
    break;
  }
  sprintf(cstr, "arm=%s thr=%s evts=%s", arm, thr, evt);
  return (cstr);
}


x86 assembly (clang, -O0):
<decode_capab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
jne    113e <decode_capab+0x2e>
lea    0xeeb(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <decode_capab+0x39>
lea    0xedf(%rip),%rax
mov    %rax,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
and    $0xc,%eax
shr    $0x2,%eax
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%rax
ja     11b1 <decode_capab+0xa1>
mov    -0x30(%rbp),%rax
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea6(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <decode_capab+0xac>
lea    0xe9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <decode_capab+0xac>
lea    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <decode_capab+0xac>
jmp    11b1 <decode_capab+0xa1>
lea    0xe81(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1(%rbp),%al
and    $0x3,%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x3,%rax
ja     121f <decode_capab+0x10f>
mov    -0x38(%rbp),%rax
lea    0xe2f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe4e(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    122a <decode_capab+0x11a>
lea    0xe44(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    122a <decode_capab+0x11a>
lea    0xe3b(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    122a <decode_capab+0x11a>
jmp    121f <decode_capab+0x10f>
lea    0xe03(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0x2e03(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2df0(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_capab>:
push   %rbx
mov    %edi,%eax
shr    $0x2,%al
and    $0x3,%al
cmp    $0x3,%al
jne    1125 <decode_capab+0x15>
lea    0xef6(%rip),%rcx
jmp    1136 <decode_capab+0x26>
movzbl %al,%eax
lea    0xf19(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
mov    %edi,%eax
and    $0x3,%al
cmp    $0x3,%al
jne    1147 <decode_capab+0x37>
lea    0xec4(%rip),%r8
jmp    1158 <decode_capab+0x48>
movzbl %al,%eax
lea    0xf03(%rip),%rdx
movslq (%rdx,%rax,4),%r8
add    %rdx,%r8
test   $0x40,%dil
lea    0xe9d(%rip),%rax
lea    0xe9a(%rip),%rdx
cmove  %rax,%rdx
lea    0x2ecb(%rip),%rbx
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@decode_capab.cstr = internal global [50 x i8] zeroinitializer
@.str = [4 x i8] c"man\00"
@.str.1 = [5 x i8] c"auto\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [6 x i8] c"fixed\00"
@.str.6 = [6 x i8] c"state\00"
@.str.7 = [7 x i8] c"entire\00"
@.str.8 = [6 x i8] c"disab\00"
@.str.9 = [22 x i8] c"arm=%s thr=%s evts=%s\00"
define i8* @decode_capab(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i8 %0, i8* %2
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = and i32 %8, 64
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
br label %13
12: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %13
13: ; preds = %12, %11
%14 = load i8, i8* %2
%15 = zext i8 %14 to i32
%16 = and i32 %15, 12
%17 = ashr i32 %16, 2
%18 = trunc i32 %17 to i8
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = zext i8 %19 to i32
switch i32 %20, label %25 [
i32 0, label %21
i32 1, label %22
i32 2, label %23
i32 3, label %24
]
21: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %26
22: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %26
23: ; preds = %13
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %4
br label %26
24: ; preds = %13
br label %25
25: ; preds = %13, %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8** %4
br label %26
26: ; preds = %25, %23, %22, %21
%27 = load i8, i8* %2
%28 = zext i8 %27 to i32
%29 = and i32 %28, 3
%30 = trunc i32 %29 to i8
store i8 %30, i8* %6
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
switch i32 %32, label %37 [
i32 0, label %33
i32 1, label %34
i32 2, label %35
i32 3, label %36
]
33: ; preds = %26
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %5
br label %38
34: ; preds = %26
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %5
br label %38
35: ; preds = %26
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8** %5
br label %38
36: ; preds = %26
br label %37
37: ; preds = %26, %36
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %38
38: ; preds = %37, %35, %34, %33
%39 = load i8*, i8** %3
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = call i32 @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @decode_capab.cstr, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %39, i8* %40, i8* %41)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @decode_capab.cstr, i64 0, i64 0)
}

LLVM IR (-O2):
@decode_capab.cstr = internal global [50 x i8] zeroinitializer
@.str = [4 x i8] c"man\00"
@.str.1 = [5 x i8] c"auto\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [6 x i8] c"fixed\00"
@.str.6 = [6 x i8] c"state\00"
@.str.7 = [7 x i8] c"entire\00"
@.str.8 = [6 x i8] c"disab\00"
@.str.9 = [22 x i8] c"arm=%s thr=%s evts=%s\00"
@reltable.decode_capab = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab to i64)) to i32)]
@reltable.decode_capab.11 = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.6 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([3 x i32]* @reltable.decode_capab.11 to i64)) to i32)]
define i8* @decode_capab(i8 zeroext %0) {
%2 = lshr i8 %0, 2
%3 = and i8 %2, 3
%4 = icmp eq i8 %3, 3
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = zext i8 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.decode_capab to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %1 ]
%11 = and i8 %0, 3
%12 = icmp eq i8 %11, 3
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = zext i8 %11 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.decode_capab.11 to i8*), i64 %15)
br label %17
17: ; preds = %9, %13
%18 = phi i8* [ %16, %13 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %9 ]
%19 = and i8 %0, 64
%20 = icmp eq i8 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%22 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @decode_capab.cstr, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %21, i8* %10, i8* %18)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @decode_capab.cstr, i64 0, i64 0)
}