#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, void *, size_t, int /*<<< orphan*/, struct sockaddr *, int *);
ssize_t safe_recvfrom(int sockfd, void *buf, size_t len,
                      struct sockaddr_in *src_addr) {
  socklen_t src_addr_len = sizeof(*src_addr);
  ssize_t rvalue =
      recvfrom(sockfd, buf, len, 0, (struct sockaddr *)src_addr, &src_addr_len);
  if (rvalue == -1) {
    perror("safe_recvfrom - Failed to recieve");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<safe_recvfrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1030 <recvfrom@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    118f <safe_recvfrom+0x5f>
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_recvfrom>:
push   %rax
mov    %rcx,%r8
movl   $0x4,0x4(%rsp)
lea    0x4(%rsp),%r9
xor    %ecx,%ecx
call   1030 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     114f <safe_recvfrom+0x1f>
pop    %rcx
ret
lea    0xeaa(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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