#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 long, int);
void spd_set_memclk(void) {
  static const int indicies[] = {26, 23, 9};
  int new_cycle_time, new_latency;
  int index;
  unsigned min_cycle_time, min_latency;
  unsigned device;
  min_cycle_time = 0x50;
  min_latency = 2;
  device = 0x50;
  new_cycle_time = 0xa0;
  new_latency = 5;
  for (index = 0; index < 3; index++) {
    unsigned long loops;
    unsigned long address;
    address = indicies[index];
    loops = 1000000;
    do {
    } while (--loops);
    if (loops < 0) {
      continue;
    }
    __builtin_outb(device, 0x10e4);
    __builtin_outb(address, 0x10e8);
    loops = 1000000;
    if ((loops ? 0 : -1) < 0) {
      continue;
    }
  }
  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,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
movl   $0x50,-0x18(%rbp)
movl   $0xa0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11ea <spd_set_memclk+0xda>
movslq -0xc(%rbp),%rcx
lea    0xea9(%rip),%rax
movslq (%rax,%rcx,4),%rax
mov    %rax,-0x28(%rbp)
movq   $0xf4240,-0x20(%rbp)
jmp    116c <spd_set_memclk+0x5c>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1167 <spd_set_memclk+0x57>
cmpq   $0x0,-0x20(%rbp)
jae    1192 <spd_set_memclk+0x82>
jmp    11dc <spd_set_memclk+0xcc>
mov    -0x18(%rbp),%eax
mov    %eax,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    -0x28(%rbp),%rdi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
movq   $0xf4240,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
cmp    $0x0,%eax
jge    11d7 <spd_set_memclk+0xc7>
jmp    11dc <spd_set_memclk+0xcc>
jmp    11dc <spd_set_memclk+0xcc>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1142 <spd_set_memclk+0x32>
mov    -0x4(%rbp),%eax
cmp    -0x10(%rbp),%eax
jbe    11fc <spd_set_memclk+0xec>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    120e <spd_set_memclk+0xfe>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%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>
mov    $0x1a,%edi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
mov    $0x50,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    $0x17,%edi
mov    $0x10e8,%esi
call   1030 <__builtin_outb@plt>
mov    $0x50,%edi
mov    $0x10e4,%esi
call   1030 <__builtin_outb@plt>
mov    $0x9,%edi
mov    $0x10e8,%esi
pop    %rax
jmp    1030 <__builtin_outb@plt>

LLVM IR (-O0):
@spd_set_memclk.indicies = internal constant [3 x i32] [i32 26, i32 23, i32 9]
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 i64
%8 = alloca i64
store i32 80, i32* %4
store i32 2, i32* %5
store i32 80, i32* %6
store i32 160, i32* %1
store i32 5, i32* %2
store i32 0, i32* %3
br label %9
9: ; preds = %40, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %43
12: ; preds = %9
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [3 x i32], [3 x i32]* @spd_set_memclk.indicies, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
store i64 %17, i64* %8
store i64 1000000, i64* %7
br label %18
18: ; preds = %19, %12
br label %19
19: ; preds = %18
%20 = load i64, i64* %7
%21 = add i64 %20, -1
store i64 %21, i64* %7
%22 = icmp ne i64 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %19
%24 = load i64, i64* %7
%25 = icmp ult i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
br label %40
27: ; preds = %23
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = call i32 @__builtin_outb(i64 %29, i32 4324)
%31 = load i64, i64* %8
%32 = call i32 @__builtin_outb(i64 %31, i32 4328)
store i64 1000000, i64* %7
%33 = load i64, i64* %7
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 -1
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %27
br label %40
39: ; preds = %27
br label %40
40: ; preds = %39, %38, %26
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %9
43: ; preds = %9
%44 = load i32, i32* %1
%45 = load i32, i32* %4
%46 = icmp ugt i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i32, i32* %1
store i32 %48, i32* %4
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* %2
%51 = load i32, i32* %5
%52 = icmp ugt i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i32, i32* %2
store i32 %54, i32* %5
br label %55
55: ; preds = %53, %49
ret void
}

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