#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 pcibios_read_config_byte(int /*<<< orphan*/, scalar_t__, int);
int /*<<< orphan*/ pcibios_write_config_byte(int /*<<< orphan*/, scalar_t__,
                                             int, int);
int /*<<< orphan*/ sdram_no_memory();
int smbus_read_byte(unsigned int, int);
void spd_enable_refresh(void) {
  int status;
  int byte;
  unsigned device;
  unsigned refresh_rate;
  byte = -1;
  status = -1;
  device = 0x50;
  while ((byte < 0) && (device <= 0x53)) {
    byte = smbus_read_byte(device, 12);
    device += 1;
  }
  if (byte < 0) {
    sdram_no_memory();
  }
  byte &= 0x7f;
  refresh_rate = 5;
  if (byte < 6) {
  }
  byte = pcibios_read_config_byte(0, ((0x00 << 3) + 0), 0x57);
  byte &= 0xf8;
  byte |= refresh_rate;
  pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x57, byte);
}


x86 assembly (clang, -O0):
<spd_enable_refresh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x50,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jge    1176 <spd_enable_refresh+0x36>
cmpl   $0x53,-0xc(%rbp)
setbe  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1186 <spd_enable_refresh+0x46>
jmp    11a4 <spd_enable_refresh+0x64>
mov    -0xc(%rbp),%edi
mov    $0xc,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <spd_enable_refresh+0x1d>
cmpl   $0x0,-0x8(%rbp)
jge    11b5 <spd_enable_refresh+0x75>
mov    $0x0,%al
call   1050 <sdram_no_memory@plt>
mov    -0x8(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x8(%rbp)
movl   $0x5,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
jge    11d4 <spd_enable_refresh+0x94>
jmp    11d4 <spd_enable_refresh+0x94>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x57,%edx
call   1060 <pcibios_read_config_byte@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x57,%edx
call   1030 <pcibios_write_config_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_enable_refresh>:
push   %rbx
mov    $0x50,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0xc,%esi
call   1040 <smbus_read_byte@plt>
test   %eax,%eax
jns    116a <spd_enable_refresh+0x2a>
lea    0x1(%rbx),%ecx
cmp    $0x53,%ebx
mov    %ecx,%ebx
jb     1150 <spd_enable_refresh+0x10>
test   %eax,%eax
jns    1175 <spd_enable_refresh+0x35>
xor    %eax,%eax
call   1050 <sdram_no_memory@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
call   1060 <pcibios_read_config_byte@plt>
and    $0xf8,%eax
lea    0x5(%rax),%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
pop    %rbx
jmp    1030 <pcibios_write_config_byte@plt>

LLVM IR (-O0):
define void @spd_enable_refresh() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 -1, i32* %2
store i32 -1, i32* %1
store i32 80, i32* %3
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp ule i32 %9, 83
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = load i32, i32* %3
%15 = call i32 @smbus_read_byte(i32 %14, i32 12)
store i32 %15, i32* %2
%16 = load i32, i32* %3
%17 = add i32 %16, 1
store i32 %17, i32* %3
br label %5
18: ; preds = %11
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (...) @sdram_no_memory()
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %2
%25 = and i32 %24, 127
store i32 %25, i32* %2
store i32 5, i32* %4
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %29
28: ; preds = %23
br label %29
29: ; preds = %28, %23
%30 = call i32 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = and i32 %31, 248
store i32 %32, i32* %2
%33 = load i32, i32* %4
%34 = load i32, i32* %2
%35 = or i32 %34, %33
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 87, i32 %36)
ret void
}

LLVM IR (-O2):
define void @spd_enable_refresh() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 80, %0 ], [ %4, %1 ]
%3 = tail call i32 @smbus_read_byte(i32 %2, i32 12)
%4 = add nuw nsw i32 %2, 1
%5 = icmp slt i32 %3, 0
%6 = icmp ult i32 %2, 83
%7 = and i1 %5, %6
br i1 %7, label %1, label %8
8: ; preds = %1
br i1 %5, label %9, label %11
9: ; preds = %8
%10 = tail call i32 (...) @sdram_no_memory()
br label %11
11: ; preds = %9, %8
%12 = tail call i32 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
%13 = and i32 %12, 248
%14 = or i32 %13, 5
%15 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 87, i32 %14)
ret void
}