#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*/ __kern_rs232_getc(unsigned int);
void __kern_rs232_read(unsigned int __uartreg, unsigned char *__ptr,
                       unsigned int __size, unsigned int __nblk) {
  unsigned int s, n;
  for (n = 0; n < __nblk; n++) {
    for (s = 0; s < __size; s++) {
      *__ptr++ = __kern_rs232_getc(__uartreg);
    }
  }
}


x86 assembly (clang, -O0):
<__kern_rs232_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1187 <__kern_rs232_read+0x77>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1174 <__kern_rs232_read+0x64>
mov    -0x4(%rbp),%edi
call   1030 <__kern_rs232_getc@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <__kern_rs232_read+0x2f>
jmp    1179 <__kern_rs232_read+0x69>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112c <__kern_rs232_read+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__kern_rs232_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
je     1165 <__kern_rs232_read+0x55>
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%r13d
xor    %r12d,%r12d
jmp    1139 <__kern_rs232_read+0x29>
add    $0x1,%r12d
cmp    %r14d,%r12d
je     1165 <__kern_rs232_read+0x55>
test   %r15d,%r15d
je     1130 <__kern_rs232_read+0x20>
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1030 <__kern_rs232_getc@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    1150 <__kern_rs232_read+0x40>
jmp    1130 <__kern_rs232_read+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @__kern_rs232_read(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
br label %11
11: ; preds = %30, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %8
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
store i32 0, i32* %9
br label %16
16: ; preds = %26, %15
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* %5
%22 = call i32 @__kern_rs232_getc(i32 %21)
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
store i8 %23, i8* %24
br label %26
26: ; preds = %20
%27 = load i32, i32* %9
%28 = add i32 %27, 1
store i32 %28, i32* %9
br label %16
29: ; preds = %16
br label %30
30: ; preds = %29
%31 = load i32, i32* %10
%32 = add i32 %31, 1
store i32 %32, i32* %10
br label %11
33: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @__kern_rs232_read(i32 %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %23, label %6
6: ; preds = %4
%7 = icmp eq i32 %2, 0
br label %8
8: ; preds = %6, %19
%9 = phi i32 [ 0, %6 ], [ %21, %19 ]
%10 = phi i8* [ %1, %6 ], [ %20, %19 ]
br i1 %7, label %19, label %11
11: ; preds = %8, %11
%12 = phi i32 [ %17, %11 ], [ 0, %8 ]
%13 = phi i8* [ %16, %11 ], [ %10, %8 ]
%14 = tail call i32 @__kern_rs232_getc(i32 %0)
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %15, i8* %13
%17 = add nuw i32 %12, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %11
19: ; preds = %11, %8
%20 = phi i8* [ %10, %8 ], [ %16, %11 ]
%21 = add nuw i32 %9, 1
%22 = icmp eq i32 %21, %3
br i1 %22, label %23, label %8
23: ; preds = %19, %4
ret void
}