#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 */

/* Type definitions */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int pp_send(char *addr_str, char *data) {
  int s;
  struct addrinfo hints, *res;
  int ret;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET6;
  hints.ai_socktype = SOCK_DGRAM;
  if ((ret = getaddrinfo(addr_str, "6414", &hints, &res)) != 0) {
    puts("ERROR pp_send: getaddrinfo");
    return (-1);
  }
  if ((s = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
    puts("ERROR pp_send: create socket");
    return (-1);
  }
  if ((ret = sendto(s, data, strlen(data), 0, res->ai_addr, res->ai_addrlen)) <
      0) {
    printf("ERROR pp_send: sending data: %d\n", ret);
  }
  freeaddrinfo(res);
  close(s);
  return ret;
}


x86 assembly (clang, -O0):
<pp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
je     1204 <pp_send+0x74>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12aa <pp_send+0x11a>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1242 <pp_send+0xb2>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12aa <pp_send+0x11a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x38(%rbp),%rax
mov    (%rax),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    1293 <pp_send+0x103>
mov    -0x3c(%rbp),%esi
lea    0xdaf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pp_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0xe2d(%rip),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
je     11f8 <pp_send+0x68>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1255 <pp_send+0xc5>
mov    (%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10b0 <socket@plt>
test   %eax,%eax
js     1260 <pp_send+0xd0>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    (%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1245 <pp_send+0xb5>
lea    0xdff(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    (%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdb9(%rip),%rdi
jmp    11ec <pp_send+0x5c>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"6414\00"
@.str.1 = [27 x i8] c"ERROR pp_send: getaddrinfo\00"
@.str.2 = [29 x i8] c"ERROR pp_send: create socket\00"
@.str.3 = [33 x i8] c"ERROR pp_send: sending data: %d\0A\00"
define i32 @pp_send(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 20)
%11 = load i32, i32* @AF_INET6
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_DGRAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %13, i32* %14
%15 = load i8*, i8** %4
%16 = call i32 @getaddrinfo(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %7, %struct.addrinfo** %8)
store i32 %16, i32* %9
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
20: ; preds = %2
%21 = load %struct.addrinfo*, %struct.addrinfo** %8
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 4
%23 = load i32, i32* %22
%24 = load %struct.addrinfo*, %struct.addrinfo** %8
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 3
%26 = load i32, i32* %25
%27 = load %struct.addrinfo*, %struct.addrinfo** %8
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 @socket(i32 %23, i32 %26, i32 %29)
store i32 %30, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
34: ; preds = %20
%35 = load i32, i32* %6
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = load %struct.addrinfo*, %struct.addrinfo** %8
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = load %struct.addrinfo*, %struct.addrinfo** %8
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @sendto(i32 %35, i8* %36, i32 %38, i32 0, i32 %41, i32 %44)
store i32 %45, i32* %9
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %34
%48 = load i32, i32* %9
%49 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %47, %34
%51 = load %struct.addrinfo*, %struct.addrinfo** %8
%52 = call i32 @freeaddrinfo(%struct.addrinfo* %51)
%53 = load i32, i32* %6
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %9
store i32 %55, i32* %3
br label %56
56: ; preds = %50, %32, %18
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [5 x i8] c"6414\00"
@.str.1 = [27 x i8] c"ERROR pp_send: getaddrinfo\00"
@.str.2 = [29 x i8] c"ERROR pp_send: create socket\00"
@.str.3 = [33 x i8] c"ERROR pp_send: sending data: %d\0A\00"
define i32 @pp_send(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%8 = load i32, i32* @AF_INET6
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_DGRAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %43
16: ; preds = %2
%17 = load %struct.addrinfo*, %struct.addrinfo** %4
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @socket(i32 %19, i32 %21, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %43
28: ; preds = %16
%29 = call i32 @strlen(i8* %1)
%30 = load %struct.addrinfo*, %struct.addrinfo** %4
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @sendto(i32 %24, i8* %1, i32 %29, i32 0, i32 %32, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %39
39: ; preds = %37, %28
%40 = load %struct.addrinfo*, %struct.addrinfo** %4
%41 = call i32 @freeaddrinfo(%struct.addrinfo* %40)
%42 = call i32 @close(i32 %24)
br label %43
43: ; preds = %39, %26, %14
%44 = phi i32 [ -1, %14 ], [ -1, %26 ], [ %35, %39 ]
ret i32 %44
}