#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__ EAGAIN;
scalar_t__ errno;
int recv(int, void *, int, int /*<<< orphan*/);
int receive(int connection, void *buffer, int size, int busy_waiting) {
  if (busy_waiting) {
    while (recv(connection, buffer, size, 0) < size) {
      if (errno != EAGAIN)
        return -1;
    }
  } else if (recv(connection, buffer, size, 0) < size) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     117e <receive+0x6e>
jmp    1134 <receive+0x24>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    -0x14(%rbp),%eax
jge    1179 <receive+0x69>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
je     1174 <receive+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <receive+0xa0>
jmp    1134 <receive+0x24>
jmp    11a9 <receive+0x99>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    -0x14(%rbp),%eax
jge    11a4 <receive+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <receive+0xa0>
jmp    11a9 <receive+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
test   %ecx,%ecx
je     1162 <receive+0x52>
mov    0x2eb6(%rip),%r15
mov    0x2e9f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    %ebx,%eax
jge    117b <receive+0x6b>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1140 <receive+0x30>
mov    $0xffffffff,%eax
jmp    117d <receive+0x6d>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ebx,%ecx
jl     117d <receive+0x6d>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @receive(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %4
br label %13
13: ; preds = %25, %12
%14 = load i32, i32* %6
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = call i32 @recv(i32 %14, i8* %15, i32 %16, i32 0)
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i64, i64* @errno
%22 = load i64, i64* @EAGAIN
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 -1, i32* %5
br label %37
25: ; preds = %20
br label %13
26: ; preds = %13
br label %36
27: ; preds = %4
%28 = load i32, i32* %6
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = call i32 @recv(i32 %28, i8* %29, i32 %30, i32 0)
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 -1, i32* %5
br label %37
35: ; preds = %27
br label %36
36: ; preds = %35, %26
store i32 0, i32* %5
br label %37
37: ; preds = %36, %34, %24
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @receive(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %13, label %6
6: ; preds = %4, %9
%7 = tail call i32 @recv(i32 %0, i8* %1, i32 %2, i32 0)
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @EAGAIN
%12 = icmp eq i64 %10, %11
br i1 %12, label %6, label %17
13: ; preds = %4
%14 = tail call i32 @recv(i32 %0, i8* %1, i32 %2, i32 0)
%15 = icmp slt i32 %14, %2
br i1 %15, label %17, label %16
16: ; preds = %6, %13
br label %17
17: ; preds = %9, %13, %16
%18 = phi i32 [ 0, %16 ], [ -1, %13 ], [ -1, %9 ]
ret i32 %18
}