#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;
};
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int recvfrom(int, void *, size_t, int /*<<< orphan*/, struct sockaddr *, int *);
ssize_t sock_recvfrom(int sockfd, void *buf, size_t len) {
  struct sockaddr_in addr;
  socklen_t addrlen = sizeof(addr);
  ssize_t rbytes;
  rbytes = recvfrom(sockfd, buf, len, 0, (struct sockaddr *)&addr, &addrlen);
  if (rbytes == -1) {
    perror("recvfrom");
    return -1;
  }
  return rbytes;
}


x86 assembly (clang, -O0):
<sock_recvfrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1179 <sock_recvfrom+0x59>
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <sock_recvfrom+0x5f>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_recvfrom>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
xor    %ecx,%ecx
call   1030 <recvfrom@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     114d <sock_recvfrom+0x2d>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xeac(%rip),%rdi
call   1040 <perror@plt>
jmp    1145 <sock_recvfrom+0x25>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"recvfrom\00"
define i32 @sock_recvfrom(i32 %0, i8* %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 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @recvfrom(i32 %0, i8* %1, i64 %2, i32 0, %struct.sockaddr* %8, i32* %5)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %3, %11
ret i32 %9
}