#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__ EINTR;
scalar_t__ errno;
int recv(int, void *, size_t, int);
ssize_t recv_ni(int s, void *buf, size_t len, int flags) {
  int retval;
  while ((retval = recv(s, buf, len, flags)) < 0) {
    if (errno != EINTR)
      return retval;
  }
  return retval;
}


x86 assembly (clang, -O0):
<recv_ni>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    116f <recv_ni+0x5f>
mov    0x2e94(%rip),%rax
mov    (%rax),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
je     116a <recv_ni+0x5a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <recv_ni+0x65>
jmp    1126 <recv_ni+0x16>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_ni>:
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
mov    0x2eb3(%rip),%r12
mov    0x2ea4(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    115e <recv_ni+0x4e>
mov    (%r12),%rcx
cmp    0x0(%r13),%rcx
je     1140 <recv_ni+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @recv_ni(i32 %0, i8* %1, i64 %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i32 @recv(i32 %0, i8* %1, i64 %2, i32 %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %5, %8
ret i32 %6
}