#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_inb(int);
int __builtin_inl(unsigned int);
int /*<<< orphan*/ __builtin_outb(int, int);
void spd_enable_refresh(void) {
  static const unsigned char refresh_rates[] = {
      0x01, 0x05, 0x05, 0x02, 0x03, 0x04,
  };
  int byte;
  unsigned device;
  unsigned refresh_rate;
  byte = -1;
  device = 0x50;
  while ((byte < 0) && (device <= 0x57)) {
    byte = __builtin_inl(device);
    device += 1;
  }
  if (byte < 0) {
    while (1)
      ;
  }
  byte &= 0x7f;
  refresh_rate = 5;
  if (byte < 6) {
    refresh_rate = refresh_rates[byte];
  }
  byte = __builtin_inb(0x57);
  byte &= 0xf8;
  byte |= refresh_rate;
  __builtin_outb(byte, 0x57);
}


x86 assembly (clang, -O0):
<spd_enable_refresh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
movl   $0x50,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0xd(%rbp)
jge    115f <spd_enable_refresh+0x2f>
cmpl   $0x57,-0x8(%rbp)
setbe  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    116f <spd_enable_refresh+0x3f>
jmp    1188 <spd_enable_refresh+0x58>
mov    -0x8(%rbp),%edi
call   1040 <__builtin_inl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <spd_enable_refresh+0x16>
cmpl   $0x0,-0x4(%rbp)
jge    119c <spd_enable_refresh+0x6c>
jmp    1197 <spd_enable_refresh+0x67>
jmp    1197 <spd_enable_refresh+0x67>
mov    -0x4(%rbp),%eax
and    $0x7f,%eax
mov    %eax,-0x4(%rbp)
movl   $0x5,-0xc(%rbp)
cmpl   $0x6,-0x4(%rbp)
jge    11c8 <spd_enable_refresh+0x98>
movslq -0x4(%rbp),%rcx
lea    0xe3f(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0xc(%rbp)
mov    $0x57,%edi
call   1030 <__builtin_inb@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf8,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x57,%esi
call   1050 <__builtin_outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spd_enable_refresh>:
push   %rbx
mov    $0x50,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <__builtin_inl@plt>
test   %eax,%eax
jns    1155 <spd_enable_refresh+0x25>
lea    0x1(%rbx),%ecx
cmp    $0x57,%ebx
mov    %ecx,%ebx
jb     1140 <spd_enable_refresh+0x10>
test   %eax,%eax
js     1190 <spd_enable_refresh+0x60>
and    $0x7f,%eax
mov    $0x5,%ebx
cmp    $0x5,%eax
ja     1171 <spd_enable_refresh+0x41>
lea    0xe93(%rip),%rcx
movzbl (%rax,%rcx,1),%ebx
mov    $0x57,%edi
call   1030 <__builtin_inb@plt>
and    $0xf8,%eax
or     %eax,%ebx
mov    %ebx,%edi
mov    $0x57,%esi
pop    %rbx
jmp    1050 <__builtin_outb@plt>
nop
jmp    1190 <spd_enable_refresh+0x60>

LLVM IR (-O0):
@spd_enable_refresh.refresh_rates = internal constant [6 x i8] c"\01\05\05\02\03\04"
define void @spd_enable_refresh() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 -1, i32* %1
store i32 80, i32* %2
br label %4
4: ; preds = %12, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* %2
%9 = icmp ule i32 %8, 87
br label %10
10: ; preds = %7, %4
%11 = phi i1 [ false, %4 ], [ %9, %7 ]
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = load i32, i32* %2
%14 = call i32 @__builtin_inl(i32 %13)
store i32 %14, i32* %1
%15 = load i32, i32* %2
%16 = add i32 %15, 1
store i32 %16, i32* %2
br label %4
17: ; preds = %10
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
br label %21
21: ; preds = %20, %21
br label %21
22: ; preds = %17
%23 = load i32, i32* %1
%24 = and i32 %23, 127
store i32 %24, i32* %1
store i32 5, i32* %3
%25 = load i32, i32* %1
%26 = icmp slt i32 %25, 6
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [6 x i8], [6 x i8]* @spd_enable_refresh.refresh_rates, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
store i32 %32, i32* %3
br label %33
33: ; preds = %27, %22
%34 = call i32 @__builtin_inb(i32 87)
store i32 %34, i32* %1
%35 = load i32, i32* %1
%36 = and i32 %35, 248
store i32 %36, i32* %1
%37 = load i32, i32* %3
%38 = load i32, i32* %1
%39 = or i32 %38, %37
store i32 %39, i32* %1
%40 = load i32, i32* %1
%41 = call i32 @__builtin_outb(i32 %40, i32 87)
ret void
}

LLVM IR (-O2):
@spd_enable_refresh.refresh_rates = internal unnamed_addr constant [6 x i8] c"\01\05\05\02\03\04"
define void @spd_enable_refresh() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 80, %0 ], [ %4, %1 ]
%3 = tail call i32 @__builtin_inl(i32 %2)
%4 = add nuw nsw i32 %2, 1
%5 = icmp slt i32 %3, 0
%6 = icmp ult i32 %2, 87
%7 = and i1 %5, %6
br i1 %7, label %1, label %8
8: ; preds = %1
br i1 %5, label %9, label %10
9: ; preds = %8, %9
br label %9
10: ; preds = %8
%11 = and i32 %3, 127
%12 = icmp ult i32 %11, 6
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [6 x i8], [6 x i8]* @spd_enable_refresh.refresh_rates, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
br label %18
18: ; preds = %13, %10
%19 = phi i32 [ %17, %13 ], [ 5, %10 ]
%20 = tail call i32 @__builtin_inb(i32 87)
%21 = and i32 %20, 248
%22 = or i32 %21, %19
%23 = tail call i32 @__builtin_outb(i32 %22, i32 87)
ret void
}