#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__ usb_checkreceivestatus();
unsigned int usb_receivebyte(unsigned char *);
void usb_receivebuffer(void *buffer, unsigned int size) {
  unsigned char *receivebyte = (unsigned char *)buffer;
  unsigned int bytesleft = size;
  unsigned int returnvalue;
  while (bytesleft > 0) {
    if (usb_checkreceivestatus()) {
      returnvalue = usb_receivebyte(receivebyte);
      if (returnvalue == 1) {
        receivebyte++;
        bytesleft--;
      }
    }
  }
}


x86 assembly (clang, -O0):
<usb_receivebuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    118d <usb_receivebuffer+0x6d>
mov    $0x0,%al
call   1040 <usb_checkreceivestatus@plt>
cmp    $0x0,%rax
je     1188 <usb_receivebuffer+0x68>
mov    -0x18(%rbp),%rdi
call   1030 <usb_receivebyte@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1183 <usb_receivebuffer+0x63>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <usb_receivebuffer+0x68>
jmp    113d <usb_receivebuffer+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_receivebuffer>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1156 <usb_receivebuffer+0x36>
mov    %esi,%ebx
mov    %rdi,%r14
jmp    1134 <usb_receivebuffer+0x14>
nop
test   %ebx,%ebx
je     1156 <usb_receivebuffer+0x36>
xor    %eax,%eax
call   1040 <usb_checkreceivestatus@plt>
test   %rax,%rax
je     1130 <usb_receivebuffer+0x10>
mov    %r14,%rdi
call   1030 <usb_receivebyte@plt>
cmp    $0x1,%eax
jne    1130 <usb_receivebuffer+0x10>
add    $0x1,%r14
add    $0xffffffff,%ebx
jmp    1130 <usb_receivebuffer+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @usb_receivebuffer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* %4
store i32 %9, i32* %6
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %6
%12 = icmp ugt i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = call i64 (...) @usb_checkreceivestatus()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i32 @usb_receivebyte(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
%24 = load i32, i32* %6
%25 = add i32 %24, -1
store i32 %25, i32* %6
br label %26
26: ; preds = %21, %16
br label %27
27: ; preds = %26, %13
br label %10
28: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @usb_receivebuffer(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2, %15
%5 = phi i8* [ %17, %15 ], [ %0, %2 ]
%6 = phi i32 [ %16, %15 ], [ %1, %2 ]
%7 = tail call i64 (...) @usb_checkreceivestatus()
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i32 @usb_receivebyte(i8* %5)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %5, i64 1
%14 = add i32 %6, -1
br label %15
15: ; preds = %9, %12, %4
%16 = phi i32 [ %14, %12 ], [ %6, %9 ], [ %6, %4 ]
%17 = phi i8* [ %13, %12 ], [ %5, %9 ], [ %5, %4 ]
%18 = icmp eq i32 %16, 0
br i1 %18, label %19, label %4
19: ; preds = %15, %2
ret void
}