#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 /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ EINTR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ recvfrom(int, void *, size_t, int, struct sockaddr *,
                            int /*<<< orphan*/ *);
ssize_t recvfrom_loop(int fd, void *buf, size_t buf_len, int flags,
                      struct sockaddr *sa, socklen_t *sa_len) {
  for (;;) {
    ssize_t l;
    if ((l = recvfrom(fd, buf, buf_len, flags, sa, sa_len)) >= 0)
      return l;
    if (errno != EINTR)
      return -errno;
  }
}


x86 assembly (clang, -O0):
<recvfrom_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%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)
cmp    $0x0,%eax
jl     1160 <recvfrom_loop+0x50>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <recvfrom_loop+0x80>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
je     118b <recvfrom_loop+0x7b>
xor    %eax,%eax
mov    0x2e5f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <recvfrom_loop+0x80>
jmp    112e <recvfrom_loop+0x1e>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvfrom_loop>:
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)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1030 <recvfrom@plt>
test   %eax,%eax
jns    1160 <recvfrom_loop+0x50>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     1130 <recvfrom_loop+0x20>
neg    %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 i32 0
@EINTR = global i32 0
define i32 @recvfrom_loop(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.sockaddr*
%13 = alloca i32*
%14 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32 %3, i32* %11
store %struct.sockaddr* %4, %struct.sockaddr** %12
store i32* %5, i32** %13
br label %15
15: ; preds = %33, %6
%16 = load i32, i32* %8
%17 = load i8*, i8** %9
%18 = load i64, i64* %10
%19 = load i32, i32* %11
%20 = load %struct.sockaddr*, %struct.sockaddr** %12
%21 = load i32*, i32** %13
%22 = call i32 @recvfrom(i32 %16, i8* %17, i64 %18, i32 %19, %struct.sockaddr* %20, i32* %21)
store i32 %22, i32* %14
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i32, i32* %14
store i32 %25, i32* %7
br label %34
26: ; preds = %15
%27 = load i32, i32* @errno
%28 = load i32, i32* @EINTR
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @errno
%32 = sub nsw i32 0, %31
store i32 %32, i32* %7
br label %34
33: ; preds = %26
br label %15
34: ; preds = %30, %24
%35 = load i32, i32* %7
ret i32 %35
}

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