#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *, char *,
                            char *, char *, char *);
void i830_debug_chdecmisc(char *result, int len, int reg, uint32_t val,
                          uint32_t devid) {
  const char *enhmodesel = NULL;
  switch ((val >> 5) & 3) {
  case 1:
    enhmodesel = "XOR bank/rank";
    break;
  case 2:
    enhmodesel = "swap bank";
    break;
  case 3:
    enhmodesel = "XOR bank";
    break;
  case 0:
    enhmodesel = "none";
    break;
  }
  snprintf(result, len,
           "%s, ch2 enh %sabled, ch1 enh %sabled, "
           "ch0 enh %sabled, "
           "flex %sabled, ep %spresent",
           enhmodesel, (val & (1 << 4)) ? "en" : "dis",
           (val & (1 << 3)) ? "en" : "dis", (val & (1 << 2)) ? "en" : "dis",
           (val & (1 << 1)) ? "en" : "dis", (val & (1 << 0)) ? "" : "not ");
}


x86 assembly (clang, -O0):
<i830_debug_chdecmisc>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
shr    $0x5,%eax
and    $0x3,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     1199 <i830_debug_chdecmisc+0x89>
mov    -0x30(%rbp),%rax
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeab(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1199 <i830_debug_chdecmisc+0x89>
lea    0xea9(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1199 <i830_debug_chdecmisc+0x89>
lea    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1199 <i830_debug_chdecmisc+0x89>
lea    0xe9c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%edx
and    $0x10,%edx
lea    0xeda(%rip),%r8
lea    0xed0(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r8
mov    -0x1c(%rbp),%edx
and    $0x8,%edx
lea    0xebf(%rip),%r9
lea    0xeb5(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r9
mov    -0x1c(%rbp),%edx
and    $0x4,%edx
lea    0xea4(%rip),%r11
lea    0xe9a(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r11
mov    -0x1c(%rbp),%edx
and    $0x2,%edx
lea    0xe89(%rip),%r10
lea    0xe7f(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r10
mov    -0x1c(%rbp),%ebx
and    $0x1,%ebx
lea    0xe72(%rip),%rax
lea    0xe6f(%rip),%rdx
cmp    $0x0,%ebx
cmovne %rdx,%rax
lea    0xe04(%rip),%rdx
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <snprintf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<i830_debug_chdecmisc>:
push   %rbx
mov    %ecx,%eax
shr    $0x5,%eax
and    $0x3,%eax
lea    0xf64(%rip),%rdx
movslq (%rdx,%rax,4),%r10
add    %rdx,%r10
test   $0x10,%cl
lea    0xf4a(%rip),%rdx
lea    0xf40(%rip),%rax
mov    %rax,%r8
cmove  %rdx,%r8
test   $0x8,%cl
mov    %rax,%r9
cmove  %rdx,%r9
test   $0x4,%cl
mov    %rax,%r11
cmove  %rdx,%r11
test   $0x2,%cl
cmove  %rdx,%rax
test   $0x1,%cl
lea    0xf1b(%rip),%rcx
lea    0xf18(%rip),%rbx
cmove  %rcx,%rbx
sub    $0x8,%rsp
lea    0xeac(%rip),%rdx
mov    %r10,%rcx
push   %rbx
push   %rax
push   %r11
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"XOR bank/rank\00"
@.str.1 = [10 x i8] c"swap bank\00"
@.str.2 = [9 x i8] c"XOR bank\00"
@.str.3 = [5 x i8] c"none\00"
@.str.4 = [82 x i8] c"%s, ch2 enh %sabled, ch1 enh %sabled, ch0 enh %sabled, flex %sabled, ep %spresent\00"
@.str.5 = [3 x i8] c"en\00"
@.str.6 = [4 x i8] c"dis\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [5 x i8] c"not \00"
define void @i830_debug_chdecmisc(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i8* null, i8** %11
%12 = load i32, i32* %9
%13 = ashr i32 %12, 5
%14 = and i32 %13, 3
switch i32 %14, label %19 [
i32 1, label %15
i32 2, label %16
i32 3, label %17
i32 0, label %18
]
15: ; preds = %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %11
br label %19
16: ; preds = %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %19
17: ; preds = %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %11
br label %19
18: ; preds = %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %11
br label %19
19: ; preds = %5, %18, %17, %16, %15
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = load i8*, i8** %11
%23 = load i32, i32* %9
%24 = and i32 %23, 16
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%28 = load i32, i32* %9
%29 = and i32 %28, 8
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%33 = load i32, i32* %9
%34 = and i32 %33, 4
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%38 = load i32, i32* %9
%39 = and i32 %38, 2
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%43 = load i32, i32* %9
%44 = and i32 %43, 1
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%48 = call i32 @snprintf(i8* %20, i32 %21, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %27, i8* %32, i8* %37, i8* %42, i8* %47)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"XOR bank/rank\00"
@.str.1 = [10 x i8] c"swap bank\00"
@.str.2 = [9 x i8] c"XOR bank\00"
@.str.3 = [5 x i8] c"none\00"
@.str.4 = [82 x i8] c"%s, ch2 enh %sabled, ch1 enh %sabled, ch0 enh %sabled, flex %sabled, ep %spresent\00"
@.str.5 = [3 x i8] c"en\00"
@.str.6 = [4 x i8] c"dis\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [5 x i8] c"not \00"
@reltable.i830_debug_chdecmisc = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.i830_debug_chdecmisc to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.i830_debug_chdecmisc to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.i830_debug_chdecmisc to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.i830_debug_chdecmisc to i64)) to i32)]
define void @i830_debug_chdecmisc(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = lshr i32 %3, 5
%7 = and i32 %6, 3
%8 = zext i32 %7 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.i830_debug_chdecmisc to i8*), i64 %9)
%11 = and i32 %3, 16
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%14 = and i32 %3, 8
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%17 = and i32 %3, 4
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%20 = and i32 %3, 2
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%23 = and i32 %3, 1
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%26 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %13, i8* %16, i8* %19, i8* %22, i8* %25)
ret void
}