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

/* Variables and functions */
int EINTR;
int errno;
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int BasSockUdpReceive(int sock, char *buf, int size, struct sockaddr_in *from) {
  int fromlen;
  int res;
  int code;
  do {
    fromlen = sizeof(*from);
    res = recvfrom(sock, buf, size, 0, (struct sockaddr *)from, &fromlen);
    if (res < 0)
      code = errno;
    else
      code = 0;
  } while (code == EINTR);
  return res;
}


x86 assembly (clang, -O0):
<BasSockUdpReceive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1164 <BasSockUdpReceive+0x54>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    116b <BasSockUdpReceive+0x5b>
movl   $0x0,-0x2c(%rbp)
jmp    1170 <BasSockUdpReceive+0x60>
mov    -0x2c(%rbp),%eax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
je     1126 <BasSockUdpReceive+0x16>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasSockUdpReceive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb3(%rip),%r13
mov    0x2ea4(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x4,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r14,%r8
lea    0x4(%rsp),%r9
call   1030 <recvfrom@plt>
mov    %eax,%ecx
sar    $0x1f,%ecx
and    0x0(%r13),%ecx
cmp    (%r12),%ecx
je     1140 <BasSockUdpReceive+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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