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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *, int, unsigned long);
int readb_idx_reg(int, int);
void dump_sl(const char *pfx) {
  u_int8_t val;
  unsigned int sl_size_mb;
  unsigned long rtsf_in_sl_addr;
  u_int64_t sl_in_mem_addr;
  val = readb_idx_reg(0x3c5, 0x68);
  switch (val) {
  case 0:
    sl_size_mb = 512;
    break;
  case 0x80:
    sl_size_mb = 256;
    break;
  case 0xc0:
    sl_size_mb = 128;
    break;
  case 0xe0:
    sl_size_mb = 64;
    break;
  case 0xf0:
    sl_size_mb = 32;
    break;
  case 0xf8:
    sl_size_mb = 16;
    break;
  case 0xfc:
    sl_size_mb = 8;
    break;
  case 0xfe:
    sl_size_mb = 4;
    break;
  case 0xff:
    sl_size_mb = 2;
    break;
  }
  rtsf_in_sl_addr = readb_idx_reg(0x3c5, 0x6a) << 12;
  rtsf_in_sl_addr |= readb_idx_reg(0x3c5, 0x6b) << 20;
  val = readb_idx_reg(0x3c5, 0x6c);
  rtsf_in_sl_addr |= (val & 0x1) << 28;
  sl_in_mem_addr = readb_idx_reg(0x3c5, 0x6d) << 21;
  sl_in_mem_addr |= readb_idx_reg(0x3c5, 0x6d) << 29;
  sl_in_mem_addr |= (readb_idx_reg(0x3c5, 0x6d) & 0x7f) << 37;
  printf("%sSL in System memory: 0x%llx, RTSF in SL: 0x%lx\n", pfx,
         sl_in_mem_addr, rtsf_in_sl_addr);
}


