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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ IN6_IS_ADDR_UNSPECIFIED(struct in6_addr *);
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                             int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(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, portno;
  socklen_t clilen;
  char buffer[256];
  struct sockaddr_in6 si_me, si_other;
  int slen = sizeof(struct sockaddr_in6);
  int n;
  char client_addr_ipv6[100];
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <listening port>\n", argv[0]);
    exit(0);
  }
  printf("\nIPv6 UDP Server Started...\n");
  sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
  if (sockfd < 0)
    error("ERROR opening socket");
  bzero((char *)&si_me, sizeof(si_me));
  portno = atoi(argv[1]);
  struct in6_addr s6 = {};
  if (!IN6_IS_ADDR_UNSPECIFIED(&s6))
    inet_pton(AF_INET6, "fe80::2e1:ff:fe00:119f", &s6);
  si_me.sin6_family = AF_INET6;
  si_me.sin6_addr = s6;
  si_me.sin6_port = htons(portno);
  si_me.sin6_flowinfo = 0;
  if (bind(sockfd, (struct sockaddr *)&si_me, sizeof(si_me)) < 0)
    error("ERROR on binding");
  n = recvfrom(sockfd, buffer, 255, 0, (struct sockaddr *)&si_other, &slen);
  if (n < 0)
    error("ERROR reading from socket");
  inet_ntop(AF_INET6, &(si_other.sin6_addr), client_addr_ipv6, 100);
  printf("Incoming connection from client having address: %s\n",
         client_addr_ipv6);
  printf("Message from client: %s\n", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x18,-0x154(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1240 <main+0x50>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdcc(%rip),%rsi
call   1080 <fprintf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1287 <main+0x97>
lea    0xdb7(%rip),%rdi
call   10c0 <error@plt>
lea    -0x138(%rbp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    -0x1c8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x1c8(%rbp),%rdi
call   10f0 <IN6_IS_ADDR_UNSPECIFIED@plt>
cmp    $0x0,%eax
jne    12ec <main+0xfc>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
lea    -0x1c8(%rbp),%rdx
call   1090 <inet_pton@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
mov    -0x1c8(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x128(%rbp)
movq   $0x0,-0x130(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x138(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    134a <main+0x15a>
lea    0xd20(%rip),%rdi
call   10c0 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x150(%rbp),%r8
mov    $0xff,%edx
xor    %ecx,%ecx
lea    -0x154(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x158(%rbp)
cmpl   $0x0,-0x158(%rbp)
jge    138d <main+0x19d>
lea    0xcee(%rip),%rdi
call   10c0 <error@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
lea    -0x1c0(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
lea    -0x1c0(%rbp),%rsi
lea    0xcd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1b8,%rsp
mov    %rsi,%r14
movl   $0x18,0xc(%rsp)
cmp    $0x1,%edi
jle    1361 <main+0x171>
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dbc(%rip),%r15
mov    (%r15),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1250 <main+0x60>
lea    0xdd1(%rip),%rdi
call   10c0 <error@plt>
lea    0x10(%rsp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    0x8(%r14),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   10f0 <IN6_IS_ADDR_UNSPECIFIED@plt>
test   %eax,%eax
jne    1294 <main+0xa4>
mov    (%r15),%edi
lea    0xda7(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1090 <inet_pton@plt>
mov    (%r15),%eax
mov    %eax,0x24(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x18,%edx
call   10b0 <bind@plt>
test   %rax,%rax
jns    12d9 <main+0xe9>
lea    0xd74(%rip),%rdi
call   10c0 <error@plt>
lea    0xb0(%rsp),%rsi
lea    0x28(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
test   %eax,%eax
jns    1309 <main+0x119>
lea    0xd55(%rip),%rdi
call   10c0 <error@plt>
mov    (%r15),%edi
lea    0x28(%rsp),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdx
mov    $0x64,%ecx
call   1030 <inet_ntop@plt>
lea    0xd49(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd6c(%rip),%rdi
lea    0xb0(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xc8c(%rip),%rsi
call   1080 <fprintf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { %struct.in6_addr, i64, i32, i32 }
%struct.in6_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s <listening port>\0A\00"
@.str.1 = [29 x i8] c"\0AIPv6 UDP Server 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 = [23 x i8] c"fe80::2e1:ff:fe00:119f\00"
@.str.4 = [17 x i8] c"ERROR on binding\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
@.str.6 = [52 x i8] c"Incoming connection from client having address: %s\0A\00"
@.str.7 = [25 x i8] c"Message from client: %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 i32
%9 = alloca [256 x i8]
%10 = alloca %struct.sockaddr_in6
%11 = alloca %struct.sockaddr_in6
%12 = alloca i32
%13 = alloca i32
%14 = alloca [100 x i8]
%15 = alloca %struct.in6_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 24, i32* %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @AF_INET6
%28 = load i32, i32* @SOCK_DGRAM
%29 = load i32, i32* @IPPROTO_UDP
%30 = call i32 @socket(i32 %27, i32 %28, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %25
%36 = bitcast %struct.sockaddr_in6* %10 to i8*
%37 = call i32 @bzero(i8* %36, i32 24)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %7
%42 = bitcast %struct.in6_addr* %15 to i8*
%43 = call i32 @IN6_IS_ADDR_UNSPECIFIED(%struct.in6_addr* %15)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %35
%46 = load i32, i32* @AF_INET6
%47 = call i32 @inet_pton(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %struct.in6_addr* %15)
br label %48
48: ; preds = %45, %35
%49 = load i32, i32* @AF_INET6
%50 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 3
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
%52 = bitcast %struct.in6_addr* %51 to i8*
%53 = bitcast %struct.in6_addr* %15 to i8*
%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 = load i32, i32* %6
%59 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%60 = call i64 @bind(i32 %58, %struct.sockaddr* %59, i32 24)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %48
%63 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %48
%65 = load i32, i32* %6
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%67 = bitcast %struct.sockaddr_in6* %11 to %struct.sockaddr*
%68 = call i32 @recvfrom(i32 %65, i8* %66, i32 255, i32 0, %struct.sockaddr* %67, i32* %12)
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %64
%72 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %73
73: ; preds = %71, %64
%74 = load i32, i32* @AF_INET6
%75 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 0
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%77 = call i32 @inet_ntop(i32 %74, %struct.in6_addr* %75, i8* %76, i32 100)
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i8* %78)
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %80)
%82 = load i32, i32* %6
%83 = call i32 @close(i32 %82)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { %struct.in6_addr, i64, i32, i32 }
%struct.in6_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s <listening 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 = [23 x i8] c"fe80::2e1:ff:fe00:119f\00"
@.str.4 = [17 x i8] c"ERROR on binding\00"
@.str.5 = [26 x i8] c"ERROR reading from socket\00"
@.str.6 = [52 x i8] c"Incoming connection from client having address: %s\0A\00"
@.str.7 = [25 x i8] c"Message from client: %s\0A\00"
@str = [28 x i8] c"\0AIPv6 UDP Server Started...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.sockaddr_in6
%5 = alloca %struct.sockaddr_in6
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca %struct.in6_addr
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in6* %4 to i8*
%11 = bitcast %struct.sockaddr_in6* %5 to i8*
%12 = bitcast i32* %6 to i8*
store i32 24, i32* %6
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%14 = icmp slt i32 %0, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%22 = load i32, i32* @AF_INET6
%23 = load i32, i32* @SOCK_DGRAM
%24 = load i32, i32* @IPPROTO_UDP
%25 = tail call i32 @socket(i32 %22, i32 %23, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
%30 = call i32 @bzero(i8* %10, i32 24)
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i32 @atoi(i8* %32)
%34 = bitcast %struct.in6_addr* %8 to i8*
%35 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %8, i64 0, i32 0
store i32 0, i32* %35
%36 = call i32 @IN6_IS_ADDR_UNSPECIFIED(%struct.in6_addr* %8)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = load i32, i32* @AF_INET6
%40 = call i32 @inet_pton(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %struct.in6_addr* %8)
br label %41
41: ; preds = %38, %29
%42 = load i32, i32* @AF_INET6
%43 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 3
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0, i32 0
%45 = load i32, i32* %35
store i32 %45, i32* %44
%46 = call i32 @htons(i32 %33)
%47 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
store i64 0, i64* %48
%49 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%50 = call i64 @bind(i32 %25, %struct.sockaddr* %49, i32 24)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %41
%53 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %41
%55 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%56 = call i32 @recvfrom(i32 %25, i8* %9, i32 255, i32 0, %struct.sockaddr* %55, i32* %6)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
%61 = load i32, i32* @AF_INET6
%62 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 0
%63 = call i32 @inet_ntop(i32 %61, %struct.in6_addr* %62, i8* %13, i32 100)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %9)
%66 = call i32 @close(i32 %25)
ret i32 0
}