#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;
typedef int u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int readb_idx_reg(int, int);
void dump_scaling(void) {
  u_int32_t h_scaling, v_scaling;
  u_int8_t val;
  val = readb_idx_reg(0x3d5, 0x79);
  if (val & 0x01) {
    printf("Panel Scaling enabled, mode %s\n",
           val & 0x02 ? "Interpolation" : "Duplication");
    v_scaling = (val >> 3) & 0x1;
    h_scaling = ((val >> 4) & 0x3) << 10;
    v_scaling |= ((val >> 6) & 0x3) << 9;
    val = readb_idx_reg(0x3d5, 0x77);
    h_scaling |= val << 2;
    val = readb_idx_reg(0x3d5, 0x78);
    v_scaling |= val << 1;
    val = readb_idx_reg(0x3d5, 0x9f);
    h_scaling |= val & 0x3;
    printf("Scaling Factors: horizontal=%u, vertical=%u\n", h_scaling,
           v_scaling);
  } else
    printf("Panel Scaling disabled\n");
}


x86 assembly (clang, -O0):
<dump_scaling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3d5,%edi
mov    $0x79,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1212 <dump_scaling+0xf2>
mov    -0xc(%rbp),%ecx
and    $0x2,%ecx
lea    0xed8(%rip),%rsi
lea    0xec3(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sar    $0x3,%eax
and    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
and    $0x3,%eax
shl    $0xa,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x6,%eax
and    $0x3,%eax
shl    $0x9,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x3d5,%edi
mov    $0x77,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0x3d5,%edi
mov    $0x78,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x3d5,%edi
mov    $0x9f,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <dump_scaling+0x100>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_scaling>:
push   %rbp
push   %r14
push   %rbx
mov    $0x3d5,%edi
mov    $0x79,%esi
call   1050 <readb_idx_reg@plt>
mov    %eax,%ebx
test   $0x1,%bl
jne    115a <dump_scaling+0x2a>
lea    0xf16(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
test   $0x2,%bl
lea    0xeca(%rip),%rax
lea    0xeb5(%rip),%rsi
cmove  %rax,%rsi
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
shr    $0x3,%eax
and    $0x1,%eax
mov    %ebx,%ebp
and    $0x30,%ebp
shl    $0x6,%ebp
and    $0xc0,%ebx
lea    (%rax,%rbx,8),%r14d
mov    $0x3d5,%edi
mov    $0x77,%esi
call   1050 <readb_idx_reg@plt>
lea    0x0(,%rax,4),%ebx
or     %ebp,%ebx
mov    $0x3d5,%edi
mov    $0x78,%esi
call   1050 <readb_idx_reg@plt>
lea    (%rax,%rax,1),%ebp
or     %r14d,%ebp
mov    $0x3d5,%edi
mov    $0x9f,%esi
call   1050 <readb_idx_reg@plt>
and    $0x3,%eax
or     %eax,%ebx
lea    0xe5b(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Panel Scaling enabled, mode %s\0A\00"
@.str.1 = [14 x i8] c"Interpolation\00"
@.str.2 = [12 x i8] c"Duplication\00"
@.str.3 = [45 x i8] c"Scaling Factors: horizontal=%u, vertical=%u\0A\00"
@.str.4 = [24 x i8] c"Panel Scaling disabled\0A\00"
define void @dump_scaling() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @readb_idx_reg(i32 981, i32 121)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, 1
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %0
%9 = load i32, i32* %3
%10 = and i32 %9, 2
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* %3
%16 = ashr i32 %15, 3
%17 = and i32 %16, 1
store i32 %17, i32* %2
%18 = load i32, i32* %3
%19 = ashr i32 %18, 4
%20 = and i32 %19, 3
%21 = shl i32 %20, 10
store i32 %21, i32* %1
%22 = load i32, i32* %3
%23 = ashr i32 %22, 6
%24 = and i32 %23, 3
%25 = shl i32 %24, 9
%26 = load i32, i32* %2
%27 = or i32 %26, %25
store i32 %27, i32* %2
%28 = call i32 @readb_idx_reg(i32 981, i32 119)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = shl i32 %29, 2
%31 = load i32, i32* %1
%32 = or i32 %31, %30
store i32 %32, i32* %1
%33 = call i32 @readb_idx_reg(i32 981, i32 120)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = shl i32 %34, 1
%36 = load i32, i32* %2
%37 = or i32 %36, %35
store i32 %37, i32* %2
%38 = call i32 @readb_idx_reg(i32 981, i32 159)
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = and i32 %39, 3
%41 = load i32, i32* %1
%42 = or i32 %41, %40
store i32 %42, i32* %1
%43 = load i32, i32* %1
%44 = load i32, i32* %2
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %44)
br label %48
46: ; preds = %0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %8
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Panel Scaling enabled, mode %s\0A\00"
@.str.1 = [14 x i8] c"Interpolation\00"
@.str.2 = [12 x i8] c"Duplication\00"
@.str.3 = [45 x i8] c"Scaling Factors: horizontal=%u, vertical=%u\0A\00"
@str = [23 x i8] c"Panel Scaling disabled\00"
define void @dump_scaling() {
%1 = tail call i32 @readb_idx_reg(i32 981, i32 121)
%2 = and i32 %1, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %26, label %4
4: ; preds = %0
%5 = and i32 %1, 2
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = lshr i32 %1, 3
%10 = and i32 %9, 1
%11 = shl i32 %1, 6
%12 = and i32 %11, 3072
%13 = shl i32 %1, 3
%14 = and i32 %13, 1536
%15 = or i32 %10, %14
%16 = tail call i32 @readb_idx_reg(i32 981, i32 119)
%17 = shl i32 %16, 2
%18 = or i32 %17, %12
%19 = tail call i32 @readb_idx_reg(i32 981, i32 120)
%20 = shl i32 %19, 1
%21 = or i32 %15, %20
%22 = tail call i32 @readb_idx_reg(i32 981, i32 159)
%23 = and i32 %22, 3
%24 = or i32 %18, %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %21)
br label %28
26: ; preds = %0
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %4
ret void
}