#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_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char *argv[]) {
  char *SERVER_IP = "::1";
  int SERVER_PORT = 6666;
  if (argc > 3)
    printf("param err:\nUsage: %s ip port | %s port | %s\n", argv[0], argv[0],
           argv[0]);
  else if (argc == 3) {
    SERVER_IP = argv[1];
    SERVER_PORT = atoi(argv[2]);
  } else if (argc == 2)
    SERVER_PORT = atoi(argv[1]);
  struct sockaddr_in6 servAddr;
  int cliSocket;
  char *sendbuf = "Hello Server, I am Client / IPv6.";
  if ((cliSocket = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
    printf("socket err");
    exit(1);
  }
  servAddr.sin6_family = AF_INET6;
  servAddr.sin6_port = htons(SERVER_PORT);
  inet_pton(AF_INET6, SERVER_IP, &servAddr.sin6_addr);
  printf("Send data to %s:%d ...\n\n", SERVER_IP, SERVER_PORT);
  while (1) {
    int num = sendto(cliSocket, sendbuf, strlen(sendbuf) + 1, 0,
                     (struct sockaddr *)&servAddr, sizeof(servAddr));
    if (num == strlen(sendbuf) + 1)
      printf("Send: Hello Server, I am IPv6 UDP Client.\nlength:%d\n\n", num);
    else
      printf("send err\n");
    sleep(1);
  }
  close(cliSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1a0a,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    11ea <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1239 <main+0xa9>
cmpl   $0x3,-0x8(%rbp)
jne    1215 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1234 <main+0xa4>
cmpl   $0x2,-0x8(%rbp)
jne    122f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1234 <main+0xa4>
jmp    1239 <main+0xa9>
lea    0xdf1(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1281 <main+0xf1>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <inet_pton@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jne    132f <main+0x19f>
mov    -0x3c(%rbp),%esi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    133d <main+0x1ad>
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    12c3 <main+0x133>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x4,%edi
jl     11d8 <main+0x38>
mov    (%rsi),%rcx
lea    0xe47(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2f(%rip),%r14
mov    $0x1a0a,%ebp
jmp    1203 <main+0x63>
lea    0xe21(%rip),%r14
cmp    $0x2,%edi
je     11f8 <main+0x58>
mov    $0x1a0a,%ebp
cmp    $0x3,%edi
jne    1203 <main+0x63>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
jmp    11fc <main+0x5c>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x2dd6(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12d2 <main+0x132>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
lea    0x8(%rsp),%r15
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <inet_pton@plt>
lea    0xe0d(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdcd(%rip),%rbp
lea    0xe0c(%rip),%r14
lea    0xe3b(%rip),%r12
jmp    1292 <main+0xf2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    %eax,%ebx
jne    1280 <main+0xe0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1288 <main+0xe8>
lea    0xd7a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"::1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@.str.2 = [34 x i8] c"Hello Server, I am Client / IPv6.\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@.str.5 = [54 x i8] c"Send: Hello Server, I am IPv6 UDP Client.\0Alength:%d\0A\0A\00"
@.str.6 = [10 x i8] c"send err\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in6
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 6666, i32* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %20, i8* %23)
br label %46
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %6
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %7
br label %45
36: ; preds = %25
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %28
br label %46
46: ; preds = %45, %14
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8** %10
%47 = load i32, i32* @AF_INET6
%48 = load i32, i32* @SOCK_DGRAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i32, i32* @AF_INET6
%56 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 2
store i32 %55, i32* %56
%57 = load i32, i32* %7
%58 = call i32 @htons(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 1
store i32 %58, i32* %59
%60 = load i32, i32* @AF_INET6
%61 = load i8*, i8** %6
%62 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
%63 = call i32 @inet_pton(i32 %60, i8* %61, i32* %62)
%64 = load i8*, i8** %6
%65 = load i32, i32* %7
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %64, i32 %65)
br label %67
67: ; preds = %54, %85
%68 = load i32, i32* %9
%69 = load i8*, i8** %10
%70 = load i8*, i8** %10
%71 = call i32 @strlen(i8* %70)
%72 = add nsw i32 %71, 1
%73 = bitcast %struct.sockaddr_in6* %8 to %struct.sockaddr*
%74 = call i32 @sendto(i32 %68, i8* %69, i32 %72, i32 0, %struct.sockaddr* %73, i32 12)
store i32 %74, i32* %11
%75 = load i32, i32* %11
%76 = load i8*, i8** %10
%77 = call i32 @strlen(i8* %76)
%78 = add nsw i32 %77, 1
%79 = icmp eq i32 %75, %78
br i1 %79, label %80, label %83
80: ; preds = %67
%81 = load i32, i32* %11
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %81)
br label %85
83: ; preds = %67
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %85
85: ; preds = %83, %80
%86 = call i32 @sleep(i32 1)
br label %67
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"::1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@.str.2 = [34 x i8] c"Hello Server, I am Client / IPv6.\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@.str.5 = [54 x i8] c"Send: Hello Server, I am IPv6 UDP Client.\0Alength:%d\0A\0A\00"
@str = [9 x i8] c"send err\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in6
%4 = icmp sgt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %6, i8* %6)
br label %19
8: ; preds = %2
switch i32 %0, label %19 [
i32 3, label %9
i32 2, label %15
]
9: ; preds = %8
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
br label %19
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %8, %9, %15, %5
%20 = phi i32 [ 6666, %5 ], [ %14, %9 ], [ %18, %15 ], [ 6666, %8 ]
%21 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %5 ], [ %11, %9 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %8 ]
%22 = bitcast %struct.sockaddr_in6* %3 to i8*
%23 = load i32, i32* @AF_INET6
%24 = load i32, i32* @SOCK_DGRAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i32, i32* @AF_INET6
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = tail call i32 @htons(i32 %20)
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
store i32 %33, i32* %34
%35 = load i32, i32* @AF_INET6
%36 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
%37 = call i32 @inet_pton(i32 %35, i8* %21, i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %21, i32 %20)
%39 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
br label %40
40: ; preds = %51, %30
%41 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%42 = add nsw i32 %41, 1
%43 = call i32 @sendto(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 0, %struct.sockaddr* %39, i32 12)
%44 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%45 = add nsw i32 %44, 1
%46 = icmp eq i32 %43, %45
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %51
49: ; preds = %40
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
%52 = call i32 @sleep(i32 1)
br label %40
}