#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 char get_spd_byte(int, unsigned char);
unsigned int get_ddr_speed(int slotnum, int ddrtype) {
  unsigned char cycle = 0, offset = 0;
  unsigned int speed = 0;
  if (ddrtype == 0x8) {
    offset = 0x09;
    cycle = get_spd_byte(slotnum, offset);
    if (cycle == 0x50)
      speed = 400;
    else if (cycle == 0x3D)
      speed = 533;
    else if (cycle == 0x30)
      speed = 667;
    else if (cycle == 0x25)
      speed = 800;
  }
  if (ddrtype == 0xb) {
    offset = 0x0C;
    cycle = get_spd_byte(slotnum, offset);
    if (cycle == 0x14)
      speed = 800;
    else if (cycle == 0x0F)
      speed = 1066;
    else if (cycle == 0x0C)
      speed = 1333;
    else if (cycle == 0x0A)
      speed = 1600;
  }
  return speed;
}


x86 assembly (clang, -O0):
<get_ddr_speed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x8(%rbp)
jne    11bd <get_ddr_speed+0xad>
movb   $0x9,-0xa(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0xa(%rbp),%esi
call   1030 <get_spd_byte@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x50,%eax
jne    1163 <get_ddr_speed+0x53>
movl   $0x190,-0x10(%rbp)
jmp    11b8 <get_ddr_speed+0xa8>
movzbl -0x9(%rbp),%eax
cmp    $0x3d,%eax
jne    117c <get_ddr_speed+0x6c>
movl   $0x215,-0x10(%rbp)
jmp    11b3 <get_ddr_speed+0xa3>
movzbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jne    1195 <get_ddr_speed+0x85>
movl   $0x29b,-0x10(%rbp)
jmp    11ae <get_ddr_speed+0x9e>
movzbl -0x9(%rbp),%eax
cmp    $0x25,%eax
jne    11a9 <get_ddr_speed+0x99>
movl   $0x320,-0x10(%rbp)
jmp    11ae <get_ddr_speed+0x9e>
jmp    11b3 <get_ddr_speed+0xa3>
jmp    11b8 <get_ddr_speed+0xa8>
jmp    11bd <get_ddr_speed+0xad>
cmpl   $0xb,-0x8(%rbp)
jne    124d <get_ddr_speed+0x13d>
movb   $0xc,-0xa(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0xa(%rbp),%esi
call   1030 <get_spd_byte@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x14,%eax
jne    11f3 <get_ddr_speed+0xe3>
movl   $0x320,-0x10(%rbp)
jmp    1248 <get_ddr_speed+0x138>
movzbl -0x9(%rbp),%eax
cmp    $0xf,%eax
jne    120c <get_ddr_speed+0xfc>
movl   $0x42a,-0x10(%rbp)
jmp    1243 <get_ddr_speed+0x133>
movzbl -0x9(%rbp),%eax
cmp    $0xc,%eax
jne    1225 <get_ddr_speed+0x115>
movl   $0x535,-0x10(%rbp)
jmp    123e <get_ddr_speed+0x12e>
movzbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1239 <get_ddr_speed+0x129>
movl   $0x640,-0x10(%rbp)
jmp    123e <get_ddr_speed+0x12e>
jmp    1243 <get_ddr_speed+0x133>
jmp    1248 <get_ddr_speed+0x138>
jmp    124d <get_ddr_speed+0x13d>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ddr_speed>:
push   %rax
xor    %eax,%eax
cmp    $0xb,%esi
je     113a <get_ddr_speed+0x2a>
cmp    $0x8,%esi
jne    117e <get_ddr_speed+0x6e>
mov    $0x9,%esi
call   1030 <get_spd_byte@plt>
cmp    $0x3c,%al
jg     116d <get_ddr_speed+0x5d>
cmp    $0x25,%al
je     1180 <get_ddr_speed+0x70>
cmp    $0x30,%al
jne    117c <get_ddr_speed+0x6c>
mov    $0x29b,%eax
pop    %rcx
ret
mov    $0xc,%esi
call   1030 <get_spd_byte@plt>
mov    %eax,%ecx
add    $0xf6,%cl
cmp    $0xa,%cl
ja     117c <get_ddr_speed+0x6c>
mov    $0x320,%eax
movzbl %cl,%ecx
lea    0xea3(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x640,%eax
pop    %rcx
ret
cmp    $0x50,%al
je     1195 <get_ddr_speed+0x85>
cmp    $0x3d,%al
jne    117c <get_ddr_speed+0x6c>
mov    $0x215,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    $0x320,%eax
pop    %rcx
ret
mov    $0x535,%eax
pop    %rcx
ret
mov    $0x42a,%eax
pop    %rcx
ret
mov    $0x190,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @get_ddr_speed(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8 0, i8* %5
store i8 0, i8* %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 8
br i1 %9, label %10, label %37
10: ; preds = %2
store i8 9, i8* %6
%11 = load i32, i32* %3
%12 = load i8, i8* %6
%13 = call zeroext i8 @get_spd_byte(i32 %11, i8 zeroext %12)
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 80
br i1 %16, label %17, label %18
17: ; preds = %10
store i32 400, i32* %7
br label %36
18: ; preds = %10
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 61
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 533, i32* %7
br label %35
23: ; preds = %18
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 48
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 667, i32* %7
br label %34
28: ; preds = %23
%29 = load i8, i8* %5
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 37
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 800, i32* %7
br label %33
33: ; preds = %32, %28
br label %34
34: ; preds = %33, %27
br label %35
35: ; preds = %34, %22
br label %36
36: ; preds = %35, %17
br label %37
37: ; preds = %36, %2
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 11
br i1 %39, label %40, label %67
40: ; preds = %37
store i8 12, i8* %6
%41 = load i32, i32* %3
%42 = load i8, i8* %6
%43 = call zeroext i8 @get_spd_byte(i32 %41, i8 zeroext %42)
store i8 %43, i8* %5
%44 = load i8, i8* %5
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 20
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 800, i32* %7
br label %66
48: ; preds = %40
%49 = load i8, i8* %5
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 15
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 1066, i32* %7
br label %65
53: ; preds = %48
%54 = load i8, i8* %5
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 12
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 1333, i32* %7
br label %64
58: ; preds = %53
%59 = load i8, i8* %5
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 10
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 1600, i32* %7
br label %63
63: ; preds = %62, %58
br label %64
64: ; preds = %63, %57
br label %65
65: ; preds = %64, %52
br label %66
66: ; preds = %65, %47
br label %67
67: ; preds = %66, %37
%68 = load i32, i32* %7
ret i32 %68
}

LLVM IR (-O2):
define i32 @get_ddr_speed(i32 %0, i32 %1) {
switch i32 %1, label %15 [
i32 8, label %3
i32 11, label %9
]
3: ; preds = %2
%4 = tail call zeroext i8 @get_spd_byte(i32 %0, i8 zeroext 9)
switch i8 %4, label %8 [
i8 80, label %15
i8 61, label %5
i8 48, label %6
i8 37, label %7
]
5: ; preds = %3
br label %15
6: ; preds = %3
br label %15
7: ; preds = %3
br label %15
8: ; preds = %3
br label %15
9: ; preds = %2
%10 = tail call zeroext i8 @get_spd_byte(i32 %0, i8 zeroext 12)
switch i8 %10, label %14 [
i8 20, label %15
i8 15, label %11
i8 12, label %12
i8 10, label %13
]
11: ; preds = %9
br label %15
12: ; preds = %9
br label %15
13: ; preds = %9
br label %15
14: ; preds = %9
br label %15
15: ; preds = %2, %5, %7, %6, %8, %3, %9, %14, %12, %13, %11
%16 = phi i32 [ 1066, %11 ], [ 1333, %12 ], [ 1600, %13 ], [ 800, %9 ], [ 0, %14 ], [ 0, %8 ], [ 400, %3 ], [ 800, %7 ], [ 667, %6 ], [ 533, %5 ], [ 0, %2 ]
ret i32 %16
}