#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 long pci_read_config32(int);
int /*<<< orphan*/ pci_write_config32(int, unsigned long);
int /*<<< orphan*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex32(unsigned long);
void sdram_enable(void) {
  unsigned long dcl;
  dcl = pci_read_config32(((((0) & 0xFF) << 16) | (((0x18) & 0x1f) << 11) |
                           (((2) & 0x07) << 8) | ((0x90) & 0xFF)));
  print_debug("dcl: ");
  print_debug_hex32(dcl);
  print_debug("\r\n");
  dcl |= (1 << 3);
  pci_write_config32(((((0) & 0xFF) << 16) | (((0x18) & 0x1f) << 11) |
                      (((2) & 0x07) << 8) | ((0x90) & 0xFF)),
                     dcl);
  dcl &= ~(1 << 3);
  dcl &= ~(1 << 0);
  dcl &= ~(1 << 1);
  dcl &= ~(1 << 2);
  dcl |= (1 << 8);
  pci_write_config32(((((0) & 0xFF) << 16) | (((0x18) & 0x1f) << 11) |
                      (((2) & 0x07) << 8) | ((0x90) & 0xFF)),
                     dcl);
  print_debug("Initializing memory: ");
  int loops = 0;
  do {
    dcl = pci_read_config32(((((0) & 0xFF) << 16) | (((0x18) & 0x1f) << 11) |
                             (((2) & 0x07) << 8) | ((0x90) & 0xFF)));
    loops += 1;
    if ((loops & 1023) == 0) {
      print_debug(".");
    }
  } while (((dcl & (1 << 8)) != 0) && (loops < 300000));
  if (loops >= 300000) {
    print_debug(" failed\r\n");
  } else {
    print_debug(" done\r\n");
  }
}


x86 assembly (clang, -O0):
<sdram_enable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xc290,%edi
call   1030 <pci_read_config32@plt>
mov    %rax,-0x8(%rbp)
lea    0xea3(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x8(%rbp),%rdi
call   1050 <print_debug_hex32@plt>
lea    0xeb3(%rip),%rdi
call   1060 <print_debug@plt>
mov    -0x8(%rbp),%rax
or     $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0xc290,%edi
call   1040 <pci_write_config32@plt>
mov    -0x8(%rbp),%rax
and    $0xfffffffffffffff7,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xfffffffffffffffe,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xfffffffffffffffd,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0xfffffffffffffffb,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
or     $0x100,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0xc290,%edi
call   1040 <pci_write_config32@plt>
lea    0xe22(%rip),%rdi
call   1060 <print_debug@plt>
movl   $0x0,-0xc(%rbp)
mov    $0xc290,%edi
call   1030 <pci_read_config32@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3ff,%eax
cmp    $0x0,%eax
jne    1224 <sdram_enable+0xe4>
lea    0xdfd(%rip),%rdi
call   1060 <print_debug@plt>
jmp    1229 <sdram_enable+0xe9>
mov    -0x8(%rbp),%rcx
and    $0x100,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
je     1250 <sdram_enable+0x110>
cmpl   $0x493e0,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11f0 <sdram_enable+0xb0>
cmpl   $0x493e0,-0xc(%rbp)
jl     1279 <sdram_enable+0x139>
lea    0xdaf(%rip),%rdi
call   1060 <print_debug@plt>
jmp    1285 <sdram_enable+0x145>
lea    0xda8(%rip),%rdi
call   1060 <print_debug@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sdram_enable>:
push   %r15
push   %r14
push   %rbx
mov    $0xc290,%edi
call   1030 <pci_read_config32@plt>
mov    %rax,%rbx
lea    0xea7(%rip),%rdi
call   1060 <print_debug@plt>
mov    %rbx,%rdi
call   1050 <print_debug_hex32@plt>
lea    0xeb8(%rip),%rdi
call   1060 <print_debug@plt>
mov    %rbx,%rsi
or     $0x8,%rsi
mov    $0xc290,%edi
call   1040 <pci_write_config32@plt>
and    $0xfffffffffffffef0,%rbx
or     $0x100,%rbx
mov    $0xc290,%edi
mov    %rbx,%rsi
call   1040 <pci_write_config32@plt>
lea    0xe61(%rip),%rdi
call   1060 <print_debug@plt>
mov    $0xffffffff,%ebx
lea    0xe66(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    $0xc290,%edi
call   1030 <pci_read_config32@plt>
mov    %rax,%r15
lea    0x2(%rbx),%eax
test   $0x3ff,%eax
jne    11df <sdram_enable+0x9f>
mov    %r14,%rdi
call   1060 <print_debug@plt>
add    $0x1,%ebx
test   $0x100,%r15d
je     11f3 <sdram_enable+0xb3>
cmp    $0x493df,%ebx
jb     11c0 <sdram_enable+0x80>
cmp    $0x493df,%ebx
lea    0xe1e(%rip),%rax
lea    0xe21(%rip),%rdi
cmovae %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <print_debug@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"dcl: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [22 x i8] c"Initializing memory: \00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [10 x i8] c" failed\0D\0A\00"
@.str.5 = [8 x i8] c" done\0D\0A\00"
define void @sdram_enable() {
%1 = alloca i64
%2 = alloca i32
%3 = call i64 @pci_read_config32(i32 49808)
store i64 %3, i64* %1
%4 = call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = load i64, i64* %1
%6 = call i32 @print_debug_hex32(i64 %5)
%7 = call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = load i64, i64* %1
%9 = or i64 %8, 8
store i64 %9, i64* %1
%10 = load i64, i64* %1
%11 = call i32 @pci_write_config32(i32 49808, i64 %10)
%12 = load i64, i64* %1
%13 = and i64 %12, -9
store i64 %13, i64* %1
%14 = load i64, i64* %1
%15 = and i64 %14, -2
store i64 %15, i64* %1
%16 = load i64, i64* %1
%17 = and i64 %16, -3
store i64 %17, i64* %1
%18 = load i64, i64* %1
%19 = and i64 %18, -5
store i64 %19, i64* %1
%20 = load i64, i64* %1
%21 = or i64 %20, 256
store i64 %21, i64* %1
%22 = load i64, i64* %1
%23 = call i32 @pci_write_config32(i32 49808, i64 %22)
%24 = call i32 @print_debug(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %25
25: ; preds = %42, %0
%26 = call i64 @pci_read_config32(i32 49808)
store i64 %26, i64* %1
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = and i32 %29, 1023
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %25
br label %35
35: ; preds = %34
%36 = load i64, i64* %1
%37 = and i64 %36, 256
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %2
%41 = icmp slt i32 %40, 300000
br label %42
42: ; preds = %39, %35
%43 = phi i1 [ false, %35 ], [ %41, %39 ]
br i1 %43, label %25, label %44
44: ; preds = %42
%45 = load i32, i32* %2
%46 = icmp sge i32 %45, 300000
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @print_debug(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %51
49: ; preds = %44
%50 = call i32 @print_debug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"dcl: \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [22 x i8] c"Initializing memory: \00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [10 x i8] c" failed\0D\0A\00"
@.str.5 = [8 x i8] c" done\0D\0A\00"
define void @sdram_enable() {
%1 = tail call i64 @pci_read_config32(i32 49808)
%2 = tail call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @print_debug_hex32(i64 %1)
%4 = tail call i32 @print_debug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = or i64 %1, 8
%6 = tail call i32 @pci_write_config32(i32 49808, i64 %5)
%7 = and i64 %1, -272
%8 = or i64 %7, 256
%9 = tail call i32 @pci_write_config32(i32 49808, i64 %8)
%10 = tail call i32 @print_debug(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %19, %0
%12 = phi i32 [ 0, %0 ], [ %14, %19 ]
%13 = tail call i64 @pci_read_config32(i32 49808)
%14 = add nuw nsw i32 %12, 1
%15 = and i32 %14, 1023
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %11, %17
%20 = and i64 %13, 256
%21 = icmp ne i64 %20, 0
%22 = icmp ult i32 %12, 299999
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %11, label %24
24: ; preds = %19
%25 = icmp ugt i32 %12, 299998
%26 = select i1 %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0)
%27 = tail call i32 @print_debug(i8* %26)
ret void
}