#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 */
typedef int /*<<< orphan*/ uint8_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ recvfrom(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/,
                    struct sockaddr *, unsigned int *);
size_t client_recv(int sock, uint8_t *data, size_t data_len) {
  ssize_t len;
  struct sockaddr_in addr;
  unsigned int addr_len;
  addr_len = sizeof(addr);
  memset(&addr, 0, sizeof(addr));
  len = recvfrom(sock, data, data_len, 0, (struct sockaddr *)&addr, &addr_len);
  if (len < 0) {
    perror("recvfrom() failed");
    exit(EXIT_FAILURE);
  }
  return len;
}


x86 assembly (clang, -O0):
<client_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11ad <client_recv+0x6d>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_recv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
call   1040 <recvfrom@plt>
test   %rax,%rax
js     1195 <client_recv+0x55>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
@EXIT_FAILURE = global i32 0
define i64 @client_recv(i32 %0, i32* %1, i64 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 4)
%9 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%10 = call i64 @recvfrom(i32 %0, i32* %1, i64 %2, i32 0, %struct.sockaddr* %9, i32* %5)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %3
ret i64 %10
}