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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, ...);
int readb_idx_reg(int, int);
int /*<<< orphan*/ writeb_idx_mask(int, int, int, int);
int dump_lvds(void) {
  u_int8_t val;
  char *mode;
  writeb_idx_mask(0x3c5, 0x5a, 0x01, 0x01);
  val = readb_idx_reg(0x3c5, 0x13);
  switch (val >> 6) {
  case 0:
    mode = "LVDS1 + LVDS2";
    break;
  case 2:
    mode = "One Dual LVDS Channel";
    break;
  default:
    mode = "RESERVED";
    break;
  }
  printf("LVDS Seq Mode: %s\n", mode);
  val = readb_idx_reg(0x3d5, 0xd2);
  switch ((val >> 4) & 3) {
  case 0:
    mode = "LVDS1 + LVDS2";
    break;
  case 2:
    mode = "One Dual LVDS Channel";
    break;
  default:
    mode = "RESERVED";
    break;
  }
  printf("LVDS CRT Mode: %s\n", mode);
  printf("LVDS Channel 1 Format %s, Power %s\n", val & 2 ? "OpenLDI" : "SPWG",
         val & 0x80 ? "Down" : "Up");
  printf("LVDS Channel 2 Format %s, Power %s\n", val & 1 ? "OpenLDI" : "SPWG",
         val & 0x40 ? "Down" : "Up");
}


