#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*/ s6_addr;
};
struct sockaddr_in6 {
  TYPE_1__ sin6_addr;
  scalar_t__ sin6_flowinfo;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname2(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memmove(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int sendto(int, char *, scalar_t__, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd, portno;
  struct hostent *server;
  char buffer[256] = "This is a string from client!";
  struct sockaddr_in6 serv_addr;
  int slen = sizeof(struct sockaddr_in6);
  int n;
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <server adddress> <server port>\n", argv[0]);
    exit(0);
  }
  portno = atoi(argv[2]);
  printf("\nIPv6 UDP Client Started...\n");
  sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
  if (sockfd < 0)
    error("ERROR opening socket");
  server = gethostbyname2(argv[1], AF_INET6);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  memset((char *)&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin6_family = AF_INET6;
  serv_addr.sin6_port = htons(portno);
  serv_addr.sin6_flowinfo = 0;
  memmove((char *)&serv_addr.sin6_addr.s6_addr, (char *)server->h_addr,
          server->h_length);
  n = sendto(sockfd, buffer, strlen(buffer) + 1, 0,
             (struct sockaddr *)&serv_addr, slen);
  if (n < 0)
    error("ERROR writing to socket");
  printf("\nString sent to server...\n");
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x100,%edx
call   10b0 <memcpy@plt>
movl   $0x18,-0x13c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    124a <main+0x6a>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xec4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    0xeca(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    129f <main+0xbf>
lea    0xeae(%rip),%rdi
call   10d0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
call   1090 <gethostbyname2@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12e2 <main+0x102>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    -0x138(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x128(%rbp)
movq   $0x0,-0x130(%rbp)
lea    -0x138(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10c0 <memmove@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x14c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x14c(%rbp),%edi
mov    -0x148(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x138(%rbp),%r8
mov    -0x13c(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x140(%rbp)
cmpl   $0x0,-0x140(%rbp)
jge    13a2 <main+0x1c2>
lea    0xdd5(%rip),%rdi
call   10d0 <error@plt>
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe05(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x100,%edx
call   10b0 <memcpy@plt>
cmp    $0x2,%ebx
jle    1313 <main+0x133>
mov    0x10(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r14d
lea    0xf47(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dae(%rip),%r12
mov    (%r12),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    125f <main+0x7f>
lea    0xed1(%rip),%rdi
call   10d0 <error@plt>
mov    0x8(%rbp),%rdi
mov    (%r12),%esi
call   1090 <gethostbyname2@plt>
test   %rax,%rax
je     1335 <main+0x155>
mov    %rax,%rbp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x1c(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x8(%rbp),%rsi
mov    0x0(%rbp),%edx
mov    %r15,%rdi
call   10c0 <memmove@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x18,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
jns    12ee <main+0x10e>
lea    0xe6c(%rip),%rdi
call   10d0 <error@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xdfb(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in6 = type { %struct.TYPE_2__, i64, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buffer = [256 x i8] c"This is a string from client!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <server adddress> <server port>\0A\00"
@.str.1 = [29 x i8] c"\0AIPv6 UDP Client Started...\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@.str.5 = [27 x i8] c"\0AString sent to server...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.hostent*
%9 = alloca [256 x i8]
%10 = alloca %struct.sockaddr_in6
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [256 x i8]* %9 to i8*
store i32 24, i32* %11
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @AF_INET6
%30 = load i32, i32* @SOCK_DGRAM
%31 = load i32, i32* @IPPROTO_UDP
%32 = call i32 @socket(i32 %29, i32 %30, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %23
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @AF_INET6
%42 = call %struct.hostent* @gethostbyname2(i8* %40, i32 %41)
store %struct.hostent* %42, %struct.hostent** %8
%43 = load %struct.hostent*, %struct.hostent** %8
%44 = icmp eq %struct.hostent* %43, null
br i1 %44, label %45, label %49
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %37
%50 = bitcast %struct.sockaddr_in6* %10 to i8*
%51 = call i32 @memset(i8* %50, i32 0, i32 24)
%52 = load i32, i32* @AF_INET6
%53 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 3
store i32 %52, i32* %53
%54 = load i32, i32* %7
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 2
store i32 %55, i32* %56
%57 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 1
store i64 0, i64* %57
%58 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
%60 = bitcast i32* %59 to i8*
%61 = load %struct.hostent*, %struct.hostent** %8
%62 = getelementptr inbounds %struct.hostent, %struct.hostent* %61, i32 0, i32 1
%63 = load i64, i64* %62
%64 = inttoptr i64 %63 to i8*
%65 = load %struct.hostent*, %struct.hostent** %8
%66 = getelementptr inbounds %struct.hostent, %struct.hostent* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @memmove(i8* %60, i8* %64, i32 %67)
%69 = load i32, i32* %6
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %72, 1
%74 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%75 = load i32, i32* %11
%76 = call i32 @sendto(i32 %69, i8* %70, i64 %73, i32 0, %struct.sockaddr* %74, i32 %75)
store i32 %76, i32* %12
%77 = load i32, i32* %12
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %49
%80 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %79, %49
%82 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { %struct.TYPE_2__, i64, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.main.buffer = [256 x i8] c"This is a string from client!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <server adddress> <server port>\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.4 = [24 x i8] c"ERROR writing to socket\00"
@str = [28 x i8] c"\0AIPv6 UDP Client Started...\00"
@str.6 = [26 x i8] c"\0AString sent to server...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.sockaddr_in6
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in6* %4 to i8*
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @AF_INET6
%19 = load i32, i32* @SOCK_DGRAM
%20 = load i32, i32* @IPPROTO_UDP
%21 = tail call i32 @socket(i32 %18, i32 %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @AF_INET6
%29 = tail call %struct.hostent* @gethostbyname2(i8* %27, i32 %28)
%30 = icmp eq %struct.hostent* %29, null
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 0)
unreachable
35: ; preds = %25
%36 = call i32 @memset(i8* %6, i32 0, i32 24)
%37 = load i32, i32* @AF_INET6
%38 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 3
store i32 %37, i32* %38
%39 = call i32 @htons(i32 %16)
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
store i64 0, i64* %41
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i64 0, i32 1
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to i8*
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i64 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @memmove(i8* %6, i8* %44, i32 %46)
%48 = call i64 @strlen(i8* %5)
%49 = add nsw i64 %48, 1
%50 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%51 = call i32 @sendto(i32 %21, i8* %5, i64 %49, i32 0, %struct.sockaddr* %50, i32 24)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %35
%54 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %35
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%57 = call i32 @close(i32 %21)
ret i32 0
}