x86 assembly (clang, -O0):
<dump_sl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3c5,%edi
mov    $0x68,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11e9 <dump_sl+0xc9>
jmp    1151 <dump_sl+0x31>
mov    -0x20(%rbp),%eax
sub    $0x80,%eax
je     11f5 <dump_sl+0xd5>
jmp    1164 <dump_sl+0x44>
mov    -0x20(%rbp),%eax
sub    $0xc0,%eax
je     1201 <dump_sl+0xe1>
jmp    1177 <dump_sl+0x57>
mov    -0x20(%rbp),%eax
sub    $0xe0,%eax
je     120d <dump_sl+0xed>
jmp    118a <dump_sl+0x6a>
mov    -0x20(%rbp),%eax
sub    $0xf0,%eax
je     1219 <dump_sl+0xf9>
jmp    119d <dump_sl+0x7d>
mov    -0x20(%rbp),%eax
sub    $0xf8,%eax
je     1225 <dump_sl+0x105>
jmp    11b0 <dump_sl+0x90>
mov    -0x20(%rbp),%eax
sub    $0xfc,%eax
je     1231 <dump_sl+0x111>
jmp    11c3 <dump_sl+0xa3>
mov    -0x20(%rbp),%eax
sub    $0xfe,%eax
je     123d <dump_sl+0x11d>
jmp    11d6 <dump_sl+0xb6>
mov    -0x20(%rbp),%eax
sub    $0xff,%eax
je     1249 <dump_sl+0x129>
jmp    1250 <dump_sl+0x130>
movl   $0x200,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x100,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x80,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x40,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x20,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x10,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x8,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x4,-0x10(%rbp)
jmp    1250 <dump_sl+0x130>
movl   $0x2,-0x10(%rbp)
mov    $0x3c5,%edi
mov    $0x6a,%esi
call   1040 <readb_idx_reg@plt>
shl    $0xc,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    $0x3c5,%edi
mov    $0x6b,%esi
call   1040 <readb_idx_reg@plt>
shl    $0x14,%eax
cltq
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x3c5,%edi
mov    $0x6c,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
shl    $0x1c,%eax
cltq
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
shl    $0x15,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
shl    $0x1d,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
and    $0x7f,%eax
mov    $0x25,%ecx
shl    %cl,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xcf9(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_sl>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3c5,%edi
mov    $0x68,%esi
call   1040 <readb_idx_reg@plt>
mov    $0x3c5,%edi
mov    $0x6a,%esi
call   1040 <readb_idx_reg@plt>
mov    %eax,%ebx
shl    $0xc,%ebx
mov    $0x3c5,%edi
mov    $0x6b,%esi
call   1040 <readb_idx_reg@plt>
shl    $0x14,%eax
or     %ebx,%eax
movslq %eax,%rbx
mov    $0x3c5,%edi
mov    $0x6c,%esi
call   1040 <readb_idx_reg@plt>
and    $0x1,%eax
shl    $0x1c,%eax
or     %rax,%rbx
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
mov    $0x3c5,%edi
mov    $0x6d,%esi
call   1040 <readb_idx_reg@plt>
lea    0xe53(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"%sSL in System memory: 0x%llx, RTSF in SL: 0x%lx\0A\00"
define void @dump_sl(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 @readb_idx_reg(i32 965, i32 104)
store i32 %7, i32* %3
%8 = load i32, i32* %3
switch i32 %8, label %18 [
i32 0, label %9
i32 128, label %10
i32 192, label %11
i32 224, label %12
i32 240, label %13
i32 248, label %14
i32 252, label %15
i32 254, label %16
i32 255, label %17
]
9: ; preds = %1
store i32 512, i32* %4
br label %18
10: ; preds = %1
store i32 256, i32* %4
br label %18
11: ; preds = %1
store i32 128, i32* %4
br label %18
12: ; preds = %1
store i32 64, i32* %4
br label %18
13: ; preds = %1
store i32 32, i32* %4
br label %18
14: ; preds = %1
store i32 16, i32* %4
br label %18
15: ; preds = %1
store i32 8, i32* %4
br label %18
16: ; preds = %1
store i32 4, i32* %4
br label %18
17: ; preds = %1
store i32 2, i32* %4
br label %18
18: ; preds = %1, %17, %16, %15, %14, %13, %12, %11, %10, %9
%19 = call i32 @readb_idx_reg(i32 965, i32 106)
%20 = shl i32 %19, 12
%21 = sext i32 %20 to i64
store i64 %21, i64* %5
%22 = call i32 @readb_idx_reg(i32 965, i32 107)
%23 = shl i32 %22, 20
%24 = sext i32 %23 to i64
%25 = load i64, i64* %5
%26 = or i64 %25, %24
store i64 %26, i64* %5
%27 = call i32 @readb_idx_reg(i32 965, i32 108)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = and i32 %28, 1
%30 = shl i32 %29, 28
%31 = sext i32 %30 to i64
%32 = load i64, i64* %5
%33 = or i64 %32, %31
store i64 %33, i64* %5
%34 = call i32 @readb_idx_reg(i32 965, i32 109)
%35 = shl i32 %34, 21
store i32 %35, i32* %6
%36 = call i32 @readb_idx_reg(i32 965, i32 109)
%37 = shl i32 %36, 29
%38 = load i32, i32* %6
%39 = or i32 %38, %37
store i32 %39, i32* %6
%40 = call i32 @readb_idx_reg(i32 965, i32 109)
%41 = and i32 %40, 127
%42 = shl i32 %41, 37
%43 = load i32, i32* %6
%44 = or i32 %43, %42
store i32 %44, i32* %6
%45 = load i8*, i8** %2
%46 = load i32, i32* %6
%47 = load i64, i64* %5
%48 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %45, i32 %46, i64 %47)
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"%sSL in System memory: 0x%llx, RTSF in SL: 0x%lx\0A\00"
define void @dump_sl(i8* %0) {
%2 = tail call i32 @readb_idx_reg(i32 965, i32 104)
%3 = tail call i32 @readb_idx_reg(i32 965, i32 106)
%4 = shl i32 %3, 12
%5 = tail call i32 @readb_idx_reg(i32 965, i32 107)
%6 = shl i32 %5, 20
%7 = or i32 %6, %4
%8 = sext i32 %7 to i64
%9 = tail call i32 @readb_idx_reg(i32 965, i32 108)
%10 = shl i32 %9, 28
%11 = and i32 %10, 268435456
%12 = zext i32 %11 to i64
%13 = or i64 %12, %8
%14 = tail call i32 @readb_idx_reg(i32 965, i32 109)
%15 = tail call i32 @readb_idx_reg(i32 965, i32 109)
%16 = tail call i32 @readb_idx_reg(i32 965, i32 109)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %0, i32 poison, i64 %13)
ret void
}