#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 ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int recv(int, void *, size_t, int);
int /*<<< orphan*/ task_yield();
ssize_t sys_recv(int sockfd, void *buf, size_t len, int flags) {
  ssize_t ret;
RETRY:
  ret = recv(sockfd, buf, len, flags);
  if (ret == -1 && errno == EAGAIN) {
    task_yield();
    goto RETRY;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sys_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    117c <sys_recv+0x5c>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <sys_recv+0x5c>
mov    $0x0,%al
call   1040 <task_yield@plt>
jmp    1136 <sys_recv+0x16>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    117d <sys_recv+0x5d>
mov    0x2e99(%rip),%r12
mov    0x2e82(%rip),%r13
xchg   %ax,%ax
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    1178 <sys_recv+0x58>
xor    %eax,%eax
call   1040 <task_yield@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     1150 <sys_recv+0x30>
jmp    117d <sys_recv+0x5d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_recv(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
br label %10
10: ; preds = %22, %4
%11 = load i32, i32* %5
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = load i32, i32* %8
%15 = call i32 @recv(i32 %11, i8* %12, i64 %13, i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (...) @task_yield()
br label %10
24: ; preds = %18, %10
%25 = load i32, i32* %9
ret i32 %25
}

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