#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*/ read_reg16(struct device *, int /*<<< orphan*/);
int /*<<< orphan*/ wait_drq(struct device *);
void read_data(struct device *dev, void *buf) {
  int i;
  uint16_t *ptr = buf;
  wait_drq(dev);
  for (i = 0; i < 256; i++) {
    *ptr++ = read_reg16(dev, 0);
  }
}


x86 assembly (clang, -O0):
<read_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    1181 <read_data+0x61>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <read_reg16@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x20(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <read_data+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_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    %r15,%rdi
xor    %esi,%esi
call   1030 <read_reg16@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x100,%ebx
jne    1140 <read_data+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.device = type { i32 }
define void @read_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 = %19, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load %struct.device*, %struct.device** %3
%16 = call i32 @read_reg16(%struct.device* %15, i32 0)
%17 = load i32*, i32** %6
%18 = getelementptr inbounds i32, i32* %17, i32 1
store i32* %18, i32** %6
store i32 %16, i32* %17
br label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %11
22: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.device = type { i32 }
define void @read_data(%struct.device* %0, i8* nocapture writeonly %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 ], [ %9, %5 ]
%7 = phi i32 [ 0, %2 ], [ %10, %5 ]
%8 = tail call i32 @read_reg16(%struct.device* %0, i32 0)
%9 = getelementptr inbounds i32, i32* %6, i64 1
store i32 %8, i32* %6
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, 256
br i1 %11, label %12, label %5
12: ; preds = %5
ret void
}