#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 */

/* Variables and functions */
unsigned char pcibios_read_config_byte(int /*<<< orphan*/, scalar_t__, int);
int /*<<< orphan*/ pcibios_write_config_word(int /*<<< orphan*/, scalar_t__,
                                             int, unsigned int);
unsigned int smbus_read_byte(unsigned int, int);
void spd_set_rps(void) {
  unsigned page_sizes;
  unsigned index;
  unsigned device;
  unsigned char dramc;
  page_sizes = 0;
  index = 0;
  device = 0x50;
  for (; device <= 0x53; index += 4, device += 1) {
    unsigned int status;
    unsigned int byte;
    int page_size;
    byte = smbus_read_byte(device, 3);
    if (byte < 0)
      continue;
    page_size = byte & 0xf;
    page_size -= 11;
    if (page_size <= 0)
      continue;
    page_sizes |= (page_size << index);
    byte = smbus_read_byte(device, 5);
    if (byte <= 1)
      continue;
    page_sizes |= (page_size << (index + 2));
  }
  dramc = pcibios_read_config_byte(0, ((0x00 << 3) + 0), 0x57);
  if (dramc & 0x10) {
    page_sizes += 0x1111;
  }
  pcibios_write_config_word(0, ((0x00 << 3) + 0), 0x74, page_sizes);
}


x86 assembly (clang, -O0):
<spd_set_rps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x50,-0xc(%rbp)
cmpl   $0x53,-0xc(%rbp)
ja     11ec <spd_set_rps+0xbc>
mov    -0xc(%rbp),%edi
mov    $0x3,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jae    1176 <spd_set_rps+0x46>
jmp    11d5 <spd_set_rps+0xa5>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0xb,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1197 <spd_set_rps+0x67>
jmp    11d5 <spd_set_rps+0xa5>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
ja     11c4 <spd_set_rps+0x94>
jmp    11d5 <spd_set_rps+0xa5>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x2,%ecx
shl    %cl,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <spd_set_rps+0x1d>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x57,%edx
call   1050 <pcibios_read_config_byte@plt>
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     121a <spd_set_rps+0xea>
mov    -0x4(%rbp),%eax
add    $0x1111,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x74,%edx
call   1030 <pcibios_write_config_word@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_rps>:
push   %r14
push   %rbx
push   %rax
mov    $0x50,%edi
mov    $0x3,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
xor    %r14d,%r14d
cmp    $0xc,%ebx
jb     1177 <spd_set_rps+0x47>
add    $0xfffffff5,%ebx
mov    $0x50,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x2,%eax
jae    116c <spd_set_rps+0x3c>
mov    %ebx,%r14d
jmp    1177 <spd_set_rps+0x47>
lea    0x0(,%rbx,4),%r14d
or     %ebx,%r14d
mov    $0x51,%edi
mov    $0x3,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
cmp    $0xc,%ebx
jb     11b5 <spd_set_rps+0x85>
add    $0xfffffff5,%ebx
mov    %ebx,%eax
shl    $0x4,%eax
or     %eax,%r14d
mov    $0x51,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x2,%eax
jb     11b5 <spd_set_rps+0x85>
shl    $0x6,%ebx
or     %ebx,%r14d
mov    $0x52,%edi
mov    $0x3,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
cmp    $0xc,%ebx
jb     11f3 <spd_set_rps+0xc3>
add    $0xfffffff5,%ebx
mov    %ebx,%eax
shl    $0x8,%eax
or     %eax,%r14d
mov    $0x52,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x2,%eax
jb     11f3 <spd_set_rps+0xc3>
shl    $0xa,%ebx
or     %ebx,%r14d
mov    $0x53,%edi
mov    $0x3,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebx
and    $0xf,%ebx
cmp    $0xc,%ebx
jb     1231 <spd_set_rps+0x101>
add    $0xfffffff5,%ebx
mov    %ebx,%eax
shl    $0xc,%eax
or     %eax,%r14d
mov    $0x53,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x2,%eax
jb     1231 <spd_set_rps+0x101>
shl    $0xe,%ebx
or     %ebx,%r14d
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
call   1050 <pcibios_read_config_byte@plt>
lea    0x1111(%r14),%ecx
test   $0x10,%al
cmove  %r14d,%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x74,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <pcibios_write_config_word@plt>

