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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             unsigned int *);
int udp_receive(int sock, char *buffer, int size, struct sockaddr *sockaddr) {
  unsigned int sockaddrLen = sizeof(*sockaddr);
  int receivedSize =
      recvfrom(sock, buffer, (4096 + 1), 0, sockaddr, &sockaddrLen);
  if (receivedSize < 0) {
    perror("recvfrom() failed.");
    return -1;
  }
  return receivedSize;
}


x86 assembly (clang, -O0):
<udp_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%r8
mov    $0x1001,%edx
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    117d <udp_receive+0x5d>
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <udp_receive+0x63>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_receive>:
push   %rax
mov    %rcx,%r8
movl   $0x4,0x4(%rsp)
lea    0x4(%rsp),%r9
mov    $0x1001,%edx
xor    %ecx,%ecx
call   1030 <recvfrom@plt>
test   %eax,%eax
js     1143 <udp_receive+0x23>
pop    %rcx
ret
lea    0xeb6(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"recvfrom() failed.\00"
define i32 @udp_receive(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.sockaddr* %3, %struct.sockaddr** %9
store i32 4, i32* %10
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load %struct.sockaddr*, %struct.sockaddr** %9
%15 = call i32 @recvfrom(i32 %12, i8* %13, i32 4097, i32 0, %struct.sockaddr* %14, i32* %10)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %22
20: ; preds = %4
%21 = load i32, i32* %11
store i32 %21, i32* %5
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"recvfrom() failed.\00"
define i32 @udp_receive(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%7 = call i32 @recvfrom(i32 %0, i8* %1, i32 4097, i32 0, %struct.sockaddr* %3, i32* %5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %4, %9
%12 = phi i32 [ -1, %9 ], [ %7, %4 ]
ret i32 %12
}