#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ sendto(int, void *, size_t, int /*<<< orphan*/,
                          struct sockaddr_in *, int);
ssize_t writeToUDP(int fd, void *buf, size_t buflen, uint32_t dip,
                   uint16_t dport) {
  struct sockaddr_in sa;
  sa.sin_addr.s_addr = htonl(dip);
  sa.sin_family = AF_INET;
  sa.sin_port = htons(dport);
  return sendto(fd, buf, buflen, 0, &sa, sizeof(sa));
}


x86 assembly (clang, -O0):
<writeToUDP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToUDP>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    %ecx,%edi
call   1040 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r8
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define i32 @writeToUDP(i32 %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %9
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* %10
%19 = call i32 @htons(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %6
%22 = load i8*, i8** %7
%23 = load i64, i64* %8
%24 = call i32 @sendto(i32 %21, i8* %22, i64 %23, i32 0, %struct.sockaddr_in* %11, i32 12)
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
define i32 @writeToUDP(i32 %0, i8* %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca %struct.sockaddr_in
%7 = bitcast %struct.sockaddr_in* %6 to i8*
%8 = tail call i32 @htonl(i32 %3)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 %4)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %12, i32* %13
%14 = call i32 @sendto(i32 %0, i8* %1, i64 %2, i32 0, %struct.sockaddr_in* %6, i32 12)
ret i32 %14
}