#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 sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ payload;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void udpClient6(char *serverIPv6, char *payload, int port) {
  int sock;
  socklen_t clilen;
  struct sockaddr_in6 server_addr, client_addr;
  char buffer[1024];
  char addrbuf[INET6_ADDRSTRLEN];
  sock = socket(PF_INET6, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("creating socket");
    exit(1);
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin6_family = AF_INET6;
  inet_pton(AF_INET6, serverIPv6, &server_addr.sin6_addr);
  char *sep_ip;
  char last_segment[20];
  printf("IPv6 address of the server: %s\n", serverIPv6);
  server_addr.sin6_port = htons(port);
  printf("sending back to: %s - using port %d\n", serverIPv6, port);
  if (sendto(sock, payload, sizeof(payload), 0, (struct sockaddr *)&server_addr,
             sizeof(server_addr)) < 0) {
    perror("sendto failed");
    exit(4);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<udpClient6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x448(%rbp)
mov    %rax,-0x450(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11fc <udpClient6+0x6c>
lea    0xe13(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
call   1080 <inet_pton@plt>
mov    -0x8(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x8,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    12a1 <udpClient6+0x111>
lea    0xdc3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x448(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpClient6>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rsp,%r13
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1264 <udpClient6+0xd4>
mov    %eax,%ebx
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x10(%rsp)
lea    0xc(%rsp),%rdx
mov    %rbp,%rsi
call   1080 <inet_pton@plt>
lea    0xe0e(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xe11(%rip),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
js     127a <udpClient6+0xea>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r13,%rsp
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd95(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdd4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@AF_INET6 = global i32 0
@.str.1 = [32 x i8] c"IPv6 address of the server: %s\0A\00"
@.str.2 = [37 x i8] c"sending back to: %s - using port %d\0A\00"
@.str.3 = [14 x i8] c"sendto failed\00"
define void @udpClient6(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in6
%10 = alloca %struct.sockaddr_in6
%11 = alloca [1024 x i8]
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca [20 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%16 = load i32, i32* @INET6_ADDRSTRLEN
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %12
%19 = alloca i8, i64 %17
store i64 %17, i64* %13
%20 = load i32, i32* @PF_INET6
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %3
%29 = call i32 @memset(%struct.sockaddr_in6* %9, i32 0, i32 12)
%30 = load i32, i32* @AF_INET6
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @AF_INET6
%33 = load i8*, i8** %4
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 1
%35 = call i32 @inet_pton(i32 %32, i8* %33, i32* %34)
%36 = load i8*, i8** %4
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %6
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i8*, i8** %4
%42 = load i32, i32* %6
%43 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i32, i32* %7
%45 = load i8*, i8** %5
%46 = bitcast %struct.sockaddr_in6* %9 to %struct.sockaddr*
%47 = call i64 @sendto(i32 %44, i8* %45, i32 8, i32 0, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %28
%50 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 4)
unreachable
52: ; preds = %28
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = load i8*, i8** %12
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@AF_INET6 = global i32 0
@.str.1 = [32 x i8] c"IPv6 address of the server: %s\0A\00"
@.str.2 = [37 x i8] c"sending back to: %s - using port %d\0A\00"
@.str.3 = [14 x i8] c"sendto failed\00"
define void @udpClient6(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in6
%5 = bitcast %struct.sockaddr_in6* %4 to i8*
%6 = tail call i8* @llvm.stacksave()
%7 = load i32, i32* @PF_INET6
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = call i32 @memset(%struct.sockaddr_in6* %4, i32 0, i32 12)
%16 = load i32, i32* @AF_INET6
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
%19 = call i32 @inet_pton(i32 %16, i8* %0, i32* %18)
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = call i32 @htons(i32 %2)
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
store i32 %21, i32* %22
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %2)
%24 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%25 = call i64 @sendto(i32 %9, i8* %1, i32 8, i32 0, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %14
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @exit(i32 4)
unreachable
30: ; preds = %14
%31 = call i32 @close(i32 %9)
ret void
}