#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_in {
  scalar_t__ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ EINTR;
scalar_t__ errno;
int recvfrom(int, void *, size_t, int, struct sockaddr *, int *);
size_t WrecvfromInet4(int s, void *buf, size_t len, int flags,
                      struct sockaddr_in *from) {
  ssize_t res;
  socklen_t size = sizeof(*from);
retry:
  res = recvfrom(s, buf, len, flags, ((struct sockaddr *)(from)), &size);
  if (res == -1) {
    if (errno == EINTR)
      goto retry;
  }
  if (res == -1 || size != sizeof(*from) || from->sin_family != AF_INET)
    res = -1;
  return ((size_t)(res));
}


x86 assembly (clang, -O0):
<WrecvfromInet4>:
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    %r8,-0x28(%rbp)
movl   $0x8,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    117d <WrecvfromInet4+0x6d>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <WrecvfromInet4+0x68>
jmp    1131 <WrecvfromInet4+0x21>
jmp    117d <WrecvfromInet4+0x6d>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11ac <WrecvfromInet4+0x9c>
movslq -0x30(%rbp),%rax
cmp    $0x8,%rax
jne    11ac <WrecvfromInet4+0x9c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
je     11b3 <WrecvfromInet4+0xa3>
movl   $0xffffffff,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrecvfromInet4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x8,0x4(%rsp)
mov    0x2e98(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r14,%r8
lea    0x4(%rsp),%r9
call   1030 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    116f <WrecvfromInet4+0x5f>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     1140 <WrecvfromInet4+0x30>
jmp    1185 <WrecvfromInet4+0x75>
cmpl   $0x8,0x4(%rsp)
jne    1185 <WrecvfromInet4+0x75>
mov    (%r14),%rcx
mov    0x2e68(%rip),%rdx
cmp    (%rdx),%rcx
je     118a <WrecvfromInet4+0x7a>
mov    $0xffffffff,%eax
cltq
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i64 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@AF_INET = global i64 0
define i64 @WrecvfromInet4(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr_in* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca %struct.sockaddr_in*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store %struct.sockaddr_in* %4, %struct.sockaddr_in** %10
store i32 8, i32* %12
br label %13
13: ; preds = %27, %5
%14 = load i32, i32* %6
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = load i32, i32* %9
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%19 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%20 = call i32 @recvfrom(i32 %14, i8* %15, i64 %16, i32 %17, %struct.sockaddr* %19, i32* %12)
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %13
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %13
28: ; preds = %23
br label %29
29: ; preds = %28, %13
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, -1
br i1 %31, label %42, label %32
32: ; preds = %29
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = icmp ne i64 %34, 8
br i1 %35, label %42, label %36
36: ; preds = %32
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load i64, i64* @AF_INET
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %36, %32, %29
store i32 -1, i32* %11
br label %43
43: ; preds = %42, %36
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
ret i64 %45
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64 }
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@AF_INET = global i64 0
define i64 @WrecvfromInet4(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr_in* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 8, i32* %6
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %9
9: ; preds = %12, %5
%10 = call i32 @recvfrom(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %8, i32* %6)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %9, label %24
16: ; preds = %9
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* @AF_INET
%23 = icmp eq i64 %21, %22
br i1 %23, label %25, label %24
24: ; preds = %12, %19, %16
br label %25
25: ; preds = %24, %19
%26 = phi i32 [ -1, %24 ], [ %10, %19 ]
%27 = sext i32 %26 to i64
ret i64 %27
}