#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 */
scalar_t__ CheckNewArrive();
unsigned char RxDByte_DXL();
int dxl_hal_rx(unsigned char *pPacket, int numPacket) {
  unsigned char i;
  for (i = 0; i < numPacket; i++) {
    if (CheckNewArrive())
      pPacket[i] = RxDByte_DXL();
    else
      return i;
  }
  return numPacket;
}


x86 assembly (clang, -O0):
<dxl_hal_rx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <dxl_hal_rx+0x68>
mov    $0x0,%al
call   1030 <CheckNewArrive@plt>
cmp    $0x0,%rax
je     116a <dxl_hal_rx+0x4a>
mov    $0x0,%al
call   1040 <RxDByte_DXL@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movzbl -0x15(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    1176 <dxl_hal_rx+0x56>
movzbl -0x15(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <dxl_hal_rx+0x6e>
jmp    117b <dxl_hal_rx+0x5b>
mov    -0x15(%rbp),%al
add    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    1133 <dxl_hal_rx+0x13>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dxl_hal_rx>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
test   %esi,%esi
jle    1158 <dxl_hal_rx+0x38>
mov    %rdi,%r14
xor    %ebp,%ebp
nop
xor    %eax,%eax
call   1030 <CheckNewArrive@plt>
test   %rax,%rax
je     1156 <dxl_hal_rx+0x36>
xor    %eax,%eax
call   1040 <RxDByte_DXL@plt>
mov    %ebp,%ecx
mov    %al,(%r14,%rcx,1)
add    $0x1,%ebp
movzbl %bpl,%ebp
cmp    %ebx,%ebp
jl     1130 <dxl_hal_rx+0x10>
jmp    1158 <dxl_hal_rx+0x38>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @dxl_hal_rx(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %8
%5 = phi i32 [ %13, %8 ], [ 0, %2 ]
%6 = tail call i64 (...) @CheckNewArrive()
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = tail call zeroext i8 (...) @RxDByte_DXL()
%10 = zext i32 %5 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %9, i8* %11
%12 = add nuw nsw i32 %5, 1
%13 = and i32 %12, 255
%14 = icmp slt i32 %13, %1
br i1 %14, label %4, label %15
15: ; preds = %4, %8, %2
%16 = phi i32 [ %1, %2 ], [ %1, %8 ], [ %5, %4 ]
ret i32 %16
}