x86 assembly (clang, -O0):
<dump_lvds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x3c5,%edi
mov    %edi,-0x18(%rbp)
mov    $0x5a,%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1040 <writeb_idx_mask@plt>
mov    -0x18(%rbp),%edi
mov    $0x13,%esi
call   1050 <readb_idx_reg@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x6,%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1188 <dump_lvds+0x58>
jmp    1177 <dump_lvds+0x47>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1198 <dump_lvds+0x68>
jmp    11a8 <dump_lvds+0x78>
lea    0xe71(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b3 <dump_lvds+0x83>
lea    0xe6f(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b3 <dump_lvds+0x83>
lea    0xe75(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3d5,%edi
mov    $0xd2,%esi
call   1050 <readb_idx_reg@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x4,%eax
and    $0x3,%eax
mov    %eax,-0x1c(%rbp)
je     11ff <dump_lvds+0xcf>
jmp    11ee <dump_lvds+0xbe>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     120f <dump_lvds+0xdf>
jmp    121f <dump_lvds+0xef>
lea    0xdfa(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    122a <dump_lvds+0xfa>
lea    0xdf8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    122a <dump_lvds+0xfa>
lea    0xdfe(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
and    $0x2,%ecx
lea    0xe36(%rip),%rsi
lea    0xe27(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x8(%rbp),%ecx
and    $0x80,%ecx
lea    0xe22(%rip),%rdx
lea    0xe16(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
and    $0x1,%ecx
lea    0xdef(%rip),%rsi
lea    0xde0(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x8(%rbp),%ecx
and    $0x40,%ecx
lea    0xdde(%rip),%rdx
lea    0xdd2(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_lvds>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x3c5,%edi
mov    $0x5a,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1040 <writeb_idx_mask@plt>
mov    $0x3c5,%edi
mov    $0x13,%esi
call   1050 <readb_idx_reg@plt>
mov    %eax,%ecx
and    $0xffffffc0,%ecx
cmp    $0x80,%ecx
lea    0xe9c(%rip),%r15
lea    0xeab(%rip),%rbx
mov    %rbx,%rsi
cmove  %r15,%rsi
cmp    $0x40,%eax
lea    0xe76(%rip),%rbp
cmovb  %rbp,%rsi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3d5,%edi
mov    $0xd2,%esi
call   1050 <readb_idx_reg@plt>
mov    %eax,%r14d
shr    $0x4,%eax
and    $0x3,%eax
cmp    $0x2,%eax
cmove  %r15,%rbx
test   %eax,%eax
cmove  %rbp,%rbx
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   $0x2,%r14b
lea    0xea2(%rip),%r15
lea    0xe93(%rip),%rbx
mov    %rbx,%rsi
cmove  %r15,%rsi
test   $0x80,%r14b
lea    0xe93(%rip),%r12
lea    0xe87(%rip),%rbp
mov    %rbp,%rdx
cmove  %r12,%rdx
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   $0x1,%r14b
cmove  %r15,%rbx
test   $0x40,%r14b
cmove  %r12,%rbp
lea    0xe63(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"LVDS1 + LVDS2\00"
@.str.1 = [22 x i8] c"One Dual LVDS Channel\00"
@.str.2 = [9 x i8] c"RESERVED\00"
@.str.3 = [19 x i8] c"LVDS Seq Mode: %s\0A\00"
@.str.4 = [19 x i8] c"LVDS CRT Mode: %s\0A\00"
@.str.5 = [36 x i8] c"LVDS Channel 1 Format %s, Power %s\0A\00"
@.str.6 = [8 x i8] c"OpenLDI\00"
@.str.7 = [5 x i8] c"SPWG\00"
@.str.8 = [5 x i8] c"Down\00"
@.str.9 = [3 x i8] c"Up\00"
@.str.10 = [36 x i8] c"LVDS Channel 2 Format %s, Power %s\0A\00"
define i32 @dump_lvds() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @writeb_idx_mask(i32 965, i32 90, i32 1, i32 1)
%5 = call i32 @readb_idx_reg(i32 965, i32 19)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = ashr i32 %6, 6
switch i32 %7, label %10 [
i32 0, label %8
i32 2, label %9
]
8: ; preds = %0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %3
br label %11
9: ; preds = %0
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %11
10: ; preds = %0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %11
11: ; preds = %10, %9, %8
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = call i32 @readb_idx_reg(i32 981, i32 210)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = ashr i32 %15, 4
%17 = and i32 %16, 3
switch i32 %17, label %20 [
i32 0, label %18
i32 2, label %19
]
18: ; preds = %11
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %3
br label %21
19: ; preds = %11
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %21
20: ; preds = %11
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %21
21: ; preds = %20, %19, %18
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %2
%25 = and i32 %24, 2
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%29 = load i32, i32* %2
%30 = and i32 %29, 128
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %28, i8* %33)
%35 = load i32, i32* %2
%36 = and i32 %35, 1
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%40 = load i32, i32* %2
%41 = and i32 %40, 64
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0)
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %39, i8* %44)
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"LVDS1 + LVDS2\00"
@.str.1 = [22 x i8] c"One Dual LVDS Channel\00"
@.str.2 = [9 x i8] c"RESERVED\00"
@.str.3 = [19 x i8] c"LVDS Seq Mode: %s\0A\00"
@.str.4 = [19 x i8] c"LVDS CRT Mode: %s\0A\00"
@.str.5 = [36 x i8] c"LVDS Channel 1 Format %s, Power %s\0A\00"
@.str.6 = [8 x i8] c"OpenLDI\00"
@.str.7 = [5 x i8] c"SPWG\00"
@.str.8 = [5 x i8] c"Down\00"
@.str.9 = [3 x i8] c"Up\00"
@.str.10 = [36 x i8] c"LVDS Channel 2 Format %s, Power %s\0A\00"
define i32 @dump_lvds() {
%1 = tail call i32 @writeb_idx_mask(i32 965, i32 90, i32 1, i32 1)
%2 = tail call i32 @readb_idx_reg(i32 965, i32 19)
%3 = and i32 %2, -64
%4 = icmp eq i32 %3, 128
%5 = select i1 %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
%6 = icmp ult i32 %2, 64
%7 = select i1 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i32 @readb_idx_reg(i32 981, i32 210)
%10 = lshr i32 %9, 4
%11 = and i32 %10, 3
%12 = icmp eq i32 %11, 2
%13 = select i1 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
%14 = icmp eq i32 %11, 0
%15 = select i1 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = and i32 %9, 2
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0)
%20 = and i32 %9, 128
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %19, i8* %22)
%24 = and i32 %9, 1
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0)
%27 = and i32 %9, 64
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%30 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %26, i8* %29)
ret i32 undef
}