#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) {
  static const unsigned char refresh_rates[] = {
      0x01, 0x05, 0x05, 0x02, 0x03, 0x04,
  };
  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) {
    refresh_rate = refresh_rates[byte];
  }
  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    11e1 <spd_enable_refresh+0xa1>
movslq -0x8(%rbp),%rcx
lea    0xe26(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x10(%rbp)
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   %rbp
push   %rbx
push   %rax
mov    $0x50,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0xc,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    116c <spd_enable_refresh+0x2c>
lea    0x1(%rbp),%eax
cmp    $0x53,%ebp
mov    %eax,%ebp
jb     1150 <spd_enable_refresh+0x10>
test   %ebx,%ebx
jns    1177 <spd_enable_refresh+0x37>
xor    %eax,%eax
call   1050 <sdram_no_memory@plt>
and    $0x7f,%ebx
mov    $0x5,%ebp
cmp    $0x5,%ebx
ja     118f <spd_enable_refresh+0x4f>
lea    0xe75(%rip),%rax
movzbl (%rbx,%rax,1),%ebp
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
call   1060 <pcibios_read_config_byte@plt>
and    $0xf8,%eax
or     %eax,%ebp
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <pcibios_write_config_byte@plt>

LLVM IR (-O0):
@spd_enable_refresh.refresh_rates = internal constant [6 x i8] c"\01\05\05\02\03\04"
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 %34
28: ; preds = %23
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [6 x i8], [6 x i8]* @spd_enable_refresh.refresh_rates, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
store i32 %33, i32* %4
br label %34
34: ; preds = %28, %23
%35 = call i32 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = and i32 %36, 248
store i32 %37, i32* %2
%38 = load i32, i32* %4
%39 = load i32, i32* %2
%40 = or i32 %39, %38
store i32 %40, i32* %2
%41 = load i32, i32* %2
%42 = call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 87, i32 %41)
ret void
}

LLVM IR (-O2):
@spd_enable_refresh.refresh_rates = internal unnamed_addr constant [6 x i8] c"\01\05\05\02\03\04"
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 = and i32 %3, 127
%13 = icmp ult i32 %12, 6
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = zext i32 %12 to i64
%16 = getelementptr inbounds [6 x i8], [6 x i8]* @spd_enable_refresh.refresh_rates, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
br label %19
19: ; preds = %14, %11
%20 = phi i32 [ %18, %14 ], [ 5, %11 ]
%21 = tail call i32 @pcibios_read_config_byte(i32 0, i64 0, i32 87)
%22 = and i32 %21, 248
%23 = or i32 %22, %20
%24 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 87, i32 %23)
ret void
}