#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 */

/* Variables and functions */
scalar_t__ EINTR;
int _fix_errno();
scalar_t__ errno;
int recv(int, void *, int, int /*<<< orphan*/);
int socket_recv(int fd, void *buf, int len) {
  int ret;
  do {
    errno = 0;
    do {
      ret = ((recv(fd, buf, len, 0)));
    } while (ret < 0 && errno == EINTR);
  } while (0);
  ;
  if (ret < 0)
    return _fix_errno();
  return ret;
  ;
}


x86 assembly (clang, -O0):
<socket_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2ea7(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jge    117d <socket_recv+0x5d>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1140 <socket_recv+0x20>
jmp    118d <socket_recv+0x6d>
cmpl   $0x0,-0x18(%rbp)
jge    11a6 <socket_recv+0x86>
mov    $0x0,%al
call   1040 <_fix_errno@plt>
mov    %eax,-0x4(%rbp)
jmp    11ac <socket_recv+0x8c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_recv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea9(%rip),%r15
movq   $0x0,(%r15)
mov    0x2e93(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    116c <socket_recv+0x4c>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1150 <socket_recv+0x30>
test   %eax,%eax
js     1179 <socket_recv+0x59>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_fix_errno@plt>

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

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