#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 const *, char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void i830_debug_sdvo(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 = val & (1 << 29) ? "enabled" : "disabled";
  const char *detected = val & (1 << 2) ? "" : "not ";
  const char *gang = val & (1 << 16) ? ", gang mode" : "";
  char sdvoextra[20];
  if (((devid) == 0x2582 || (devid) == 0x258A || (devid) == 0x2592)) {
    sprintf(sdvoextra, ", SDVO mult %d", (int)((val & (7 << 23)) >> 23) + 1);
  } else {
    sdvoextra[0] = '\0';
  }
  snprintf(result, len, "%s, pipe %c, stall %s, %sdetected%s%s", enable,
           disp_pipe, stall, detected, sdvoextra, gang);
}


x86 assembly (clang, -O0):
<i830_debug_sdvo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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
and    $0x80000000,%edx
lea    0xebc(%rip),%rax
lea    0xead(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edx
and    $0x40000000,%edx
mov    $0x41,%eax
mov    $0x42,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x21(%rbp)
mov    -0x14(%rbp),%edx
and    $0x20000000,%edx
lea    0xe7e(%rip),%rax
lea    0xe6f(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edx
and    $0x4,%edx
lea    0xe68(%rip),%rax
lea    0xe65(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edx
and    $0x10000,%edx
lea    0xe4a(%rip),%rax
lea    0xe44(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x2582,-0x18(%rbp)
je     1204 <i830_debug_sdvo+0xe4>
cmpl   $0x258a,-0x18(%rbp)
je     1204 <i830_debug_sdvo+0xe4>
cmpl   $0x2592,-0x18(%rbp)
jne    1228 <i830_debug_sdvo+0x108>
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%edx
and    $0x3800000,%edx
sar    $0x17,%edx
add    $0x1,%edx
lea    0xe04(%rip),%rsi
call   1040 <sprintf@plt>
jmp    122c <i830_debug_sdvo+0x10c>
movb   $0x0,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x21(%rbp),%r8b
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%r11
lea    -0x60(%rbp),%r10
mov    -0x40(%rbp),%rax
lea    0xddf(%rip),%rdx
movsbl %r8b,%r8d
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <snprintf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i830_debug_sdvo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
add    $0xffffda7e,%r8d
cmp    $0x10,%r8d
ja     1166 <i830_debug_sdvo+0x46>
mov    $0x10101,%eax
bt     %r8d,%eax
jae    1166 <i830_debug_sdvo+0x46>
mov    %ebp,%edx
shr    $0x17,%edx
and    $0x7,%edx
add    $0x1,%edx
lea    0xec6(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
jmp    116a <i830_debug_sdvo+0x4a>
movb   $0x0,(%rsp)
test   $0x10000,%ebp
lea    0xe9e(%rip),%rcx
lea    0xe98(%rip),%rax
cmove  %rcx,%rax
test   $0x4,%bpl
lea    0xe84(%rip),%rbx
cmovne %rcx,%rbx
test   $0x20000000,%ebp
lea    0xe6a(%rip),%rdx
lea    0xe5b(%rip),%rcx
mov    %rcx,%r9
cmove  %rdx,%r9
mov    %ebp,%esi
and    $0x40000000,%esi
test   %ebp,%ebp
cmovns %rdx,%rcx
sub    $0x8,%rsp
lea    0x8(%rsp),%rbp
cmp    $0x1,%esi
mov    $0x42,%r8d
sbb    $0x0,%r8d
lea    0xe5a(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
push   %rax
push   %rbp
push   %rbx
call   1030 <snprintf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"enabled\00"
@.str.1 = [9 x i8] c"disabled\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"not \00"
@.str.4 = [12 x i8] c", gang mode\00"
@.str.5 = [15 x i8] c", SDVO mult %d\00"
@.str.6 = [38 x i8] c"%s, pipe %c, stall %s, %sdetected%s%s\00"
define void @i830_debug_sdvo(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*
%16 = alloca [20 x 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
%17 = load i32, i32* %9
%18 = and i32 %17, -2147483648
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, 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* %21, i8** %11
%22 = load i32, i32* %9
%23 = and i32 %22, 1073741824
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 66, i32 65
%27 = trunc i32 %26 to i8
store i8 %27, i8* %12
%28 = load i32, i32* %9
%29 = and i32 %28, 536870912
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, 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* %32, i8** %13
%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 ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
store i8* %37, i8** %14
%38 = load i32, i32* %9
%39 = and i32 %38, 65536
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
store i8* %42, i8** %15
%43 = load i32, i32* %10
%44 = icmp eq i32 %43, 9602
br i1 %44, label %51, label %45
45: ; preds = %5
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 9610
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, 9618
br i1 %50, label %51, label %58
51: ; preds = %48, %45, %5
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%53 = load i32, i32* %9
%54 = and i32 %53, 58720256
%55 = ashr i32 %54, 23
%56 = add nsw i32 %55, 1
%57 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %56)
br label %60
58: ; preds = %48
%59 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
store i8 0, i8* %59
br label %60
60: ; preds = %58, %51
%61 = load i8*, i8** %6
%62 = load i32, i32* %7
%63 = load i8*, i8** %11
%64 = load i8, i8* %12
%65 = load i8*, i8** %13
%66 = load i8*, i8** %14
%67 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%68 = load i8*, i8** %15
%69 = call i32 @snprintf(i8* %61, i32 %62, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %63, i8 signext %64, i8* %65, i8* %66, i8* %67, i8* %68)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"enabled\00"
@.str.1 = [9 x i8] c"disabled\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"not \00"
@.str.4 = [12 x i8] c", gang mode\00"
@.str.5 = [15 x i8] c", SDVO mult %d\00"
@.str.6 = [38 x i8] c"%s, pipe %c, stall %s, %sdetected%s%s\00"
define void @i830_debug_sdvo(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [20 x i8]
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
switch i32 %4, label %13 [
i32 9618, label %8
i32 9610, label %8
i32 9602, label %8
]
8: ; preds = %5, %5, %5
%9 = lshr i32 %3, 23
%10 = and i32 %9, 7
%11 = add nuw nsw i32 %10, 1
%12 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %11)
br label %14
13: ; preds = %5
store i8 0, i8* %7
br label %14
14: ; preds = %13, %8
%15 = and i32 %3, 65536
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0)
%18 = and i32 %3, 4
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%21 = and i32 %3, 536870912
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, 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)
%24 = and i32 %3, 1073741824
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i8 65, i8 66
%27 = icmp sgt i32 %3, -1
%28 = select i1 %27, 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)
%29 = call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %28, i8 signext %26, i8* %23, i8* %20, i8* %7, i8* %17)
ret void
}