#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 /*<<< orphan*/ perror(char *);
int recv(int, void *, size_t, int);
ssize_t sk_recv(int fd, void *buff, size_t lenght, int flags) {
  ssize_t bcount;
  do
    bcount = recv(fd, buff, lenght, flags);
  while ((bcount < 0) && (errno == EINTR));
  if (bcount == -1)
    perror("recv()");
  return bcount;
}


x86 assembly (clang, -O0):
<sk_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
jge    1175 <sk_recv+0x55>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1136 <sk_recv+0x16>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1196 <sk_recv+0x76>
lea    0xe6f(%rip),%rdi
call   1040 <perror@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sk_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x2e9b(%rip),%r13
nopl   (%rax)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1166 <sk_recv+0x46>
mov    0x0(%r13),%rax
mov    0x2e7f(%rip),%rcx
cmp    %rax,(%rcx)
je     1140 <sk_recv+0x20>
cmp    $0xffffffff,%ebp
je     117c <sk_recv+0x5c>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7d(%rip),%rdi
call   1040 <perror@plt>
jmp    116b <sk_recv+0x4b>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"recv()\00"
define i32 @sk_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 = %23, %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
br label %16
16: ; preds = %10
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %10, label %25
25: ; preds = %23
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %9
ret i32 %31
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"recv()\00"
define i32 @sk_recv(i32 %0, i8* %1, i64 %2, i32 %3) {
br label %5
5: ; preds = %5, %4
%6 = tail call i32 @recv(i32 %0, i8* %1, i64 %2, i32 %3)
%7 = icmp slt i32 %6, 0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %5, label %12
12: ; preds = %5
%13 = icmp eq i32 %6, -1
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
ret i32 %6
}