#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_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ memset(struct sockaddr *, int /*<<< orphan*/, int);
int recvfrom(int, char *, size_t, int, struct sockaddr *, int *);
int sock_receive(int sock, void *buf, size_t len, int flags,
                 struct sockaddr *srcaddr, socklen_t *addrlen) {
  socklen_t al;
  al = sizeof(struct sockaddr_storage);
  memset(srcaddr, 0, sizeof(struct sockaddr));
  int n;
  while ((n = recvfrom(sock, (char *)buf, len, flags, srcaddr, &al)) < 0) {
    if (errno != EINTR)
      return n;
  }
  return n;
}


x86 assembly (clang, -O0):
<sock_receive>:
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)
movl   $0x4,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    11a6 <sock_receive+0x86>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <sock_receive+0x81>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <sock_receive+0x8c>
jmp    1155 <sock_receive+0x35>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_receive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
movl   $0x4,0x4(%rsp)
mov    %r8,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %rbx,%r8
mov    %r13,%r9
call   1040 <recvfrom@plt>
test   %eax,%eax
jns    1190 <sock_receive+0x70>
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e4d(%rip),%rdx
cmp    (%rdx),%rcx
je     1160 <sock_receive+0x40>
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
@EINTR = global i64 0
define i32 @sock_receive(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
%15 = 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
store i32 4, i32* %14
%16 = load %struct.sockaddr*, %struct.sockaddr** %12
%17 = call i32 @memset(%struct.sockaddr* %16, i32 0, i32 4)
br label %18
18: ; preds = %32, %6
%19 = load i32, i32* %8
%20 = load i8*, i8** %9
%21 = load i64, i64* %10
%22 = load i32, i32* %11
%23 = load %struct.sockaddr*, %struct.sockaddr** %12
%24 = call i32 @recvfrom(i32 %19, i8* %20, i64 %21, i32 %22, %struct.sockaddr* %23, i32* %14)
store i32 %24, i32* %15
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %18
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINTR
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i32, i32* %15
store i32 %31, i32* %7
br label %35
32: ; preds = %26
br label %18
33: ; preds = %18
%34 = load i32, i32* %15
store i32 %34, i32* %7
br label %35
35: ; preds = %33, %30
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @sock_receive(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32* nocapture readnone %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%9 = tail call i32 @memset(%struct.sockaddr* %4, i32 0, i32 4)
br label %10
10: ; preds = %13, %6
%11 = call i32 @recvfrom(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32* %7)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %10, label %17
17: ; preds = %10, %13
ret i32 %11
}