#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_byte(int /*<<< orphan*/, scalar_t__,
                                             int, unsigned int);
int /*<<< orphan*/ sdram_no_memory();
int smbus_read_byte(unsigned int, int);
void spd_set_dramc(void) {
  unsigned device;
  int byte;
  unsigned dramc;
  byte = -1;
  device = 0x50;
  while ((byte < 0) && (device <= 0x53)) {
    byte = smbus_read_byte(device, 21);
    device += 1;
  }
  if (byte < 0) {
    sdram_no_memory();
  }
  dramc = 0x8;
  if ((byte & 0x12) != 0) {
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0xca, 0);
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0xcb, 0);
    pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0xcc, 0);
    dramc = 0x10;
  }
  pcibios_write_config_byte(0, ((0x00 << 3) + 0), 0x57, dramc);
}


x86 assembly (clang, -O0):
<spd_set_dramc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
movl   $0x50,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
jge    115f <spd_set_dramc+0x2f>
cmpl   $0x53,-0x4(%rbp)
setbe  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    116f <spd_set_dramc+0x3f>
jmp    118d <spd_set_dramc+0x5d>
mov    -0x4(%rbp),%edi
mov    $0x15,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <spd_set_dramc+0x16>
cmpl   $0x0,-0x8(%rbp)
jge    119e <spd_set_dramc+0x6e>
mov    $0x0,%al
call   1050 <sdram_no_memory@plt>
movl   $0x8,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x12,%eax
cmp    $0x0,%eax
je     11f1 <spd_set_dramc+0xc1>
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%esi
mov    $0xca,%edx
mov    %ecx,%edi
call   1030 <pcibios_write_config_byte@plt>
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%esi
mov    $0xcb,%edx
mov    %ecx,%edi
call   1030 <pcibios_write_config_byte@plt>
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%esi
mov    $0xcc,%edx
mov    %ecx,%edi
call   1030 <pcibios_write_config_byte@plt>
movl   $0x10,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x57,%edx
call   1030 <pcibios_write_config_byte@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_dramc>:
push   %rbp
push   %rbx
push   %rax
mov    $0x50,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    $0x15,%esi
call   1040 <smbus_read_byte@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    115c <spd_set_dramc+0x2c>
lea    0x1(%rbx),%eax
cmp    $0x53,%ebx
mov    %eax,%ebx
jb     1140 <spd_set_dramc+0x10>
test   %ebp,%ebp
js     119d <spd_set_dramc+0x6d>
test   $0x12,%bpl
je     11aa <spd_set_dramc+0x7a>
xor    %edi,%edi
xor    %esi,%esi
mov    $0xca,%edx
xor    %ecx,%ecx
call   1030 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0xcb,%edx
xor    %ecx,%ecx
call   1030 <pcibios_write_config_byte@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0xcc,%edx
xor    %ecx,%ecx
call   1030 <pcibios_write_config_byte@plt>
mov    $0x10,%ecx
jmp    11af <spd_set_dramc+0x7f>
xor    %eax,%eax
call   1050 <sdram_no_memory@plt>
test   $0x12,%bpl
jne    1166 <spd_set_dramc+0x36>
mov    $0x8,%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x57,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <pcibios_write_config_byte@plt>

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

LLVM IR (-O2):
define void @spd_set_dramc() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 80, %0 ], [ %4, %1 ]
%3 = tail call i32 @smbus_read_byte(i32 %2, i32 21)
%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, 18
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 202, i32 0)
%16 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 203, i32 0)
%17 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 204, i32 0)
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ 16, %14 ], [ 8, %11 ]
%20 = tail call i32 @pcibios_write_config_byte(i32 0, i64 0, i32 87, i32 %19)
ret void
}