#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*/ target_si;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname2(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memmove(int /*<<< orphan*/ *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sendto(int, char const *, int, int /*<<< orphan*/, struct sockaddr *, int);
void send_udp_datagram(void *buf, int len, int socket, char *target_host,
                       int target_port) {
  struct sockaddr_in target_si;
  struct hostent *he;
  memset((char *)&target_si, 0, sizeof(target_si));
  target_si.sin_family = AF_INET;
  target_si.sin_port = htons(target_port);
  if (!(he = gethostbyname2(target_host, AF_INET)))
    return;
  memmove(&target_si.sin_addr.s_addr, he->h_addr, he->h_length);
  if (sendto(socket, (const char *)buf, len, 0, (struct sockaddr *)&target_si,
             sizeof(target_si)) == -1)
    return;
}


x86 assembly (clang, -O0):
<send_udp_datagram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1060 <gethostbyname2@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b6 <send_udp_datagram+0x66>
jmp    11f5 <send_udp_datagram+0xa5>
lea    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1070 <memmove@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    11f5 <send_udp_datagram+0xa5>
jmp    11f5 <send_udp_datagram+0xa5>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_udp_datagram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebp
mov    %rcx,%r13
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%r12
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e63(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%esi
mov    %r13,%rdi
call   1060 <gethostbyname2@plt>
test   %rax,%rax
je     11d0 <send_udp_datagram+0x80>
mov    (%rax),%edx
mov    0x4(%rax),%esi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <memmove@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @send_udp_datagram(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.hostent*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = bitcast %struct.sockaddr_in* %11 to i8*
%14 = call i32 @memset(i8* %13, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* %10
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i8*, i8** %9
%21 = load i32, i32* @AF_INET
%22 = call %struct.hostent* @gethostbyname2(i8* %20, i32 %21)
store %struct.hostent* %22, %struct.hostent** %12
%23 = icmp ne %struct.hostent* %22, null
br i1 %23, label %25, label %24
24: ; preds = %5
br label %42
25: ; preds = %5
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
%28 = load %struct.hostent*, %struct.hostent** %12
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.hostent*, %struct.hostent** %12
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @memmove(i32* %27, i32 %30, i32 %33)
%35 = load i32, i32* %8
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%39 = call i32 @sendto(i32 %35, i8* %36, i32 %37, i32 0, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %25
br label %42
42: ; preds = %24, %41, %25
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @send_udp_datagram(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca %struct.sockaddr_in
%7 = bitcast %struct.sockaddr_in* %6 to i8*
%8 = call i32 @memset(i8* %7, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htons(i32 %4)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @AF_INET
%14 = call %struct.hostent* @gethostbyname2(i8* %3, i32 %13)
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %25, label %16
16: ; preds = %5
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @memmove(i32* %17, i32 %19, i32 %21)
%23 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%24 = call i32 @sendto(i32 %2, i8* %0, i32 %1, i32 0, %struct.sockaddr* %23, i32 12)
br label %25
25: ; preds = %16, %5
ret void
}