#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 */
int /*<<< orphan*/ pcibios_write_config_word(int /*<<< orphan*/, scalar_t__,
                                             int, unsigned int);
int smbus_read_byte(unsigned int, int);
void spd_set_pgpol(void) {
  unsigned device;
  unsigned bank_sizes;
  unsigned bank;
  unsigned reg;
  bank_sizes = 0;
  bank = 0;
  device = 0x50;
  for (; device <= 0x53; bank += 2, device += 1) {
    int byte;
    byte = smbus_read_byte(device, 17);
    if (byte < 0)
      continue;
    if (byte < 4)
      continue;
    bank_sizes |= (1 << bank);
    byte = smbus_read_byte(device, 5);
    if (byte <= 1)
      continue;
    bank_sizes |= (1 << (bank + 1));
  }
  reg = bank_sizes << 8;
  reg |= 0x7;
  pcibios_write_config_word(0, ((0x00 << 3) + 0), 0x78, reg);
}


x86 assembly (clang, -O0):
<spd_set_pgpol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x50,-0x4(%rbp)
cmpl   $0x53,-0x4(%rbp)
ja     11ce <spd_set_pgpol+0xae>
mov    -0x4(%rbp),%edi
mov    $0x11,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1166 <spd_set_pgpol+0x46>
jmp    11b7 <spd_set_pgpol+0x97>
cmpl   $0x4,-0x14(%rbp)
jge    1175 <spd_set_pgpol+0x55>
jmp    11b7 <spd_set_pgpol+0x97>
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     11a4 <spd_set_pgpol+0x84>
jmp    11b7 <spd_set_pgpol+0x97>
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    113d <spd_set_pgpol+0x1d>
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
or     $0x7,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x78,%edx
call   1030 <pcibios_write_config_word@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_pgpol>:
push   %rbx
mov    $0x50,%edi
mov    $0x11,%esi
call   1040 <smbus_read_byte@plt>
xor    %ebx,%ebx
cmp    $0x4,%eax
jl     1154 <spd_set_pgpol+0x34>
mov    $0x50,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
lea    (%rcx,%rcx,1),%ebx
add    $0x1,%ebx
mov    $0x51,%edi
mov    $0x11,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x4,%eax
jl     1185 <spd_set_pgpol+0x65>
mov    $0x51,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
lea    (%rbx,%rcx,8),%ebx
add    $0x4,%ebx
mov    $0x52,%edi
mov    $0x11,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x4,%eax
jl     11b8 <spd_set_pgpol+0x98>
mov    $0x52,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
shl    $0x5,%ecx
add    %ecx,%ebx
add    $0x10,%ebx
mov    $0x53,%edi
mov    $0x11,%esi
call   1040 <smbus_read_byte@plt>
cmp    $0x4,%eax
jl     11eb <spd_set_pgpol+0xcb>
mov    $0x53,%edi
mov    $0x5,%esi
call   1040 <smbus_read_byte@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
shl    $0x7,%ecx
add    %ecx,%ebx
add    $0x40,%ebx
shl    $0x8,%ebx
or     $0x7,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x78,%edx
mov    %ebx,%ecx
pop    %rbx
jmp    1030 <pcibios_write_config_word@plt>

LLVM IR (-O0):
define void @spd_set_pgpol() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
store i32 80, i32* %1
br label %6
6: ; preds = %35, %0
%7 = load i32, i32* %1
%8 = icmp ule i32 %7, 83
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i32, i32* %1
%11 = call i32 @smbus_read_byte(i32 %10, i32 17)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br label %35
15: ; preds = %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %15
br label %35
19: ; preds = %15
%20 = load i32, i32* %3
%21 = shl i32 1, %20
%22 = load i32, i32* %2
%23 = or i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %1
%25 = call i32 @smbus_read_byte(i32 %24, i32 5)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp sle i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %19
br label %35
29: ; preds = %19
%30 = load i32, i32* %3
%31 = add i32 %30, 1
%32 = shl i32 1, %31
%33 = load i32, i32* %2
%34 = or i32 %33, %32
store i32 %34, i32* %2
br label %35
35: ; preds = %29, %28, %18, %14
%36 = load i32, i32* %3
%37 = add i32 %36, 2
store i32 %37, i32* %3
%38 = load i32, i32* %1
%39 = add i32 %38, 1
store i32 %39, i32* %1
br label %6
40: ; preds = %6
%41 = load i32, i32* %2
%42 = shl i32 %41, 8
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = or i32 %43, 7
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = call i32 @pcibios_write_config_word(i32 0, i64 0, i32 120, i32 %45)
ret void
}

LLVM IR (-O2):
define void @spd_set_pgpol() {
%1 = tail call i32 @smbus_read_byte(i32 80, i32 17)
%2 = icmp slt i32 %1, 4
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i32 @smbus_read_byte(i32 80, i32 5)
%5 = icmp sgt i32 %4, 1
%6 = select i1 %5, i32 3, i32 1
br label %7
7: ; preds = %3, %0
%8 = phi i32 [ 0, %0 ], [ %6, %3 ]
%9 = tail call i32 @smbus_read_byte(i32 81, i32 17)
%10 = icmp slt i32 %9, 4
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i32 @smbus_read_byte(i32 81, i32 5)
%13 = icmp slt i32 %12, 2
%14 = select i1 %13, i32 4, i32 12
%15 = or i32 %8, %14
br label %16
16: ; preds = %11, %7
%17 = phi i32 [ %8, %7 ], [ %15, %11 ]
%18 = tail call i32 @smbus_read_byte(i32 82, i32 17)
%19 = icmp slt i32 %18, 4
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = tail call i32 @smbus_read_byte(i32 82, i32 5)
%22 = icmp slt i32 %21, 2
%23 = select i1 %22, i32 16, i32 48
%24 = or i32 %17, %23
br label %25
25: ; preds = %20, %16
%26 = phi i32 [ %17, %16 ], [ %24, %20 ]
%27 = tail call i32 @smbus_read_byte(i32 83, i32 17)
%28 = icmp slt i32 %27, 4
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = tail call i32 @smbus_read_byte(i32 83, i32 5)
%31 = icmp slt i32 %30, 2
%32 = select i1 %31, i32 64, i32 192
%33 = or i32 %26, %32
br label %34
34: ; preds = %29, %25
%35 = phi i32 [ %26, %25 ], [ %33, %29 ]
%36 = shl i32 %35, 8
%37 = or i32 %36, 7
%38 = tail call i32 @pcibios_write_config_word(i32 0, i64 0, i32 120, i32 %37)
ret void
}