LLVM IR (-O0):
define void @spd_set_rps() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 80, i32* %3
br label %8
8: ; preds = %43, %0
%9 = load i32, i32* %3
%10 = icmp ule i32 %9, 83
br i1 %10, label %11, label %48
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @smbus_read_byte(i32 %12, i32 3)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ult i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %43
17: ; preds = %11
%18 = load i32, i32* %6
%19 = and i32 %18, 15
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = sub nsw i32 %20, 11
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
br label %43
25: ; preds = %17
%26 = load i32, i32* %7
%27 = load i32, i32* %2
%28 = shl i32 %26, %27
%29 = load i32, i32* %1
%30 = or i32 %29, %28
store i32 %30, i32* %1
%31 = load i32, i32* %3
%32 = call i32 @smbus_read_byte(i32 %31, i32 5)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ule i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %25
br label %43
36: ; preds = %25
%37 = load i32, i32* %7
%38 = load i32, i32* %2
%39 = add i32 %38, 2
%40 = shl i32 %37, %39
%41 = load i32, i32* %1
%42 = or i32 %41, %40
store i32 %42, i32* %1
br label %43
43: ; preds = %36, %35, %24, %16
%44 = load i32, i32* %2
%45 = add i32 %44, 4
store i32 %45, i32* %2
%46 = load i32, i32* %3
%47 = add i32 %46, 1
store i32 %47, i32* %3
br label %8
48: ; preds = %8
%49 = call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
store i8 %49, i8* %4
%50 = load i8, i8* %4
%51 = zext i8 %50 to i32
%52 = and i32 %51, 16
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* %1
%56 = add i32 %55, 4369
store i32 %56, i32* %1
br label %57
57: ; preds = %54, %48
%58 = load i32, i32* %1
%59 = call i32 @pcibios_write_config_word(i32 0, i64 0, i32 116, i32 %58)
ret void
}

LLVM IR (-O2):
define void @spd_set_rps() {
%1 = tail call i32 @smbus_read_byte(i32 80, i32 3)
%2 = and i32 %1, 15
%3 = add nsw i32 %2, -11
%4 = icmp ult i32 %2, 12
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = tail call i32 @smbus_read_byte(i32 80, i32 5)
%7 = icmp ult i32 %6, 2
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = shl nuw nsw i32 %3, 2
%10 = or i32 %3, %9
br label %11
11: ; preds = %5, %0, %8
%12 = phi i32 [ %10, %8 ], [ 0, %0 ], [ %3, %5 ]
%13 = tail call i32 @smbus_read_byte(i32 81, i32 3)
%14 = and i32 %13, 15
%15 = add nsw i32 %14, -11
%16 = icmp ult i32 %14, 12
br i1 %16, label %25, label %17
17: ; preds = %11
%18 = shl nuw nsw i32 %15, 4
%19 = or i32 %18, %12
%20 = tail call i32 @smbus_read_byte(i32 81, i32 5)
%21 = icmp ult i32 %20, 2
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = shl nuw nsw i32 %15, 6
%24 = or i32 %19, %23
br label %25
25: ; preds = %22, %17, %11
%26 = phi i32 [ %24, %22 ], [ %12, %11 ], [ %19, %17 ]
%27 = tail call i32 @smbus_read_byte(i32 82, i32 3)
%28 = and i32 %27, 15
%29 = add nsw i32 %28, -11
%30 = icmp ult i32 %28, 12
br i1 %30, label %39, label %31
31: ; preds = %25
%32 = shl nuw nsw i32 %29, 8
%33 = or i32 %32, %26
%34 = tail call i32 @smbus_read_byte(i32 82, i32 5)
%35 = icmp ult i32 %34, 2
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = shl nuw nsw i32 %29, 10
%38 = or i32 %33, %37
br label %39
39: ; preds = %36, %31, %25
%40 = phi i32 [ %38, %36 ], [ %26, %25 ], [ %33, %31 ]
%41 = tail call i32 @smbus_read_byte(i32 83, i32 3)
%42 = and i32 %41, 15
%43 = add nsw i32 %42, -11
%44 = icmp ult i32 %42, 12
br i1 %44, label %53, label %45
45: ; preds = %39
%46 = shl nuw nsw i32 %43, 12
%47 = or i32 %46, %40
%48 = tail call i32 @smbus_read_byte(i32 83, i32 5)
%49 = icmp ult i32 %48, 2
br i1 %49, label %53, label %50
50: ; preds = %45
%51 = shl nuw nsw i32 %43, 14
%52 = or i32 %47, %51
br label %53
53: ; preds = %50, %45, %39
%54 = phi i32 [ %52, %50 ], [ %40, %39 ], [ %47, %45 ]
%55 = tail call zeroext i8 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
%56 = and i8 %55, 16
%57 = icmp eq i8 %56, 0
%58 = add i32 %54, 4369
%59 = select i1 %57, i32 %54, i32 %58
%60 = tail call i32 @pcibios_write_config_word(i32 0, i64 0, i32 116, i32 %59)
ret void
}