#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*/ __builtin_outb(unsigned int, int);
void spd_set_memclk(void) {
  unsigned min_cycle_time, min_latency;
  unsigned device;
  int new_cycle_time, new_latency;
  int index;
  int latency;
  min_cycle_time = 0x50;
  min_latency = 2;
  device = 0x50;
  new_latency = 5;
  new_cycle_time = 0xa0;
  latency = 23;
  for (index = 0; index < 3; index++, latency++) {
    unsigned long loops;
    unsigned address = index;
    loops = 1000000;
    do {
    } while (--loops);
    if (loops) {
      continue;
    }
    __builtin_outb(device, 0x10e4);
    __builtin_outb(address & 0xFF, 0x10e8);
    loops = 1000000;
    while (--loops)
      ;
  }
  if (new_cycle_time > min_cycle_time) {
    min_cycle_time = new_cycle_time;
  }
  if (new_latency > min_latency) {
    min_latency = new_latency;
  }
}


x86 assembly (clang, -O0):
<spd_set_memclk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x50,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x50,-0xc(%rbp)
movl   $0x5,-0x14(%rbp)
movl   $0xa0,-0x10(%rbp)
movl   $0x17,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11eb <spd_set_memclk+0xdb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movq   $0xf4240,-0x28(%rbp)
jmp    1166 <spd_set_memclk+0x56>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1161 <spd_set_memclk+0x51>
cmpq   $0x0,-0x28(%rbp)
je     118c <spd_set_memclk+0x7c>
jmp    11d4 <spd_set_memclk+0xc4>
mov    -0xc(%rbp),%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    -0x2c(%rbp),%edi
and    $0xff,%edi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
movq   $0xf4240,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11cf <spd_set_memclk+0xbf>
jmp    11b4 <spd_set_memclk+0xa4>
jmp    11d4 <spd_set_memclk+0xc4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <spd_set_memclk+0x39>
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jbe    11fd <spd_set_memclk+0xed>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    120f <spd_set_memclk+0xff>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_memclk>:
push   %rax
mov    $0x50,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
xor    %edi,%edi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
mov    $0x50,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    $0x1,%edi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
mov    $0x50,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    $0x2,%edi
mov    $0x10e8,%esi
pop    %rax
jmp    1030 <__builtin_outb@plt>

LLVM IR (-O0):
define void @spd_set_memclk() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
store i32 80, i32* %1
store i32 2, i32* %2
store i32 80, i32* %3
store i32 5, i32* %5
store i32 160, i32* %4
store i32 23, i32* %7
store i32 0, i32* %6
br label %10
10: ; preds = %36, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %41
13: ; preds = %10
%14 = load i32, i32* %6
store i32 %14, i32* %9
store i64 1000000, i64* %8
br label %15
15: ; preds = %16, %13
br label %16
16: ; preds = %15
%17 = load i64, i64* %8
%18 = add i64 %17, -1
store i64 %18, i64* %8
%19 = icmp ne i64 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %16
%21 = load i64, i64* %8
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %36
24: ; preds = %20
%25 = load i32, i32* %3
%26 = call i32 @__builtin_outb(i32 %25, i32 4324)
%27 = load i32, i32* %9
%28 = and i32 %27, 255
%29 = call i32 @__builtin_outb(i32 %28, i32 4328)
store i64 1000000, i64* %8
br label %30
30: ; preds = %34, %24
%31 = load i64, i64* %8
%32 = add i64 %31, -1
store i64 %32, i64* %8
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %30
35: ; preds = %30
br label %36
36: ; preds = %35, %23
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %10
41: ; preds = %10
%42 = load i32, i32* %4
%43 = load i32, i32* %1
%44 = icmp ugt i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i32, i32* %4
store i32 %46, i32* %1
br label %47
47: ; preds = %45, %41
%48 = load i32, i32* %5
%49 = load i32, i32* %2
%50 = icmp ugt i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i32, i32* %5
store i32 %52, i32* %2
br label %53
53: ; preds = %51, %47
ret void
}

LLVM IR (-O2):
define void @spd_set_memclk() {
%1 = tail call i32 @__builtin_outb(i32 80, i32 4324)
%2 = tail call i32 @__builtin_outb(i32 0, i32 4328)
%3 = tail call i32 @__builtin_outb(i32 80, i32 4324)
%4 = tail call i32 @__builtin_outb(i32 1, i32 4328)
%5 = tail call i32 @__builtin_outb(i32 80, i32 4324)
%6 = tail call i32 @__builtin_outb(i32 2, i32 4328)
ret void
}