#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct stat {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ remoteAddress;
typedef int /*<<< orphan*/ in_port_t;
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
size_t sendto(int, void *, size_t, int /*<<< orphan*/, struct sockaddr const *,
              int);
size_t udpSend(int udpSocket, in_addr_t address, in_port_t port, void *message,
               size_t messageSize) {
  struct stat info;
  if (fstat(udpSocket, &info) != 0) {
    perror("Descriptor is invalid.");
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in remoteAddress;
  memset(&remoteAddress, 0, sizeof(remoteAddress));
  remoteAddress.sin_family = AF_INET;
  remoteAddress.sin_addr.s_addr = address;
  remoteAddress.sin_port = htons(port);
  ssize_t numberOfBytesSend =
      sendto(udpSocket, message, messageSize, 0,
             (const struct sockaddr *)&remoteAddress, sizeof(remoteAddress));
  return numberOfBytesSend;
}


x86 assembly (clang, -O0):
<udpSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
je     11a9 <udpSend+0x49>
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpSend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x10(%rsp),%rsi
call   1080 <fstat@plt>
test   %rax,%rax
jne    11df <udpSend+0x7f>
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,0x4(%rsp)
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"Descriptor is invalid.\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
define i64 @udpSend(i32 %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.stat
%12 = alloca %struct.sockaddr_in
%13 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%14 = load i32, i32* %6
%15 = call i64 @fstat(i32 %14, %struct.stat* %11)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %5
%18 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %5
%22 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %7
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %8
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = load i8*, i8** %9
%33 = load i64, i64* %10
%34 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%35 = call i64 @sendto(i32 %31, i8* %32, i64 %33, i32 0, %struct.sockaddr* %34, i32 12)
store i64 %35, i64* %13
%36 = load i64, i64* %13
ret i64 %36
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"Descriptor is invalid.\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
define i64 @udpSend(i32 %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca %struct.stat
%7 = alloca %struct.sockaddr_in
%8 = bitcast %struct.stat* %6 to i8*
%9 = call i64 @fstat(i32 %0, %struct.stat* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %5
%16 = bitcast %struct.sockaddr_in* %7 to i8*
%17 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %1, i32* %20
%21 = call i32 @htons(i32 %2)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%24 = call i64 @sendto(i32 %0, i8* %3, i64 %4, i32 0, %struct.sockaddr* %23, i32 12)
ret i64 %24
}