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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                          struct sockaddr const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(void) {
  char *buffer = "test_udp";
  struct sockaddr_in dest_addr = {0};
  int sd = -1;
  sd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sd == -1) {
    printf("Error: failed to create socket\n");
    exit(0);
  }
  dest_addr.sin_family = AF_INET;
  dest_addr.sin_port = htons(54321);
  inet_aton("192.168.100.1", &dest_addr.sin_addr.s_addr);
  sendto(sd, buffer, strlen(buffer) + 1, 0, (const struct sockaddr *)&dest_addr,
         sizeof(dest_addr));
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x24(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11fa <main+0x6a>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0xd431,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1090 <inet_aton@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e63(%rip),%r14
mov    (%r14),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11f5 <main+0x85>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0xd431,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe4e(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1070 <inet_aton@plt>
lea    0xe33(%rip),%rsi
mov    $0x9,%edx
mov    %ebx,%edi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x10,%r9d
call   1050 <sendto@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"test_udp\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [32 x i8] c"Error: failed to create socket\0A\00"
@.str.2 = [14 x i8] c"192.168.100.1\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = bitcast %struct.sockaddr_in* %3 to i8*
store i32 -1, i32* %4
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 54321)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
%21 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %20)
%22 = load i32, i32* %4
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %25, 1
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @sendto(i32 %22, i8* %23, i64 %26, i32 0, %struct.sockaddr* %27, i32 16)
%29 = load i32, i32* %4
%30 = call i32 @close(i32 %29)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"test_udp\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [14 x i8] c"192.168.100.1\00"
@str = [31 x i8] c"Error: failed to create socket\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 54321)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
%16 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @sendto(i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 9, i32 0, %struct.sockaddr* %17, i32 16)
%19 = call i32 @close(i32 %5)
ret i32 0
}