#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 const *,
                            char const *, char const *);
void hsw_debug_ddi_buf_ctl(char *result, int len, int reg, uint32_t val,
                           uint32_t devid) {
  const char *enable, *reversal, *width, *detected;
  enable = (val & (1 << 31)) ? "enabled" : "disabled";
  reversal = (val & (1 << 16)) ? "reversed" : "not reversed";
  switch ((val >> 1) & 7) {
  case 0:
    width = "x1";
    break;
  case 1:
    width = "x2";
    break;
  case 3:
    width = "x4";
    break;
  default:
    width = "reserved";
    break;
  }
  detected = (val & 1) ? "detected" : "not detected";
  snprintf(result, len, "%s %s %s %s", enable, reversal, width, detected);
}


x86 assembly (clang, -O0):
<hsw_debug_ddi_buf_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%edx
lea    0xecd(%rip),%rcx
lea    0xece(%rip),%rax
test   $0x80000000,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edx
lea    0xec3(%rip),%rcx
lea    0xeb8(%rip),%rax
test   $0x10000,%edx
cmovne %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shr    %eax
and    $0x7,%eax
mov    %eax,-0x3c(%rbp)
je     119f <hsw_debug_ddi_buf_ctl+0x8f>
jmp    117d <hsw_debug_ddi_buf_ctl+0x6d>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     11af <hsw_debug_ddi_buf_ctl+0x9f>
jmp    118e <hsw_debug_ddi_buf_ctl+0x7e>
mov    -0x3c(%rbp),%eax
sub    $0x3,%eax
je     11bf <hsw_debug_ddi_buf_ctl+0xaf>
jmp    11cf <hsw_debug_ddi_buf_ctl+0xbf>
lea    0xe78(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11da <hsw_debug_ddi_buf_ctl+0xca>
lea    0xe6b(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11da <hsw_debug_ddi_buf_ctl+0xca>
lea    0xe5e(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11da <hsw_debug_ddi_buf_ctl+0xca>
lea    0xe51(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edx
and    $0x1,%edx
lea    0xe49(%rip),%rax
lea    0xe46(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xe26(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hsw_debug_ddi_buf_ctl>:
push   %rax
mov    %ecx,%eax
shr    %eax
and    $0x7,%eax
cmp    $0x3,%eax
ja     112f <hsw_debug_ddi_buf_ctl+0x1f>
mov    %eax,%eax
lea    0xf26(%rip),%rdx
movslq (%rdx,%rax,4),%r9
add    %rdx,%r9
jmp    1136 <hsw_debug_ddi_buf_ctl+0x26>
lea    0xef1(%rip),%r9
test   $0x10000,%ecx
lea    0xece(%rip),%rax
lea    0xecb(%rip),%r8
cmove  %rax,%r8
test   %ecx,%ecx
lea    0xeb1(%rip),%rdx
lea    0xea2(%rip),%rax
cmovns %rdx,%rax
test   $0x1,%cl
lea    0xec4(%rip),%rcx
lea    0xec1(%rip),%rdx
cmove  %rcx,%rdx
mov    %rdx,(%rsp)
lea    0xebb(%rip),%rdx
mov    %rax,%rcx
call   1030 <snprintf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [8 x i8] c"enabled\00"
@.str.1 = [9 x i8] c"disabled\00"
@.str.2 = [9 x i8] c"reversed\00"
@.str.3 = [13 x i8] c"not reversed\00"
@.str.4 = [3 x i8] c"x1\00"
@.str.5 = [3 x i8] c"x2\00"
@.str.6 = [3 x i8] c"x4\00"
@.str.7 = [9 x i8] c"reserved\00"
@.str.8 = [9 x i8] c"detected\00"
@.str.9 = [13 x i8] c"not detected\00"
@.str.10 = [12 x i8] c"%s %s %s %s\00"
define void @hsw_debug_ddi_buf_ctl(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*
%12 = alloca i8*
%13 = alloca i8*
%14 = 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
%15 = load i32, i32* %9
%16 = and i32 %15, -2147483648
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
store i8* %19, i8** %11
%20 = load i32, i32* %9
%21 = and i32 %20, 65536
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0)
store i8* %24, i8** %12
%25 = load i32, i32* %9
%26 = ashr i32 %25, 1
%27 = and i32 %26, 7
switch i32 %27, label %31 [
i32 0, label %28
i32 1, label %29
i32 3, label %30
]
28: ; preds = %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %13
br label %32
29: ; preds = %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %13
br label %32
30: ; preds = %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %13
br label %32
31: ; preds = %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8** %13
br label %32
32: ; preds = %31, %30, %29, %28
%33 = load i32, i32* %9
%34 = and i32 %33, 1
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0)
store i8* %37, i8** %14
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = load i8*, i8** %11
%41 = load i8*, i8** %12
%42 = load i8*, i8** %13
%43 = load i8*, i8** %14
%44 = call i32 @snprintf(i8* %38, i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %40, i8* %41, i8* %42, i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"enabled\00"
@.str.1 = [9 x i8] c"disabled\00"
@.str.2 = [9 x i8] c"reversed\00"
@.str.3 = [13 x i8] c"not reversed\00"
@.str.4 = [3 x i8] c"x1\00"
@.str.5 = [3 x i8] c"x2\00"
@.str.6 = [3 x i8] c"x4\00"
@.str.7 = [9 x i8] c"reserved\00"
@.str.8 = [9 x i8] c"detected\00"
@.str.9 = [13 x i8] c"not detected\00"
@.str.10 = [12 x i8] c"%s %s %s %s\00"
@reltable.hsw_debug_ddi_buf_ctl = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_ddi_buf_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_ddi_buf_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_ddi_buf_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_ddi_buf_ctl to i64)) to i32)]
define void @hsw_debug_ddi_buf_ctl(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = lshr i32 %3, 1
%7 = and i32 %6, 7
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = zext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.hsw_debug_ddi_buf_ctl to i8*), i64 %11)
br label %13
13: ; preds = %5, %9
%14 = phi i8* [ %12, %9 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %5 ]
%15 = and i32 %3, 65536
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
%18 = icmp sgt i32 %3, -1
%19 = select i1 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0)
%20 = and i32 %3, 1
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0)
%23 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* %19, i8* %17, i8* %14, i8* %22)
ret void
}