#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 const *, char, char);
void i830_debug_dvo(char *result, int len, int reg, uint32_t val,
                    uint32_t devid) {
  const char *enable = val & (1 << 31) ? "enabled" : "disabled";
  char disp_pipe = val & (1 << 30) ? 'B' : 'A';
  const char *stall;
  char hsync = val & (1 << 3) ? '+' : '-';
  char vsync = val & (1 << 4) ? '+' : '-';
  switch (val & (3 << 28)) {
  case (0 << 28):
    stall = "no stall";
    break;
  case (1 << 28):
    stall = "stall";
    break;
  case (2 << 28):
    stall = "TV stall";
    break;
  default:
    stall = "unknown stall";
    break;
  }
  snprintf(result, len, "%s, pipe %c, %s, %chsync, %cvsync", enable, disp_pipe,
           stall, hsync, vsync);
}


x86 assembly (clang, -O0):
<i830_debug_dvo>:
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),%eax
shr    $0x1e,%eax
and    $0x1,%eax
add    $0x41,%al
mov    %al,-0x21(%rbp)
mov    -0x14(%rbp),%eax
test   $0x8,%al
sete   %al
add    %al,%al
add    $0x2b,%al
mov    %al,-0x31(%rbp)
mov    -0x14(%rbp),%eax
test   $0x10,%al
sete   %al
add    %al,%al
add    $0x2b,%al
mov    %al,-0x32(%rbp)
mov    -0x14(%rbp),%eax
and    $0x30000000,%eax
mov    %eax,-0x38(%rbp)
je     11b0 <i830_debug_dvo+0xa0>
jmp    118a <i830_debug_dvo+0x7a>
mov    -0x38(%rbp),%eax
sub    $0x10000000,%eax
je     11c0 <i830_debug_dvo+0xb0>
jmp    119d <i830_debug_dvo+0x8d>
mov    -0x38(%rbp),%eax
sub    $0x20000000,%eax
je     11d0 <i830_debug_dvo+0xc0>
jmp    11e0 <i830_debug_dvo+0xd0>
lea    0xe5a(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11eb <i830_debug_dvo+0xdb>
lea    0xe56(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11eb <i830_debug_dvo+0xdb>
lea    0xe43(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11eb <i830_debug_dvo+0xdb>
lea    0xe3c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x21(%rbp),%r8b
mov    -0x30(%rbp),%r9
mov    -0x31(%rbp),%al
lea    0xe29(%rip),%rdx
movsbl %r8b,%r8d
movsbl %al,%eax
mov    %eax,(%rsp)
movsbl -0x32(%rbp),%eax
mov    %eax,0x8(%rsp)
call   1030 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i830_debug_dvo>:
mov    %ecx,%eax
and    $0x30000000,%eax
je     1130 <i830_debug_dvo+0x20>
cmp    $0x20000000,%eax
je     1139 <i830_debug_dvo+0x29>
cmp    $0x10000000,%eax
jne    1142 <i830_debug_dvo+0x32>
lea    0xeef(%rip),%r9
jmp    1149 <i830_debug_dvo+0x39>
lea    0xeda(%rip),%r9
jmp    1149 <i830_debug_dvo+0x39>
lea    0xeda(%rip),%r9
jmp    1149 <i830_debug_dvo+0x39>
lea    0xeda(%rip),%r9
push   %rax
xor    %eax,%eax
test   $0x10,%cl
sete   %al
xor    %r8d,%r8d
test   $0x8,%cl
sete   %r8b
mov    %ecx,%edx
and    $0x40000000,%edx
test   %ecx,%ecx
lea    0xe9b(%rip),%r10
lea    0xe8c(%rip),%rcx
cmovns %r10,%rcx
lea    (%rax,%rax,1),%r10d
add    $0x2b,%r10d
lea    (%r8,%r8,1),%eax
add    $0x2b,%eax
cmp    $0x1,%edx
mov    $0x42,%r8d
sbb    $0x0,%r8d
lea    0xe96(%rip),%rdx
push   %r10
push   %rax
call   1030 <snprintf@plt>
add    $0x10,%rsp
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"no stall\00"
@.str.3 = [6 x i8] c"stall\00"
@.str.4 = [9 x i8] c"TV stall\00"
@.str.5 = [14 x i8] c"unknown stall\00"
@.str.6 = [34 x i8] c"%s, pipe %c, %s, %chsync, %cvsync\00"
define void @i830_debug_dvo(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
%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 = and i32 %16, -2147483648
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, 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* %20, i8** %11
%21 = load i32, i32* %9
%22 = and i32 %21, 1073741824
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 66, i32 65
%26 = trunc i32 %25 to i8
store i8 %26, i8* %12
%27 = load i32, i32* %9
%28 = and i32 %27, 8
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 43, i32 45
%32 = trunc i32 %31 to i8
store i8 %32, i8* %14
%33 = load i32, i32* %9
%34 = and i32 %33, 16
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 43, i32 45
%38 = trunc i32 %37 to i8
store i8 %38, i8* %15
%39 = load i32, i32* %9
%40 = and i32 %39, 805306368
switch i32 %40, label %44 [
i32 0, label %41
i32 268435456, label %42
i32 536870912, label %43
]
41: ; preds = %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %13
br label %45
42: ; preds = %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %13
br label %45
43: ; preds = %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %13
br label %45
44: ; preds = %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8** %13
br label %45
45: ; preds = %44, %43, %42, %41
%46 = load i8*, i8** %6
%47 = load i32, i32* %7
%48 = load i8*, i8** %11
%49 = load i8, i8* %12
%50 = load i8*, i8** %13
%51 = load i8, i8* %14
%52 = load i8, i8* %15
%53 = call i32 @snprintf(i8* %46, i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %48, i8 signext %49, i8* %50, i8 signext %51, i8 signext %52)
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"no stall\00"
@.str.3 = [6 x i8] c"stall\00"
@.str.4 = [9 x i8] c"TV stall\00"
@.str.5 = [14 x i8] c"unknown stall\00"
@.str.6 = [34 x i8] c"%s, pipe %c, %s, %chsync, %cvsync\00"
define void @i830_debug_dvo(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = and i32 %3, 805306368
switch i32 %6, label %9 [
i32 0, label %10
i32 268435456, label %7
i32 536870912, label %8
]
7: ; preds = %5
br label %10
8: ; preds = %5
br label %10
9: ; preds = %5
br label %10
10: ; preds = %5, %9, %8, %7
%11 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %5 ]
%12 = and i32 %3, 16
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8 45, i8 43
%15 = and i32 %3, 8
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8 45, i8 43
%18 = and i32 %3, 1073741824
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 65, i8 66
%21 = icmp sgt i32 %3, -1
%22 = select i1 %21, 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)
%23 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %22, i8 signext %20, i8* %11, i8 signext %17, i8 signext %14)
ret void
}