#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;
};
struct in_pktinfo {
  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_flags(int, void *, size_t, int *, struct sockaddr *, int *,
                   struct in_pktinfo *);
size_t WrecvfromFlagsInet4(int s, void *buf, size_t len, int *flags,
                           struct sockaddr_in *from, struct in_pktinfo *pktp) {
  ssize_t res;
  socklen_t size = sizeof(*from);
retry:
  res = recvfrom_flags(s, buf, len, flags, ((struct sockaddr *)(from)), &size,
                       pktp);
  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):
<WrecvfromFlagsInet4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x8,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%rax
lea    -0x38(%rbp),%r9
mov    %rax,(%rsp)
call   1030 <recvfrom_flags@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    118b <WrecvfromFlagsInet4+0x7b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <WrecvfromFlagsInet4+0x76>
jmp    1136 <WrecvfromFlagsInet4+0x26>
jmp    118b <WrecvfromFlagsInet4+0x7b>
cmpl   $0xffffffff,-0x34(%rbp)
je     11ba <WrecvfromFlagsInet4+0xaa>
movslq -0x38(%rbp),%rax
cmp    $0x8,%rax
jne    11ba <WrecvfromFlagsInet4+0xaa>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
je     11c1 <WrecvfromFlagsInet4+0xb1>
movl   $0xffffffff,-0x34(%rbp)
movslq -0x34(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrecvfromFlagsInet4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x8,0x14(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r15,(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r14,%r8
lea    0x14(%rsp),%r9
call   1030 <recvfrom_flags@plt>
cmp    $0xffffffff,%eax
jne    1179 <WrecvfromFlagsInet4+0x69>
mov    0x2e70(%rip),%rax
mov    (%rax),%rax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
je     1140 <WrecvfromFlagsInet4+0x30>
jmp    118f <WrecvfromFlagsInet4+0x7f>
cmpl   $0x8,0x14(%rsp)
jne    118f <WrecvfromFlagsInet4+0x7f>
mov    (%r14),%rcx
mov    0x2e5e(%rip),%rdx
cmp    (%rdx),%rcx
je     1194 <WrecvfromFlagsInet4+0x84>
mov    $0xffffffff,%eax
cltq
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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