#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 *, int, char const *,
                            char const *, int, int);
void hsw_debug_util_pin_ctl(char *result, int len, int reg, uint32_t val,
                            uint32_t devid) {
  int enable, data, inverted_polarity;
  const char *transcoder, *mode;
  enable = (val >> 31) & 1;
  switch ((val >> 29) & 3) {
  case 0:
    transcoder = "A";
    break;
  case 1:
    transcoder = "B";
    break;
  case 2:
    transcoder = "C";
    break;
  case 3:
    transcoder = "EDP";
    break;
  }
  switch ((val >> 24) & 0xF) {
  case 0:
    mode = "data";
    break;
  case 1:
    mode = "PWM";
    break;
  case 4:
    mode = "Vblank";
    break;
  case 5:
    mode = "Vsync";
    break;
  default:
    mode = "reserved";
    break;
  }
  data = (val >> 23) & 1;
  inverted_polarity = (val >> 22) & 1;
  snprintf(result, len,
           "enable %d, transcoder %s, mode %s, data %d "
           "inverted polarity %d",
           enable, transcoder, mode, data, inverted_polarity);
}


x86 assembly (clang, -O0):
<hsw_debug_util_pin_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x1f,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x1d,%eax
and    $0x3,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x3,%eax
ja     1199 <hsw_debug_util_pin_ctl+0x89>
mov    -0x40(%rbp),%rax
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec3(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1199 <hsw_debug_util_pin_ctl+0x89>
lea    0xeb5(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1199 <hsw_debug_util_pin_ctl+0x89>
lea    0xea7(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1199 <hsw_debug_util_pin_ctl+0x89>
lea    0xe99(%rip),%rax
mov    %rax,-0x30(%rbp)
movzbl -0x11(%rbp),%eax
and    $0xf,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x5,%eax
ja     1203 <hsw_debug_util_pin_ctl+0xf3>
mov    -0x48(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe68(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <hsw_debug_util_pin_ctl+0xfe>
lea    0xe5d(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <hsw_debug_util_pin_ctl+0xfe>
lea    0xe51(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <hsw_debug_util_pin_ctl+0xfe>
lea    0xe48(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    120e <hsw_debug_util_pin_ctl+0xfe>
lea    0xe3e(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x17,%eax
and    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x16,%eax
and    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
mov    -0x20(%rbp),%r10d
mov    -0x24(%rbp),%eax
lea    0xe0b(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <snprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hsw_debug_util_pin_ctl>:
push   %rax
mov    %ecx,%r10d
shr    $0x1d,%ecx
and    $0x3,%ecx
lea    0xf4b(%rip),%rdx
movslq (%rdx,%rcx,4),%r8
add    %rdx,%r8
mov    %r10d,%ecx
shr    $0x18,%ecx
and    $0xf,%ecx
cmp    $0x5,%ecx
ja     1148 <hsw_debug_util_pin_ctl+0x38>
mov    %ecx,%ecx
lea    0xf3d(%rip),%rdx
movslq (%rdx,%rcx,4),%r9
add    %rdx,%r9
jmp    114f <hsw_debug_util_pin_ctl+0x3f>
lea    0xed1(%rip),%r9
mov    %r10d,%ecx
shr    $0x1f,%ecx
mov    %r10d,%eax
shr    $0x17,%eax
and    $0x1,%eax
shr    $0x16,%r10d
and    $0x1,%r10d
lea    0xebc(%rip),%rdx
push   %r10
push   %rax
call   1030 <snprintf@plt>
add    $0x10,%rsp
pop    %rax
ret

LLVM IR (-O0):
@.str = [2 x i8] c"A\00"
@.str.1 = [2 x i8] c"B\00"
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [4 x i8] c"EDP\00"
@.str.4 = [5 x i8] c"data\00"
@.str.5 = [4 x i8] c"PWM\00"
@.str.6 = [7 x i8] c"Vblank\00"
@.str.7 = [6 x i8] c"Vsync\00"
@.str.8 = [9 x i8] c"reserved\00"
@.str.9 = [64 x i8] c"enable %d, transcoder %s, mode %s, data %d inverted polarity %d\00"
define void @hsw_debug_util_pin_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 i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = 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
%16 = load i32, i32* %9
%17 = ashr i32 %16, 31
%18 = and i32 %17, 1
store i32 %18, i32* %11
%19 = load i32, i32* %9
%20 = ashr i32 %19, 29
%21 = and i32 %20, 3
switch i32 %21, label %26 [
i32 0, label %22
i32 1, label %23
i32 2, label %24
i32 3, label %25
]
22: ; preds = %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %14
br label %26
23: ; preds = %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %14
br label %26
24: ; preds = %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %14
br label %26
25: ; preds = %5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %14
br label %26
26: ; preds = %5, %25, %24, %23, %22
%27 = load i32, i32* %9
%28 = ashr i32 %27, 24
%29 = and i32 %28, 15
switch i32 %29, label %34 [
i32 0, label %30
i32 1, label %31
i32 4, label %32
i32 5, label %33
]
30: ; preds = %26
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %15
br label %35
31: ; preds = %26
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %15
br label %35
32: ; preds = %26
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %15
br label %35
33: ; preds = %26
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %15
br label %35
34: ; preds = %26
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8** %15
br label %35
35: ; preds = %34, %33, %32, %31, %30
%36 = load i32, i32* %9
%37 = ashr i32 %36, 23
%38 = and i32 %37, 1
store i32 %38, i32* %12
%39 = load i32, i32* %9
%40 = ashr i32 %39, 22
%41 = and i32 %40, 1
store i32 %41, i32* %13
%42 = load i8*, i8** %6
%43 = load i32, i32* %7
%44 = load i32, i32* %11
%45 = load i8*, i8** %14
%46 = load i8*, i8** %15
%47 = load i32, i32* %12
%48 = load i32, i32* %13
%49 = call i32 @snprintf(i8* %42, i32 %43, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %44, i8* %45, i8* %46, i32 %47, i32 %48)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"A\00"
@.str.1 = [2 x i8] c"B\00"
@.str.2 = [2 x i8] c"C\00"
@.str.3 = [4 x i8] c"EDP\00"
@.str.4 = [5 x i8] c"data\00"
@.str.5 = [4 x i8] c"PWM\00"
@.str.6 = [7 x i8] c"Vblank\00"
@.str.7 = [6 x i8] c"Vsync\00"
@.str.8 = [9 x i8] c"reserved\00"
@.str.9 = [64 x i8] c"enable %d, transcoder %s, mode %s, data %d inverted polarity %d\00"
@reltable.hsw_debug_util_pin_ctl = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_util_pin_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_util_pin_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_util_pin_ctl to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.hsw_debug_util_pin_ctl to i64)) to i32)]
@reltable.hsw_debug_util_pin_ctl.11 = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.8 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.8 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i64)) to i32)]
define void @hsw_debug_util_pin_ctl(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = lshr i32 %3, 29
%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.hsw_debug_util_pin_ctl to i8*), i64 %9)
%11 = lshr i32 %3, 24
%12 = and i32 %11, 15
%13 = icmp ult i32 %12, 6
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = zext i32 %12 to i64
%16 = shl i64 %15, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.hsw_debug_util_pin_ctl.11 to i8*), i64 %16)
br label %18
18: ; preds = %5, %14
%19 = phi i8* [ %17, %14 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), %5 ]
%20 = lshr i32 %3, 31
%21 = lshr i32 %3, 23
%22 = and i32 %21, 1
%23 = lshr i32 %3, 22
%24 = and i32 %23, 1
%25 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %20, i8* %10, i8* %19, i32 %22, i32 %24)
ret void
}