#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 */
typedef int /*<<< orphan*/ uint16_t;
struct device {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ wait_drq(struct device *);
int /*<<< orphan*/ write_reg16(struct device *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
void write_data(struct device *dev, void *buf) {
  int i;
  uint16_t *ptr = buf;
  wait_drq(dev);
  for (i = 0; i < 256; i++) {
    write_reg16(dev, 0, *ptr++);
  }
}


x86 assembly (clang, -O0):
<write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <wait_drq@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    117f <write_data+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <write_reg16@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <write_data+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <wait_drq@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <write_reg16@plt>
add    $0x1,%rbx
cmp    $0x100,%ebx
jne    1140 <write_data+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.device = type { i32 }
define void @write_data(%struct.device* %0, i8* %1) {
%3 = alloca %struct.device*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store %struct.device* %0, %struct.device** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %6
%9 = load %struct.device*, %struct.device** %3
%10 = call i32 @wait_drq(%struct.device* %9)
store i32 0, i32* %5
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load %struct.device*, %struct.device** %3
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %6
%18 = load i32, i32* %16
%19 = call i32 @write_reg16(%struct.device* %15, i32 0, i32 %18)
br label %20
20: ; preds = %14
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %11
23: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.device = type { i32 }
define void @write_data(%struct.device* %0, i8* nocapture %1) {
%3 = bitcast i8* %1 to i32*
%4 = tail call i32 @wait_drq(%struct.device* %0)
br label %5
5: ; preds = %2, %5
%6 = phi i32* [ %3, %2 ], [ %8, %5 ]
%7 = phi i32 [ 0, %2 ], [ %11, %5 ]
%8 = getelementptr inbounds i32, i32* %6, i64 1
%9 = load i32, i32* %6
%10 = tail call i32 @write_reg16(%struct.device* %0, i32 0, i32 %9)
%11 = add nuw nsw i32 %7, 1
%12 = icmp eq i32 %11, 256
br i1 %12, label %13, label %5
13: ; preds = %5
ret void
}