#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 __builtin_bsr(int);
int /*<<< orphan*/ print_debug_hex8(unsigned int);
int smbus_read_byte(unsigned int, int);
void spd_set_memclk(void) {
  unsigned min_cycle_time, min_latency;
  unsigned device;
  unsigned value;
  value = 0x50;
  min_cycle_time = 0x75;
  min_latency = 2;
  device = 0;
  int new_cycle_time, new_latency;
  int index;
  int latencies;
  int latency;
  new_cycle_time = 0xa0;
  new_latency = 5;
  latencies = smbus_read_byte(device, 18);
  latency = __builtin_bsr(latencies) - 2;
  for (index = 0; index < 1; index++, latency++) {
    int value;
    if ((latency < 2) || (latency > 4) || (!(latencies & (1 << latency)))) {
      continue;
    }
    value = smbus_read_byte(device, index);
    if ((value >= min_cycle_time) && (value < new_cycle_time)) {
      new_cycle_time = value;
      new_latency = latency;
      print_debug_hex8(device);
    }
  }
}


x86 assembly (clang, -O0):
<spd_set_memclk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x50,-0x10(%rbp)
movl   $0x75,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xa0,-0x14(%rbp)
movl   $0x5,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x12,%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <__builtin_bsr@plt>
sub    $0x2,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    121a <spd_set_memclk+0xea>
cmpl   $0x2,-0x24(%rbp)
jl     11bf <spd_set_memclk+0x8f>
cmpl   $0x4,-0x24(%rbp)
jg     11bf <spd_set_memclk+0x8f>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    11c4 <spd_set_memclk+0x94>
jmp    1203 <spd_set_memclk+0xd3>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jb     11fe <spd_set_memclk+0xce>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fe <spd_set_memclk+0xce>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <print_debug_hex8@plt>
jmp    1203 <spd_set_memclk+0xd3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1187 <spd_set_memclk+0x57>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_memclk>:
push   %rbx
xor    %edi,%edi
mov    $0x12,%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <__builtin_bsr@plt>
lea    -0x7(%rax),%ecx
cmp    $0xfffffffd,%ecx
jb     1175 <spd_set_memclk+0x45>
add    $0xfe,%al
movzbl %al,%eax
bt     %eax,%ebx
jae    1175 <spd_set_memclk+0x45>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <smbus_read_byte@plt>
cmp    $0x75,%eax
jb     1175 <spd_set_memclk+0x45>
cmp    $0x9f,%eax
jg     1175 <spd_set_memclk+0x45>
xor    %edi,%edi
pop    %rbx
jmp    1030 <print_debug_hex8@plt>
pop    %rbx
ret

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 i32
%9 = alloca i32
%10 = alloca i32
store i32 80, i32* %4
store i32 117, i32* %1
store i32 2, i32* %2
store i32 0, i32* %3
store i32 160, i32* %5
store i32 5, i32* %6
%11 = load i32, i32* %3
%12 = call i32 @smbus_read_byte(i32 %11, i32 18)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = call i32 @__builtin_bsr(i32 %13)
%15 = sub nsw i32 %14, 2
store i32 %15, i32* %9
store i32 0, i32* %7
br label %16
16: ; preds = %49, %0
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %54
19: ; preds = %16
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 2
br i1 %21, label %31, label %22
22: ; preds = %19
%23 = load i32, i32* %9
%24 = icmp sgt i32 %23, 4
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = shl i32 1, %27
%29 = and i32 %26, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25, %22, %19
br label %49
32: ; preds = %25
%33 = load i32, i32* %3
%34 = load i32, i32* %7
%35 = call i32 @smbus_read_byte(i32 %33, i32 %34)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = load i32, i32* %1
%38 = icmp uge i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %32
%40 = load i32, i32* %10
%41 = load i32, i32* %5
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* %10
store i32 %44, i32* %5
%45 = load i32, i32* %9
store i32 %45, i32* %6
%46 = load i32, i32* %3
%47 = call i32 @print_debug_hex8(i32 %46)
br label %48
48: ; preds = %43, %39, %32
br label %49
49: ; preds = %48, %31
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %16
54: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @spd_set_memclk() {
%1 = tail call i32 @smbus_read_byte(i32 0, i32 18)
%2 = tail call i32 @__builtin_bsr(i32 %1)
%3 = add i32 %2, -7
%4 = icmp ult i32 %3, -3
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = add nsw i32 %2, -2
%7 = shl nuw nsw i32 1, %6
%8 = and i32 %7, %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = tail call i32 @smbus_read_byte(i32 0, i32 0)
%12 = icmp ugt i32 %11, 116
%13 = icmp slt i32 %11, 160
%14 = and i1 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @print_debug_hex8(i32 0)
br label %17
17: ; preds = %10, %15, %0, %5
ret void
}