#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*/ console_tx_byte(unsigned int);
int /*<<< orphan*/ console_tx_string(char *);
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;
  for (device = 0x00; device <= 0x00; device += 1) {
    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 < 3; index++, latency++) {
      int value;
      if ((latency < 2) || (latency > 4) || (!(latencies & (1 << latency)))) {
        continue;
      }
      value = smbus_read_byte(device, index);
      if (value < 0)
        continue;
      if ((value >= min_cycle_time) && (value < new_cycle_time)) {
        new_cycle_time = value;
        new_latency = latency;
        console_tx_byte(device);
      }
    }
    console_tx_string("Transmitting this string causes problems\n");
    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   $0x75,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
ja     128d <spd_set_memclk+0x14d>
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   $0x3,-0x1c(%rbp)
jge    124a <spd_set_memclk+0x10a>
cmpl   $0x2,-0x24(%rbp)
jl     11e0 <spd_set_memclk+0xa0>
cmpl   $0x4,-0x24(%rbp)
jg     11e0 <spd_set_memclk+0xa0>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    11e5 <spd_set_memclk+0xa5>
jmp    1233 <spd_set_memclk+0xf3>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1202 <spd_set_memclk+0xc2>
jmp    1233 <spd_set_memclk+0xf3>
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jb     122e <spd_set_memclk+0xee>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    122e <spd_set_memclk+0xee>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <console_tx_byte@plt>
jmp    1233 <spd_set_memclk+0xf3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a8 <spd_set_memclk+0x68>
lea    0xdaf(%rip),%rdi
call   1030 <console_tx_string@plt>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jbe    1268 <spd_set_memclk+0x128>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    127a <spd_set_memclk+0x13a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    127f <spd_set_memclk+0x13f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <spd_set_memclk+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_set_memclk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
mov    $0x12,%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <__builtin_bsr@plt>
mov    %eax,%ebx
lea    -0x7(%rbx),%eax
mov    $0xa0,%r15d
cmp    $0xfffffffd,%eax
jb     1196 <spd_set_memclk+0x56>
lea    -0x2(%rbx),%eax
movzbl %al,%eax
bt     %eax,%ebp
jae    1196 <spd_set_memclk+0x56>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <smbus_read_byte@plt>
mov    %eax,%r14d
lea    -0x75(%r14),%eax
cmp    $0x2a,%eax
ja     1196 <spd_set_memclk+0x56>
xor    %edi,%edi
call   1060 <console_tx_byte@plt>
mov    %r14d,%r15d
lea    -0x6(%rbx),%eax
cmp    $0xfffffffd,%eax
jb     11d0 <spd_set_memclk+0x90>
lea    -0x1(%rbx),%eax
movzbl %al,%eax
bt     %eax,%ebp
jae    11d0 <spd_set_memclk+0x90>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <smbus_read_byte@plt>
test   %eax,%eax
js     11d0 <spd_set_memclk+0x90>
mov    %eax,%r14d
cmp    $0x75,%eax
jb     11d0 <spd_set_memclk+0x90>
cmp    %r15d,%r14d
jae    11d0 <spd_set_memclk+0x90>
xor    %edi,%edi
call   1060 <console_tx_byte@plt>
mov    %r14d,%r15d
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
jb     11fe <spd_set_memclk+0xbe>
bt     %ebx,%ebp
jae    11fe <spd_set_memclk+0xbe>
xor    %edi,%edi
mov    $0x2,%esi
call   1050 <smbus_read_byte@plt>
test   %eax,%eax
js     11fe <spd_set_memclk+0xbe>
cmp    $0x75,%eax
jb     11fe <spd_set_memclk+0xbe>
cmp    %r15d,%eax
jae    11fe <spd_set_memclk+0xbe>
xor    %edi,%edi
call   1060 <console_tx_byte@plt>
lea    0xdfb(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <console_tx_string@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Transmitting this string causes problems\0A\00"
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 0, i32* %3
br label %11
11: ; preds = %76, %0
%12 = load i32, i32* %3
%13 = icmp ule i32 %12, 0
br i1 %13, label %14, label %79
14: ; preds = %11
store i32 160, i32* %5
store i32 5, i32* %6
%15 = load i32, i32* %3
%16 = call i32 @smbus_read_byte(i32 %15, i32 18)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = call i32 @__builtin_bsr(i32 %17)
%19 = sub nsw i32 %18, 2
store i32 %19, i32* %9
store i32 0, i32* %7
br label %20
20: ; preds = %57, %14
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %62
23: ; preds = %20
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 2
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = load i32, i32* %9
%28 = icmp sgt i32 %27, 4
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = shl i32 1, %31
%33 = and i32 %30, %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %29, %26, %23
br label %57
36: ; preds = %29
%37 = load i32, i32* %3
%38 = load i32, i32* %7
%39 = call i32 @smbus_read_byte(i32 %37, i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
br label %57
43: ; preds = %36
%44 = load i32, i32* %10
%45 = load i32, i32* %1
%46 = icmp uge i32 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = load i32, i32* %10
%49 = load i32, i32* %5
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i32, i32* %10
store i32 %52, i32* %5
%53 = load i32, i32* %9
store i32 %53, i32* %6
%54 = load i32, i32* %3
%55 = call i32 @console_tx_byte(i32 %54)
br label %56
56: ; preds = %51, %47, %43
br label %57
57: ; preds = %56, %42, %35
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %20
62: ; preds = %20
%63 = call i32 @console_tx_string(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%64 = load i32, i32* %5
%65 = load i32, i32* %1
%66 = icmp ugt i32 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = load i32, i32* %5
store i32 %68, i32* %1
br label %69
69: ; preds = %67, %62
%70 = load i32, i32* %6
%71 = load i32, i32* %2
%72 = icmp ugt i32 %70, %71
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = load i32, i32* %6
store i32 %74, i32* %2
br label %75
75: ; preds = %73, %69
br label %76
76: ; preds = %75
%77 = load i32, i32* %3
%78 = add i32 %77, 1
store i32 %78, i32* %3
br label %11
79: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"Transmitting this string causes problems\0A\00"
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 %16, 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 %16, label %10
10: ; preds = %5
%11 = tail call i32 @smbus_read_byte(i32 0, i32 0)
%12 = add i32 %11, -117
%13 = icmp ult i32 %12, 43
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @console_tx_byte(i32 0)
br label %16
16: ; preds = %14, %10, %0, %5
%17 = phi i32 [ 160, %5 ], [ 160, %0 ], [ 160, %10 ], [ %11, %14 ]
%18 = add i32 %2, -6
%19 = icmp ult i32 %18, -3
br i1 %19, label %34, label %20
20: ; preds = %16
%21 = add nsw i32 %2, -1
%22 = shl nuw nsw i32 1, %21
%23 = and i32 %22, %1
%24 = icmp eq i32 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %20
%26 = tail call i32 @smbus_read_byte(i32 0, i32 1)
%27 = icmp slt i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = icmp ugt i32 %26, 116
%30 = icmp ult i32 %26, %17
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @console_tx_byte(i32 0)
br label %34
34: ; preds = %32, %28, %25, %20, %16
%35 = phi i32 [ %17, %20 ], [ %17, %16 ], [ %17, %25 ], [ %26, %32 ], [ %17, %28 ]
%36 = add i32 %2, -5
%37 = icmp ult i32 %36, -3
br i1 %37, label %51, label %38
38: ; preds = %34
%39 = shl nuw nsw i32 1, %2
%40 = and i32 %39, %1
%41 = icmp eq i32 %40, 0
br i1 %41, label %51, label %42
42: ; preds = %38
%43 = tail call i32 @smbus_read_byte(i32 0, i32 2)
%44 = icmp slt i32 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %42
%46 = icmp ugt i32 %43, 116
%47 = icmp ult i32 %43, %35
%48 = select i1 %46, i1 %47, i1 false
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @console_tx_byte(i32 0)
br label %51
51: ; preds = %49, %45, %42, %38, %34
%52 = tail call i32 @console_tx_string(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
ret void
}