#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;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ clientport;
typedef int /*<<< orphan*/ clienthostname;
typedef int /*<<< orphan*/ clientaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ NI_DGRAM;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                               int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
TYPE_1__ in6addr_any;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ printf(char *, ...);
unsigned int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                      int *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              void const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  int sockfd;
  int optval;
  struct sockaddr_in6 serveraddr;
  int clientlen;
  struct sockaddr_in6 clientaddr;
  char buf[1024 + 1];
  sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval,
             sizeof(int));
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin6_family = AF_INET6;
  serveraddr.sin6_addr = in6addr_any;
  serveraddr.sin6_port = htons((unsigned short)3540);
  if (bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0)
    error("ERROR on binding");
  clientlen = sizeof(clientaddr);
  unsigned int n;
  char clientipv6str[INET6_ADDRSTRLEN];
  char clienthostname[256];
  char clientport[256];
  while (1) {
    n = recvfrom(sockfd, buf, 1024, 0, (struct sockaddr *)&clientaddr,
                 &clientlen);
    if (n < 0)
      error("ERROR in recvfrom");
    buf[n] = '\0';
    getnameinfo((struct sockaddr *)&clientaddr, sizeof(clientaddr),
                clienthostname, sizeof(clienthostname), clientport,
                sizeof(clientport), NI_DGRAM);
    inet_ntop(AF_INET6, clientaddr.sin6_addr.s6_addr, clientipv6str,
              INET6_ADDRSTRLEN);
    printf("server received datagram from host: %s port: %s (ip: %s)\n",
           clienthostname, clientport, clientipv6str);
    printf("server received %d/%d bytes: %s\n", (unsigned int)strlen(buf), n,
           buf);
  }
  printf("Testing out CMake\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x670,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fb <main+0x4b>
lea    0xe0a(%rip),%rdi
call   10b0 <error@plt>
mov    -0x14(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0xdd4,%edi
call   1060 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    1279 <main+0xc9>
lea    0xda1(%rip),%rdi
call   10b0 <error@plt>
movl   $0xc,-0x2c(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x450(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x668(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x458(%rbp)
jmp    12ba <main+0x10a>
mov    -0x14(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x444(%rbp)
cmpl   $0x0,-0x444(%rbp)
jae    12f7 <main+0x147>
lea    0xd34(%rip),%rdi
call   10b0 <error@plt>
mov    -0x444(%rbp),%eax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x38(%rbp),%rdi
lea    -0x560(%rbp),%rdx
lea    -0x660(%rbp),%r8
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    $0xc,%esi
mov    $0x100,%r9d
sub    $0x10,%rsp
mov    %r9d,%ecx
mov    %eax,(%rsp)
call   1080 <getnameinfo@plt>
mov    -0x668(%rbp),%rdx
add    $0x10,%rsp
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%esi
mov    0x2c80(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    -0x668(%rbp),%rcx
lea    -0x560(%rbp),%rsi
lea    -0x660(%rbp),%rdx
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x440(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
mov    -0x444(%rbp),%edx
lea    -0x440(%rbp),%rcx
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12b5 <main+0x105>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x638,%rsp
mov    0x2dfd(%rip),%r14
mov    (%r14),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f0 <main+0x40>
lea    0xe15(%rip),%rdi
call   10b0 <error@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
lea    -0x44(%rbp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    -0x40(%rbp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    $0xdd4,%edi
call   1060 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    %ebx,%r14d
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    1266 <main+0xb6>
lea    0xdb4(%rip),%rdi
call   10b0 <error@plt>
movl   $0xc,-0x30(%rbp)
mov    0x2d64(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x660(%rbp),%r15
mov    %r14d,-0x2c(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x2c(%rbp),%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x50(%rbp),%r14
mov    %r14,%r8
lea    -0x30(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,%r12d
mov    %eax,%eax
movb   $0x0,-0x660(%rbp,%rax,1)
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
mov    %r14,%rdi
mov    $0xc,%esi
lea    -0x250(%rbp),%r14
mov    %r14,%rdx
mov    $0x100,%ecx
lea    -0x150(%rbp),%rbx
mov    %rbx,%r8
mov    $0x100,%r9d
push   %rax
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%esi
mov    0x2cbd(%rip),%rax
mov    (%rax),%ecx
mov    %r13,%rdx
call   1030 <inet_ntop@plt>
lea    0xcfa(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0xd15(%rip),%rdi
mov    %eax,%esi
mov    %r12d,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12a0 <main+0xf0>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@in6addr_any = global %struct.TYPE_2__ zeroinitializer
@.str.1 = [17 x i8] c"ERROR on binding\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [18 x i8] c"ERROR in recvfrom\00"
@NI_DGRAM = global i32 0
@.str.3 = [58 x i8] c"server received datagram from host: %s port: %s (ip: %s)\0A\00"
@.str.4 = [33 x i8] c"server received %d/%d bytes: %s\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.sockaddr_in6
%9 = alloca i32
%10 = alloca %struct.sockaddr_in6
%11 = alloca [1025 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca [256 x i8]
%16 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* @AF_INET6
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* %6
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = bitcast i32* %7 to i8*
%29 = call i32 @setsockopt(i32 %25, i32 %26, i32 %27, i8* %28, i32 4)
%30 = bitcast %struct.sockaddr_in6* %8 to i8*
%31 = call i32 @bzero(i8* %30, i32 12)
%32 = load i32, i32* @AF_INET6
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 2
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
%35 = bitcast %struct.TYPE_2__* %34 to i8*
%36 = call i32 @htons(i16 zeroext 3540)
%37 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 1
store i32 %36, i32* %37
%38 = load i32, i32* %6
%39 = bitcast %struct.sockaddr_in6* %8 to %struct.sockaddr*
%40 = call i64 @bind(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %24
%43 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %24
store i32 12, i32* %9
%45 = load i32, i32* @INET6_ADDRSTRLEN
%46 = zext i32 %45 to i64
%47 = call i8* @llvm.stacksave()
store i8* %47, i8** %13
%48 = alloca i8, i64 %46
store i64 %46, i64* %14
br label %49
49: ; preds = %59, %44
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %51, i8* %52, i32 1024, i32 0, %struct.sockaddr* %53, i32* %9)
store i32 %54, i32* %12
%55 = load i32, i32* %12
%56 = icmp ult i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %50
%60 = load i32, i32* %12
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 %61
store i8 0, i8* %62
%63 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%66 = load i32, i32* @NI_DGRAM
%67 = call i32 @getnameinfo(%struct.sockaddr* %63, i32 12, i8* %64, i32 256, i8* %65, i32 256, i32 %66)
%68 = load i32, i32* @AF_INET6
%69 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* @INET6_ADDRSTRLEN
%73 = call i32 @inet_ntop(i32 %68, i32 %71, i8* %48, i32 %72)
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %74, i8* %75, i8* %48)
%77 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%78 = call i64 @strlen(i8* %77)
%79 = trunc i64 %78 to i32
%80 = load i32, i32* %12
%81 = getelementptr inbounds [1025 x i8], [1025 x i8]* %11, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %79, i32 %80, i8* %81)
br label %49
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { %struct.TYPE_2__, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@in6addr_any = global %struct.TYPE_2__ zeroinitializer
@.str.1 = [17 x i8] c"ERROR on binding\00"
@INET6_ADDRSTRLEN = global i32 0
@NI_DGRAM = global i32 0
@.str.3 = [58 x i8] c"server received datagram from host: %s port: %s (ip: %s)\0A\00"
@.str.4 = [33 x i8] c"server received %d/%d bytes: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in6
%5 = alloca i32
%6 = alloca %struct.sockaddr_in6
%7 = alloca [1025 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = bitcast i32* %3 to i8*
%11 = bitcast %struct.sockaddr_in6* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast %struct.sockaddr_in6* %6 to i8*
%14 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 0
%15 = load i32, i32* @AF_INET6
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 %17, i32 %22, i32 %23, i8* %10, i32 4)
%25 = call i32 @bzero(i8* %11, i32 12)
%26 = load i32, i32* @AF_INET6
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0, i32 0
%29 = load i32, i32* getelementptr inbounds (%struct.TYPE_2__, %struct.TYPE_2__* @in6addr_any, i64 0, i32 0)
store i32 %29, i32* %28
%30 = call i32 @htons(i16 zeroext 3540)
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
store i32 %30, i32* %31
%32 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%33 = call i64 @bind(i32 %17, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %21
%36 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %21
store i32 12, i32* %5
%38 = load i32, i32* @INET6_ADDRSTRLEN
%39 = zext i32 %38 to i64
%40 = alloca i8, i64 %39
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%43 = bitcast %struct.sockaddr_in6* %6 to %struct.sockaddr*
%44 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 0, i32 0
br label %45
45: ; preds = %45, %37
%46 = call i32 @recvfrom(i32 %17, i8* %14, i32 1024, i32 0, %struct.sockaddr* %43, i32* %5)
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds [1025 x i8], [1025 x i8]* %7, i64 0, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* @NI_DGRAM
%50 = call i32 @getnameinfo(%struct.sockaddr* %43, i32 12, i8* %41, i32 256, i8* %42, i32 256, i32 %49)
%51 = load i32, i32* @AF_INET6
%52 = load i32, i32* %44
%53 = load i32, i32* @INET6_ADDRSTRLEN
%54 = call i32 @inet_ntop(i32 %51, i32 %52, i8* %40, i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %42, i8* %40)
%56 = call i64 @strlen(i8* %14)
%57 = trunc i64 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %57, i32 %46, i8* %14)
br label %45
}