#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 uint32_t;
struct riku_devfs_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ps2kb_getch(struct riku_devfs_node *, char *);
int ps2kb_read(struct riku_devfs_node *self, const char *buffer,
               uint32_t count) {
  int i;
  char *thebuf = (char *)buffer;
  for (i = 0; i < count; i++) {
    ps2kb_getch(self, (thebuf + i));
  }
  return 0;
}


x86 assembly (clang, -O0):
<ps2kb_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1160 <ps2kb_read+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
call   1030 <ps2kb_getch@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <ps2kb_read+0x22>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps2kb_read>:
push   %r15
push   %r14
push   %rbx
test   %edx,%edx
jle    1145 <ps2kb_read+0x35>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <ps2kb_getch@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    1130 <ps2kb_read+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.riku_devfs_node = type { i32 }
define i32 @ps2kb_read(%struct.riku_devfs_node* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %11, %7 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = tail call i32 @ps2kb_getch(%struct.riku_devfs_node* %0, i8* %9)
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, %6
br i1 %12, label %13, label %7
13: ; preds = %7, %3
ret i32 0
}