#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*/ outb(unsigned int, unsigned long);
int i8254_load(unsigned long base_address, unsigned int regshift,
               unsigned int counter_number, unsigned int count,
               unsigned int mode) {
  unsigned int byte;
  if (counter_number > 2)
    return -1;
  if (count > 0xffff)
    return -1;
  if (mode > 5)
    return -1;
  if ((mode == 2 || mode == 3) && count == 1)
    return -1;
  byte = counter_number << 6;
  byte |= 0x30;
  byte |= (mode << 1);
  outb(byte, base_address + (3 << regshift));
  byte = count & 0xff;
  outb(byte, base_address + (counter_number << regshift));
  byte = (count >> 8) & 0xff;
  outb(byte, base_address + (counter_number << regshift));
  return 0;
}


x86 assembly (clang, -O0):
<i8254_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
cmpl   $0x2,-0x18(%rbp)
jbe    113f <i8254_load+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <i8254_load+0x113>
cmpl   $0xffff,-0x1c(%rbp)
jbe    1158 <i8254_load+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <i8254_load+0x113>
cmpl   $0x5,-0x20(%rbp)
jbe    116e <i8254_load+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <i8254_load+0x113>
cmpl   $0x2,-0x20(%rbp)
je     1182 <i8254_load+0x72>
cmpl   $0x3,-0x20(%rbp)
jne    1198 <i8254_load+0x88>
cmpl   $0x1,-0x1c(%rbp)
jne    1198 <i8254_load+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <i8254_load+0x113>
mov    -0x18(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
or     $0x30,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
mov    $0x3,%eax
shl    %cl,%eax
cltq
add    %rax,%rsi
call   1030 <outb@plt>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%eax
add    %rax,%rsi
call   1030 <outb@plt>
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%eax
add    %rax,%rsi
call   1030 <outb@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i8254_load>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%eax
cmp    $0x2,%edx
ja     1193 <i8254_load+0x83>
mov    %ecx,%ebp
cmp    $0xffff,%ecx
ja     1193 <i8254_load+0x83>
cmp    $0x5,%r8d
ja     1193 <i8254_load+0x83>
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r14
cmp    $0x1,%ebp
jne    1149 <i8254_load+0x39>
mov    %r8d,%ecx
and    $0xfffffffe,%ecx
cmp    $0x2,%ecx
je     1193 <i8254_load+0x83>
mov    %ebx,%eax
shl    $0x6,%eax
add    %r8d,%r8d
mov    $0x3,%edx
mov    %r15d,%ecx
shl    %cl,%edx
or     %eax,%r8d
or     $0x30,%r8d
movslq %edx,%rsi
add    %r14,%rsi
mov    %r8d,%edi
call   1030 <outb@plt>
movzbl %bpl,%edi
mov    %r15d,%ecx
shl    %cl,%ebx
add    %r14,%rbx
mov    %rbx,%rsi
call   1030 <outb@plt>
shr    $0x8,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <outb@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i8254_load(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i64 %0, i64* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i32, i32* %9
%14 = icmp ugt i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %5
store i32 -1, i32* %6
br label %71
16: ; preds = %5
%17 = load i32, i32* %10
%18 = icmp ugt i32 %17, 65535
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %6
br label %71
20: ; preds = %16
%21 = load i32, i32* %11
%22 = icmp ugt i32 %21, 5
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -1, i32* %6
br label %71
24: ; preds = %20
%25 = load i32, i32* %11
%26 = icmp eq i32 %25, 2
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %11
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %34
30: ; preds = %27, %24
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %6
br label %71
34: ; preds = %30, %27
%35 = load i32, i32* %9
%36 = shl i32 %35, 6
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = or i32 %37, 48
store i32 %38, i32* %12
%39 = load i32, i32* %11
%40 = shl i32 %39, 1
%41 = load i32, i32* %12
%42 = or i32 %41, %40
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = load i64, i64* %7
%45 = load i32, i32* %8
%46 = shl i32 3, %45
%47 = sext i32 %46 to i64
%48 = add i64 %44, %47
%49 = call i32 @outb(i32 %43, i64 %48)
%50 = load i32, i32* %10
%51 = and i32 %50, 255
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = load i64, i64* %7
%54 = load i32, i32* %9
%55 = load i32, i32* %8
%56 = shl i32 %54, %55
%57 = zext i32 %56 to i64
%58 = add i64 %53, %57
%59 = call i32 @outb(i32 %52, i64 %58)
%60 = load i32, i32* %10
%61 = lshr i32 %60, 8
%62 = and i32 %61, 255
store i32 %62, i32* %12
%63 = load i32, i32* %12
%64 = load i64, i64* %7
%65 = load i32, i32* %9
%66 = load i32, i32* %8
%67 = shl i32 %65, %66
%68 = zext i32 %67 to i64
%69 = add i64 %64, %68
%70 = call i32 @outb(i32 %63, i64 %69)
store i32 0, i32* %6
br label %71
71: ; preds = %34, %33, %23, %19, %15
%72 = load i32, i32* %6
ret i32 %72
}

LLVM IR (-O2):
define i32 @i8254_load(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp ugt i32 %2, 2
%7 = icmp ugt i32 %3, 65535
%8 = or i1 %6, %7
%9 = icmp ugt i32 %4, 5
%10 = or i1 %8, %9
br i1 %10, label %32, label %11
11: ; preds = %5
%12 = and i32 %4, -2
%13 = icmp eq i32 %12, 2
%14 = icmp eq i32 %3, 1
%15 = and i1 %14, %13
br i1 %15, label %32, label %16
16: ; preds = %11
%17 = shl nuw nsw i32 %2, 6
%18 = shl nuw nsw i32 %4, 1
%19 = or i32 %17, %18
%20 = or i32 %19, 48
%21 = shl i32 3, %1
%22 = sext i32 %21 to i64
%23 = add i64 %22, %0
%24 = tail call i32 @outb(i32 %20, i64 %23)
%25 = and i32 %3, 255
%26 = shl i32 %2, %1
%27 = zext i32 %26 to i64
%28 = add i64 %27, %0
%29 = tail call i32 @outb(i32 %25, i64 %28)
%30 = lshr i32 %3, 8
%31 = tail call i32 @outb(i32 %30, i64 %28)
br label %32
32: ; preds = %11, %5, %16
%33 = phi i32 [ 0, %16 ], [ -1, %5 ], [ -1, %11 ]
ret i32 %33
}