#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 {
  scalar_t__ sin6_scope_id;
  scalar_t__ sin6_flowinfo;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ from;
typedef int /*<<< orphan*/ dest;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ sendto(int, char const *, size_t const, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, const char *argv[]) {
  int N = 5;
  int sock = socket(PF_INET6, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("socket");
    return 1;
  }
  while (N > 0) {
    {
      const char msg[] = "No One Expects the IPv6 Inquisition!";
      const size_t len = sizeof(msg);
      struct sockaddr_in6 dest;
      {
        const char *destStr = "7e8e::3";
        if (inet_pton(AF_INET6, destStr, &(dest.sin6_addr)) <= 0) {
          perror("inet_pton");
          return 2;
        }
      }
      dest.sin6_family = AF_INET6;
      dest.sin6_port = htons(9000);
      dest.sin6_flowinfo = 0;
      dest.sin6_scope_id = 0;
      if (sendto(sock, msg, len, 0, (struct sockaddr *)&dest, sizeof(dest)) <
          0) {
        perror("sendto");
        return 3;
      }
    }
    {
      struct sockaddr_in6 from;
      socklen_t fromlen = sizeof(from);
      char buff[1501];
      int actual = recvfrom(sock, buff, sizeof(buff) - 1, 0,
                            (struct sockaddr *)&from, &fromlen);
      if (actual < 0) {
        perror("recvfrom");
        return 4;
      }
      buff[actual] = 0;
      printf("Received: %s\n", buff);
    }
    N--;
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x690,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ee <main+0x5e>
lea    0xe23(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1361 <main+0x1d1>
jmp    11f3 <main+0x63>
cmpl   $0x0,-0x14(%rbp)
jle    1352 <main+0x1c2>
lea    -0x40(%rbp),%rdi
lea    0xe38(%rip),%rsi
mov    $0x25,%edx
call   1070 <memcpy@plt>
movq   $0x25,-0x48(%rbp)
lea    0xde6(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rsi
lea    -0x68(%rbp),%rdx
add    $0x18,%rdx
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
jg     1261 <main+0xd1>
lea    0xdbf(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1361 <main+0x1d1>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    $0x2328,%edi
call   1030 <htons@plt>
mov    %eax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x68(%rbp),%r8
mov    $0x25,%edx
xor    %ecx,%ecx
mov    $0x20,%r9d
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    12c9 <main+0x139>
lea    0xd61(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1361 <main+0x1d1>
movl   $0x20,-0x94(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x680(%rbp),%rsi
lea    -0x90(%rbp),%r8
mov    $0x5dc,%edx
xor    %ecx,%ecx
lea    -0x94(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x684(%rbp)
cmpl   $0x0,-0x684(%rbp)
jge    1322 <main+0x192>
lea    0xd0f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    1361 <main+0x1d1>
movslq -0x684(%rbp),%rax
movb   $0x0,-0x680(%rbp,%rax,1)
lea    -0x680(%rbp),%rsi
lea    0xcea(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f3 <main+0x63>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x690,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     12c6 <main+0x146>
mov    %eax,%ebx
mov    $0x6,%r12d
mov    0x2e17(%rip),%r14
lea    0x30(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0xe67(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movabs $0x216e6f69746973,%rax
mov    %rax,0x4d(%rsp)
mov    (%r14),%edi
lea    0xe06(%rip),%rsi
lea    0x28(%rsp),%rdx
call   1070 <inet_pton@plt>
test   %rax,%rax
jle    12d9 <main+0x159>
mov    (%r14),%eax
mov    %eax,0x24(%rsp)
mov    $0x2328,%edi
call   1030 <htons@plt>
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x25,%edx
mov    %ebx,%edi
mov    %r13,%rsi
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0x20,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
js     12ec <main+0x16c>
movl   $0x20,0xc(%rsp)
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x5dc,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
lea    0xc(%rsp),%r9
call   1080 <recvfrom@plt>
test   %eax,%eax
js     12ff <main+0x17f>
mov    %eax,%eax
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
add    $0xffffffff,%r12d
cmp    $0x1,%r12d
ja     11e0 <main+0x60>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd43(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
jmp    12b2 <main+0x132>
mov    $0x2,%ebx
lea    0xd3a(%rip),%rdi
call   1090 <perror@plt>
jmp    12b2 <main+0x132>
mov    $0x3,%ebx
lea    0xd31(%rip),%rdi
call   1090 <perror@plt>
jmp    12b2 <main+0x132>
lea    0xd2a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x4,%ebx
jmp    12b2 <main+0x132>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i64, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@__const.main.msg = [37 x i8] c"No One Expects the IPv6 Inquisition!\00"
@.str.1 = [8 x i8] c"7e8e::3\00"
@AF_INET6 = global i32 0
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [7 x i8] c"sendto\00"
@.str.4 = [9 x i8] c"recvfrom\00"
@.str.5 = [14 x i8] c"Received: %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 [37 x i8]
%9 = alloca i64
%10 = alloca %struct.sockaddr_in6
%11 = alloca i8*
%12 = alloca %struct.sockaddr_in6
%13 = alloca i32
%14 = alloca [1501 x i8]
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5, i32* %6
%16 = load i32, i32* @PF_INET6
%17 = load i32, i32* @SOCK_DGRAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %70
23: ; preds = %2
br label %24
24: ; preds = %59, %23
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %67
27: ; preds = %24
%28 = bitcast [37 x i8]* %8 to i8*
store i64 37, i64* %9
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %11
%29 = load i32, i32* @AF_INET6
%30 = load i8*, i8** %11
%31 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 4
%32 = call i64 @inet_pton(i32 %29, i8* %30, i32* %31)
%33 = icmp sle i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %70
36: ; preds = %27
%37 = load i32, i32* @AF_INET6
%38 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 3
store i32 %37, i32* %38
%39 = call i32 @htons(i32 9000)
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 2
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 1
store i64 0, i64* %41
%42 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
store i64 0, i64* %42
%43 = load i32, i32* %7
%44 = getelementptr inbounds [37 x i8], [37 x i8]* %8, i64 0, i64 0
%45 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%46 = call i64 @sendto(i32 %43, i8* %44, i64 37, i32 0, %struct.sockaddr* %45, i32 32)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %36
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %70
50: ; preds = %36
store i32 32, i32* %13
%51 = load i32, i32* %7
%52 = getelementptr inbounds [1501 x i8], [1501 x i8]* %14, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in6* %12 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %51, i8* %52, i32 1500, i32 0, %struct.sockaddr* %53, i32* %13)
store i32 %54, i32* %15
%55 = load i32, i32* %15
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 4, i32* %3
br label %70
59: ; preds = %50
%60 = load i32, i32* %15
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1501 x i8], [1501 x i8]* %14, i64 0, i64 %61
store i8 0, i8* %62
%63 = getelementptr inbounds [1501 x i8], [1501 x i8]* %14, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %6
%66 = add nsw i32 %65, -1
store i32 %66, i32* %6
br label %24
67: ; preds = %24
%68 = load i32, i32* %7
%69 = call i32 @close(i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %67, %57, %48, %34, %21
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i64, i64, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@__const.main.msg = [37 x i8] c"No One Expects the IPv6 Inquisition!\00"
@.str.1 = [8 x i8] c"7e8e::3\00"
@AF_INET6 = global i32 0
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [7 x i8] c"sendto\00"
@.str.4 = [9 x i8] c"recvfrom\00"
@.str.5 = [14 x i8] c"Received: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [37 x i8]
%4 = alloca %struct.sockaddr_in6
%5 = alloca %struct.sockaddr_in6
%6 = alloca i32
%7 = alloca [1501 x i8]
%8 = load i32, i32* @PF_INET6
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %2
%13 = getelementptr inbounds [37 x i8], [37 x i8]* %3, i64 0, i64 0
%14 = bitcast %struct.sockaddr_in6* %4 to i8*
%15 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 4
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 3
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
%18 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%19 = bitcast %struct.sockaddr_in6* %5 to i8*
%20 = bitcast i32* %6 to i8*
%21 = getelementptr inbounds [1501 x i8], [1501 x i8]* %7, i64 0, i64 0
%22 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%23 = bitcast %struct.sockaddr_in6* %4 to i8*
br label %26
24: ; preds = %2
%25 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %53
26: ; preds = %12, %45
%27 = phi i32 [ 5, %12 ], [ %49, %45 ]
%28 = load i32, i32* @AF_INET6
%29 = call i64 @inet_pton(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%30 = icmp slt i64 %29, 1
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i32, i32* @AF_INET6
store i32 %32, i32* %16
%33 = call i32 @htons(i32 9000)
store i32 %33, i32* %17
%34 = call i64 @sendto(i32 %10, i8* %13, i64 37, i32 0, %struct.sockaddr* %18, i32 32)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31, %26
%37 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %26 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %31 ]
%38 = phi i32 [ 2, %26 ], [ 3, %31 ]
%39 = call i32 @perror(i8* %37)
br label %53
40: ; preds = %31
store i32 32, i32* %6
%41 = call i32 @recvfrom(i32 %10, i8* %21, i32 1500, i32 0, %struct.sockaddr* %22, i32* %6)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %53
45: ; preds = %40
%46 = zext i32 %41 to i64
%47 = getelementptr inbounds [1501 x i8], [1501 x i8]* %7, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%49 = add nsw i32 %27, -1
%50 = icmp ugt i32 %27, 1
br i1 %50, label %26, label %51
51: ; preds = %45
%52 = call i32 @close(i32 %10)
br label %53
53: ; preds = %43, %36, %51, %24
%54 = phi i32 [ 1, %24 ], [ 0, %51 ], [ %38, %36 ], [ 4, %43 ]
ret i32 %54
}