#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*/ u_short;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  void *sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int /*<<< orphan*/);
scalar_t__ inet_aton(char const *, TYPE_1__ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int udp_send(char *data, int len, const char *addr, int port) {
  int n;
  int sock;
  struct sockaddr_in serv_addr;
  struct sockaddr_in cli_addr;
  memset((char *)&cli_addr, 0, sizeof(cli_addr));
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  if (inet_aton(addr, &serv_addr.sin_addr) == 0) {
    return -1;
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock == -1) {
    return -1;
  }
  cli_addr.sin_family = AF_INET;
  cli_addr.sin_port = htons((u_short)1234);
  cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(sock, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons((u_short)port);
  n = sendto(sock, data, len, 0, (struct sockaddr *)&serv_addr,
             sizeof(serv_addr));
  close(sock);
  return n;
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x48(%rbp),%rsi
add    $0x10,%rsi
call   1080 <inet_aton@plt>
cmp    $0x0,%rax
jne    11dd <udp_send+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <udp_send+0x114>
mov    0x2e04(%rip),%rax
mov    (%rax),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1210 <udp_send+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <udp_send+0x114>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %rax,-0x60(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x50(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x18,%edx
call   1090 <bind@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x48(%rbp),%r8
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <inet_aton@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     126d <udp_send+0xed>
mov    0x2e0a(%rip),%r13
mov    0x0(%r13),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     126d <udp_send+0xed>
mov    %eax,%ebx
mov    0x0(%r13),%rax
mov    %rax,0x10(%rsp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %rax,0x8(%rsp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x18(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   1090 <bind@plt>
mov    0x0(%r13),%rax
mov    %rax,0x28(%rsp)
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%r8
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1060 <sendto@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1070 <close@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
define i32 @udp_send(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = bitcast %struct.sockaddr_in* %13 to i8*
%15 = call i32 @memset(i8* %14, i32 0, i32 24)
%16 = bitcast %struct.sockaddr_in* %12 to i8*
%17 = call i32 @memset(i8* %16, i32 0, i32 24)
%18 = load i8*, i8** %8
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
%20 = call i64 @inet_aton(i8* %18, %struct.TYPE_2__* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %4
store i32 -1, i32* %5
br label %55
23: ; preds = %4
%24 = load i8*, i8** @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i8* %24, i32 %25, i32 0)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -1, i32* %5
br label %55
30: ; preds = %23
%31 = load i8*, i8** @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i8* %31, i8** %32
%33 = call i8* @htons(i32 1234)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i8* %33, i8** %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load i32, i32* %11
%40 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%41 = call i32 @bind(i32 %39, %struct.sockaddr* %40, i32 24)
%42 = load i8*, i8** @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i8* %42, i8** %43
%44 = load i32, i32* %9
%45 = call i8* @htons(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i8* %45, i8** %46
%47 = load i32, i32* %11
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%51 = call i32 @sendto(i32 %47, i8* %48, i32 %49, i32 0, %struct.sockaddr* %50, i32 24)
store i32 %51, i32* %10
%52 = load i32, i32* %11
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %10
store i32 %54, i32* %5
br label %55
55: ; preds = %30, %29, %22
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i8*, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
define i32 @udp_send(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = bitcast %struct.sockaddr_in* %6 to i8*
%9 = call i32 @memset(i8* %8, i32 0, i32 24)
%10 = call i32 @memset(i8* %7, i32 0, i32 24)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
%12 = call i64 @inet_aton(i8* %2, %struct.TYPE_2__* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %36, label %14
14: ; preds = %4
%15 = load i8*, i8** @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i8* %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %36, label %19
19: ; preds = %14
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i8* %20, i8** %21
%22 = call i8* @htons(i32 1234)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i8* %22, i8** %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%28 = call i32 @bind(i32 %17, %struct.sockaddr* %27, i32 24)
%29 = load i8*, i8** @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %29, i8** %30
%31 = call i8* @htons(i32 %3)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i8* %31, i8** %32
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %17, i8* %0, i32 %1, i32 0, %struct.sockaddr* %33, i32 24)
%35 = call i32 @close(i32 %17)
br label %36
36: ; preds = %14, %4, %19
%37 = phi i32 [ %34, %19 ], [ -1, %4 ], [ -1, %14 ]
ret i32 %37
}