#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*/ inw(unsigned short *);
int /*<<< orphan*/ outw(unsigned short, unsigned short *);
void lcd_hpi_read_words(unsigned short chip_addr, unsigned short *data,
                        int num_words) {
  int i;
  outw(chip_addr, (unsigned short *)((0x0002 << 1) + 0xfff24000));
  for (i = 0; i < num_words; i++) {
    *data++ = inw((unsigned short *)((0x0000 << 1) + 0xfff24000));
  }
}


x86 assembly (clang, -O0):
<lcd_hpi_read_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0xfff24004,%esi
movzwl -0x2(%rbp),%edi
call   1040 <outw@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1184 <lcd_hpi_read_words+0x64>
mov    $0xfff24000,%edi
call   1030 <inw@plt>
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <lcd_hpi_read_words+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_hpi_read_words>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    $0xfff24000,%eax
lea    0x4(%rax),%rsi
call   1040 <outw@plt>
test   %ebp,%ebp
jle    1157 <lcd_hpi_read_words+0x37>
mov    %ebp,%ebp
xor    %ebx,%ebx
nop
mov    $0xfff24000,%edi
call   1030 <inw@plt>
mov    %ax,(%r14,%rbx,2)
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1140 <lcd_hpi_read_words+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @lcd_hpi_read_words(i16 zeroext %0, i16* %1, i32 %2) {
%4 = alloca i16
%5 = alloca i16*
%6 = alloca i32
%7 = alloca i32
store i16 %0, i16* %4
store i16* %1, i16** %5
store i32 %2, i32* %6
%8 = load i16, i16* %4
%9 = call i32 @outw(i16 zeroext %8, i16* inttoptr (i64 4294066180 to i16*))
store i32 0, i32* %7
br label %10
10: ; preds = %19, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = call i32 @inw(i16* inttoptr (i64 4294066176 to i16*))
%16 = trunc i32 %15 to i16
%17 = load i16*, i16** %5
%18 = getelementptr inbounds i16, i16* %17, i32 1
store i16* %18, i16** %5
store i16 %16, i16* %17
br label %19
19: ; preds = %14
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %10
22: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @lcd_hpi_read_words(i16 zeroext %0, i16* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @outw(i16 zeroext %0, i16* inttoptr (i64 4294066180 to i16*))
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %14
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ 0, %3 ]
%8 = phi i16* [ %11, %6 ], [ %1, %3 ]
%9 = tail call i32 @inw(i16* inttoptr (i64 4294066176 to i16*))
%10 = trunc i32 %9 to i16
%11 = getelementptr inbounds i16, i16* %8, i64 1
store i16 %10, i16* %8
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, %2
br i1 %13, label %14, label %6
14: ; preds = %6, %3
ret void
}