#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 */
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int recvfrom(int, void *, size_t, int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ task_yield();
ssize_t sys_recvfrom(int sockfd, void *buf, size_t len, int flags,
                     struct sockaddr *src_addr, socklen_t *addrlen) {
  ssize_t ret;
RETRY:
  ret = recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
  if (ret == -1 && errno == EAGAIN) {
    task_yield();
    goto RETRY;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sys_recvfrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    118c <sys_recvfrom+0x6c>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
jne    118c <sys_recvfrom+0x6c>
mov    $0x0,%al
call   1040 <task_yield@plt>
jmp    113e <sys_recvfrom+0x1e>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_recvfrom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%ebx
nopl   0x0(%rax)
call   1030 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    117f <sys_recvfrom+0x5f>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jne    117a <sys_recvfrom+0x5a>
xor    %eax,%eax
call   1040 <task_yield@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %r15,%r8
mov    %r14,%r9
jmp    1140 <sys_recvfrom+0x20>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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