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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int sendto(int, void const *, size_t, int /*<<< orphan*/, struct sockaddr *,
           int);
ssize_t safe_sendto(int sockfd, const void *buf, size_t len,
                    const struct sockaddr_in *dest_addr) {
  ssize_t rvalue = sendto(sockfd, buf, len, 0, (struct sockaddr *)dest_addr,
                          sizeof(*dest_addr));
  if (rvalue == -1) {
    perror("safe_sendto - Failed to semd");
    exit(EXIT_FAILURE);
  }
  return rvalue;
}


x86 assembly (clang, -O0):
<safe_sendto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    118a <safe_sendto+0x5a>
lea    0xe89(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_sendto>:
push   %rax
mov    %rcx,%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
cmp    $0xffffffff,%eax
je     1148 <safe_sendto+0x18>
pop    %rcx
ret
lea    0xeb1(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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