#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 {
  void *sin6_family;
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin_family;
  void *sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr_in {
  void *sin6_family;
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin_family;
  void *sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr6;
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in6 *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *htons(int);
scalar_t__ inet_pton(void *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int sockfd;
  char buf[512];
  if (argc != 2) {
    printf("Usage : %s <Server-IP>\n", argv[0]);
    exit(0);
  }
  struct sockaddr_in serv_addr;
  struct sockaddr_in6 serv_addr6;
  bzero(&serv_addr, sizeof(serv_addr));
  bzero(&serv_addr6, sizeof(serv_addr6));
  if (inet_pton(AF_INET, argv[1], &serv_addr.sin_addr) != 0) {
    serv_addr.sin_port = htons(88);
    if ((sockfd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1)
      err("socket");
    serv_addr.sin_family = AF_INET;
    printf("IPv4 address\n");
    if (sendto(sockfd, buf, 512, 0, (struct sockaddr *)&serv_addr,
               sizeof(serv_addr)) == -1)
      err("sendto()");
  } else if (inet_pton(AF_INET6, argv[1], &serv_addr6.sin6_addr) != 0) {
    serv_addr6.sin6_port = htons(88);
    if ((sockfd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1)
      err("socket");
    serv_addr6.sin6_family = AF_INET6;
    printf("IPv6 address\n");
    if (sendto(sockfd, buf, 512, 0, (struct sockaddr *)&serv_addr6,
               sizeof(serv_addr6)) == -1)
      err("sendto()");
  } else {
    fprintf(stderr,
            "Address not recognised. IPv4 and IPv6 addresses are valid\n");
    exit(1);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11df <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x250(%rbp),%rdi
mov    $0x30,%esi
call   10a0 <bzero@plt>
lea    -0x280(%rbp),%rdi
mov    $0x30,%esi
call   10a0 <bzero@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x250(%rbp),%rdx
add    $0x28,%rdx
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
je     12d2 <main+0x132>
mov    $0x58,%edi
call   1030 <htons@plt>
mov    %rax,-0x230(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1276 <main+0xd6>
lea    0xda7(%rip),%rdi
call   1090 <err@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x238(%rbp)
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x250(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x30,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12cd <main+0x12d>
lea    0xd65(%rip),%rdi
call   1090 <err@plt>
jmp    13c7 <main+0x227>
mov    0x2cf7(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x280(%rbp),%rdx
add    $0x10,%rdx
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
je     13a3 <main+0x203>
mov    $0x58,%edi
call   1030 <htons@plt>
mov    %rax,-0x278(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
mov    0x2c88(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1347 <main+0x1a7>
lea    0xcd6(%rip),%rdi
call   1090 <err@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x280(%rbp)
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x280(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x30,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    139e <main+0x1fe>
lea    0xc94(%rip),%rdi
call   1090 <err@plt>
jmp    13c2 <main+0x222>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    0xc91(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    13c7 <main+0x227>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x268,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1318 <main+0x168>
lea    0x30(%rsp),%rdi
mov    $0x30,%esi
call   10b0 <bzero@plt>
mov    %rsp,%rdi
mov    $0x30,%esi
call   10b0 <bzero@plt>
mov    0x2df7(%rip),%r14
mov    (%r14),%rdi
mov    0x8(%rbx),%rsi
lea    0x58(%rsp),%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
je     1261 <main+0xb1>
mov    $0x58,%edi
call   1040 <htons@plt>
mov    %rax,0x50(%rsp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1241 <main+0x91>
lea    0xddc(%rip),%rdi
call   10a0 <err@plt>
mov    (%r14),%rax
mov    %rax,0x48(%rsp)
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%rsi
lea    0x30(%rsp),%r8
jmp    12df <main+0x12f>
mov    0x2d68(%rip),%r14
mov    (%r14),%rdi
mov    0x8(%rbx),%rsi
lea    0x10(%rsp),%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
je     1330 <main+0x180>
mov    $0x58,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rsp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    12c4 <main+0x114>
lea    0xd59(%rip),%rdi
call   10a0 <err@plt>
mov    (%r14),%rax
mov    %rax,(%rsp)
lea    0xd91(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%rsi
mov    %rsp,%r8
mov    %ebx,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x30,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1304 <main+0x154>
lea    0xd20(%rip),%rdi
call   10a0 <err@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rsi
lea    0xcde(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
lea    0xce8(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i8*, i32, i8*, i8*, i32 }
%struct.sockaddr_in6 = type { i8*, i8*, i32, i8*, i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Usage : %s <Server-IP>\0A\00"
@AF_INET = global i8* null
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"IPv4 address\0A\00"
@.str.3 = [9 x i8] c"sendto()\00"
@AF_INET6 = global i8* null
@.str.4 = [14 x i8] c"IPv6 address\0A\00"
@stderr = global i32 0
@.str.5 = [59 x i8] c"Address not recognised. IPv4 and IPv6 addresses are valid\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in6
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr_in6*
%20 = call i32 @bzero(%struct.sockaddr_in6* %19, i32 48)
%21 = call i32 @bzero(%struct.sockaddr_in6* %9, i32 48)
%22 = load i8*, i8** @AF_INET
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 5
%27 = call i64 @inet_pton(i8* %22, i8* %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %51
29: ; preds = %18
%30 = call i8* @htons(i32 88)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 4
store i8* %30, i8** %31
%32 = load i32, i32* @PF_INET6
%33 = load i32, i32* @SOCK_DGRAM
%34 = load i32, i32* @IPPROTO_UDP
%35 = call i32 @socket(i32 %32, i32 %33, i32 %34)
store i32 %35, i32* %6
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %29
%40 = load i8*, i8** @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i8* %40, i8** %41
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%45 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%46 = call i32 @sendto(i32 %43, i8* %44, i32 512, i32 0, %struct.sockaddr* %45, i32 48)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %39
br label %86
51: ; preds = %18
%52 = load i8*, i8** @AF_INET6
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 2
%57 = call i64 @inet_pton(i8* %52, i8* %55, i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %81
59: ; preds = %51
%60 = call i8* @htons(i32 88)
%61 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 1
store i8* %60, i8** %61
%62 = load i32, i32* @PF_INET6
%63 = load i32, i32* @SOCK_DGRAM
%64 = load i32, i32* @IPPROTO_UDP
%65 = call i32 @socket(i32 %62, i32 %63, i32 %64)
store i32 %65, i32* %6
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %59
%68 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %67, %59
%70 = load i8*, i8** @AF_INET6
%71 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %9, i32 0, i32 0
store i8* %70, i8** %71
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32, i32* %6
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%75 = bitcast %struct.sockaddr_in6* %9 to %struct.sockaddr*
%76 = call i32 @sendto(i32 %73, i8* %74, i32 512, i32 0, %struct.sockaddr* %75, i32 48)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %80
78: ; preds = %69
%79 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %80
80: ; preds = %78, %69
br label %85
81: ; preds = %51
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %80
br label %86
86: ; preds = %85, %50
%87 = load i32, i32* %6
%88 = call i32 @close(i32 %87)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i8*, i32, i8*, i8*, i32 }
%struct.sockaddr_in6 = type { i8*, i8*, i32, i8*, i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Usage : %s <Server-IP>\0A\00"
@AF_INET = global i8* null
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.3 = [9 x i8] c"sendto()\00"
@AF_INET6 = global i8* null
@stderr = global i32 0
@.str.5 = [59 x i8] c"Address not recognised. IPv4 and IPv6 addresses are valid\0A\00"
@str = [13 x i8] c"IPv6 address\00"
@str.6 = [13 x i8] c"IPv4 address\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in6
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = bitcast %struct.sockaddr_in* %4 to i8*
%14 = bitcast %struct.sockaddr_in6* %5 to i8*
%15 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr_in6*
%16 = call i32 @bzero(%struct.sockaddr_in6* %15, i32 48)
%17 = call i32 @bzero(%struct.sockaddr_in6* %5, i32 48)
%18 = load i8*, i8** @AF_INET
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 5
%22 = call i64 @inet_pton(i8* %18, i8* %20, i32* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %41, label %24
24: ; preds = %12
%25 = call i8* @htons(i32 88)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 4
store i8* %25, i8** %26
%27 = load i32, i32* @PF_INET6
%28 = load i32, i32* @SOCK_DGRAM
%29 = load i32, i32* @IPPROTO_UDP
%30 = call i32 @socket(i32 %27, i32 %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %24
%35 = load i8*, i8** @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i8* %35, i8** %36
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i32 @sendto(i32 %30, i8* %6, i32 512, i32 0, %struct.sockaddr* %38, i32 48)
%40 = icmp eq i32 %39, -1
br i1 %40, label %68, label %71
41: ; preds = %12
%42 = load i8*, i8** @AF_INET6
%43 = load i8*, i8** %19
%44 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 2
%45 = call i64 @inet_pton(i8* %42, i8* %43, i32* %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %64, label %47
47: ; preds = %41
%48 = call i8* @htons(i32 88)
%49 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 1
store i8* %48, i8** %49
%50 = load i32, i32* @PF_INET6
%51 = load i32, i32* @SOCK_DGRAM
%52 = load i32, i32* @IPPROTO_UDP
%53 = call i32 @socket(i32 %50, i32 %51, i32 %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = call i32 @err(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %47
%58 = load i8*, i8** @AF_INET6
%59 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 0
store i8* %58, i8** %59
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%61 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%62 = call i32 @sendto(i32 %53, i8* %6, i32 512, i32 0, %struct.sockaddr* %61, i32 48)
%63 = icmp eq i32 %62, -1
br i1 %63, label %68, label %71
64: ; preds = %41
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %57, %34
%69 = phi i32 [ %30, %34 ], [ %53, %57 ]
%70 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %68, %57, %34
%72 = phi i32 [ %30, %34 ], [ %53, %57 ], [ %69, %68 ]
%73 = call i32 @close(i32 %72)
ret i32 0
}