#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*/ out_byte(int, int);
void do_DMA(int read, unsigned long buffer, unsigned long len) {
  len--;
  out_byte(0x0a, 0x06);
  out_byte(0x0c, (read ? 0x46 : 0x4a));
  out_byte(0x0b, (read ? 0x46 : 0x4a));
  out_byte(0x04, ((buffer & 0xFFFF) & 0xFF));
  out_byte(0x04, (((buffer & 0xFFFF) & 0xFF00) / 0x100));
  out_byte(0x81, (((buffer & 0xFFFF0000) / 0x10000) & 0xFF));
  out_byte(0x05, (len & 0xFF));
  out_byte(0x05, ((len & 0xFF00) / 0x100));
  out_byte(0x0a, 0x02);
}


x86 assembly (clang, -O0):
<do_DMA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    $0xa,%edi
mov    $0x6,%esi
call   1030 <out_byte@plt>
mov    -0x4(%rbp),%ecx
mov    $0x4a,%esi
mov    $0x46,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
mov    $0xc,%edi
call   1030 <out_byte@plt>
mov    -0x4(%rbp),%ecx
mov    $0x4a,%esi
mov    $0x46,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
mov    $0xb,%edi
call   1030 <out_byte@plt>
mov    -0x10(%rbp),%rax
and    $0xffff,%rax
and    $0xff,%rax
mov    %eax,%esi
mov    $0x4,%edi
call   1030 <out_byte@plt>
mov    -0x10(%rbp),%rax
and    $0xffff,%rax
and    $0xff00,%rax
shr    $0x8,%rax
mov    %eax,%esi
mov    $0x4,%edi
call   1030 <out_byte@plt>
movabs $0xffff0000,%rax
and    -0x10(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %eax,%esi
mov    $0x81,%edi
call   1030 <out_byte@plt>
mov    -0x18(%rbp),%rax
and    $0xff,%rax
mov    %eax,%esi
mov    $0x5,%edi
call   1030 <out_byte@plt>
mov    -0x18(%rbp),%rax
and    $0xff00,%rax
shr    $0x8,%rax
mov    %eax,%esi
mov    $0x5,%edi
call   1030 <out_byte@plt>
mov    $0xa,%edi
mov    $0x2,%esi
call   1030 <out_byte@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_DMA>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0xa,%edi
mov    $0x6,%esi
call   1030 <out_byte@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
lea    0x46(,%rax,4),%ebp
mov    $0xc,%edi
mov    %ebp,%esi
call   1030 <out_byte@plt>
mov    $0xb,%edi
mov    %ebp,%esi
call   1030 <out_byte@plt>
movzbl %bl,%esi
mov    $0x4,%edi
call   1030 <out_byte@plt>
movzbl %bh,%esi
mov    $0x4,%edi
call   1030 <out_byte@plt>
shr    $0x10,%ebx
movzbl %bl,%esi
mov    $0x81,%edi
call   1030 <out_byte@plt>
add    $0xffffffff,%r14d
movzbl %r14b,%esi
mov    %r14,%rbx
mov    $0x5,%edi
call   1030 <out_byte@plt>
movzbl %bh,%esi
mov    $0x5,%edi
call   1030 <out_byte@plt>
mov    $0xa,%edi
mov    $0x2,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <out_byte@plt>

LLVM IR (-O0):
define void @do_DMA(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load i64, i64* %6
%8 = add i64 %7, -1
store i64 %8, i64* %6
%9 = call i32 @out_byte(i32 10, i32 6)
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i32 70, i32 74
%14 = call i32 @out_byte(i32 12, i32 %13)
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 70, i32 74
%19 = call i32 @out_byte(i32 11, i32 %18)
%20 = load i64, i64* %5
%21 = and i64 %20, 65535
%22 = and i64 %21, 255
%23 = trunc i64 %22 to i32
%24 = call i32 @out_byte(i32 4, i32 %23)
%25 = load i64, i64* %5
%26 = and i64 %25, 65535
%27 = and i64 %26, 65280
%28 = udiv i64 %27, 256
%29 = trunc i64 %28 to i32
%30 = call i32 @out_byte(i32 4, i32 %29)
%31 = load i64, i64* %5
%32 = and i64 %31, 4294901760
%33 = udiv i64 %32, 65536
%34 = and i64 %33, 255
%35 = trunc i64 %34 to i32
%36 = call i32 @out_byte(i32 129, i32 %35)
%37 = load i64, i64* %6
%38 = and i64 %37, 255
%39 = trunc i64 %38 to i32
%40 = call i32 @out_byte(i32 5, i32 %39)
%41 = load i64, i64* %6
%42 = and i64 %41, 65280
%43 = udiv i64 %42, 256
%44 = trunc i64 %43 to i32
%45 = call i32 @out_byte(i32 5, i32 %44)
%46 = call i32 @out_byte(i32 10, i32 2)
ret void
}

LLVM IR (-O2):
define void @do_DMA(i32 %0, i64 %1, i64 %2) {
%4 = tail call i32 @out_byte(i32 10, i32 6)
%5 = icmp eq i32 %0, 0
%6 = select i1 %5, i32 74, i32 70
%7 = tail call i32 @out_byte(i32 12, i32 %6)
%8 = tail call i32 @out_byte(i32 11, i32 %6)
%9 = trunc i64 %1 to i32
%10 = and i32 %9, 255
%11 = tail call i32 @out_byte(i32 4, i32 %10)
%12 = lshr i32 %9, 8
%13 = and i32 %12, 255
%14 = tail call i32 @out_byte(i32 4, i32 %13)
%15 = lshr i32 %9, 16
%16 = and i32 %15, 255
%17 = tail call i32 @out_byte(i32 129, i32 %16)
%18 = trunc i64 %2 to i32
%19 = add i32 %18, -1
%20 = and i32 %19, 255
%21 = tail call i32 @out_byte(i32 5, i32 %20)
%22 = lshr i32 %19, 8
%23 = and i32 %22, 255
%24 = tail call i32 @out_byte(i32 5, i32 %23)
%25 = tail call i32 @out_byte(i32 10, i32 2)
ret void
}