#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 /*<<< orphan*/ *s6_addr;
};
typedef int /*<<< orphan*/ ip6;
typedef int /*<<< orphan*/ buf1;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
void *decode64_in6_addr(char *, struct in6_addr *);
void *encode64_in6_addr(struct in6_addr *, char *, int);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                              int);
scalar_t__ memcmp(struct in6_addr *, struct in6_addr *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  printf("encoded_strlen = %d\n", (128 / 6 + 1));
  int i;
  void *ret;
  char ip6[(128 / 6 + 1) + 1];
  struct in6_addr addr;
  srand(time(NULL));
  for (i = 0; i < 16; i++) {
    addr.s6_addr[i] = rand();
    printf("addr[%d] = 0x%hhX\n", i, addr.s6_addr[i]);
  }
  ret = encode64_in6_addr(&addr, ip6, sizeof(ip6));
  if (ret == NULL) {
    printf("encode64_in6_addr failed\n");
    return -1;
  }
  printf("encoded_ip6 = %s\n", ip6);
  char buf[INET6_ADDRSTRLEN];
  if (NULL != inet_ntop(AF_INET6, &addr, buf, sizeof(buf)))
    printf("ip6 address is %s, strlen=%ld\n", buf, strlen(buf));
  struct in6_addr addr1;
  ret = decode64_in6_addr(ip6, &addr1);
  if (ret == NULL) {
    printf("decode64_in6_addr failed\n");
    return -1;
  }
  for (i = 0; i < 16; i++) {
    printf("addr1[%d] = 0x%hhX\n", i, addr1.s6_addr[i]);
  }
  char buf1[INET6_ADDRSTRLEN];
  if (NULL != inet_ntop(AF_INET6, &addr1, buf1, sizeof(buf1)))
    printf("ip6 address is %s, strlen=%ld\n", buf1, strlen(buf1));
  if (memcmp(&addr, &addr1, sizeof(addr)) == 0)
    printf("YES! binary identical\n");
  else
    printf("NO! binary different\n");
  if (strncmp(buf, buf1, sizeof(buf)) == 0)
    printf("YES! text identical\n");
  else
    printf("NO! text different\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
mov    $0x16,%esi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1224 <main+0x84>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%esi
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11dc <main+0x3c>
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdi
mov    $0x17,%edx
call   10b0 <encode64_in6_addr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    125f <main+0xbf>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    144c <main+0x2ac>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
lea    -0x30(%rbp),%rsi
call   1070 <printf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x70(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x48(%rbp)
mov    0x2d38(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%ecx
lea    -0x38(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12e0 <main+0x140>
mov    -0x68(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1050 <decode64_in6_addr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    131d <main+0x17d>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1445 <main+0x2a5>
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    1358 <main+0x1b8>
mov    -0x8(%rbp),%esi
mov    -0x50(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1324 <main+0x184>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x60(%rbp)
mov    0x2c5c(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%ecx
lea    -0x50(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     13bc <main+0x21c>
mov    -0x78(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x38(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x8,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
jne    13eb <main+0x24b>
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13f9 <main+0x259>
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x78(%rbp),%rsi
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rax
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1429 <main+0x289>
lea    0xcb1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1437 <main+0x297>
lea    0xcb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
mov    $0x16,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@.str = [21 x i8] c"encoded_strlen = %d\0A\00"
@.str.1 = [19 x i8] c"addr[%d] = 0x%hhX\0A\00"
@.str.2 = [26 x i8] c"encode64_in6_addr failed\0A\00"
@.str.3 = [18 x i8] c"encoded_ip6 = %s\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str.4 = [31 x i8] c"ip6 address is %s, strlen=%ld\0A\00"
@.str.5 = [26 x i8] c"decode64_in6_addr failed\0A\00"
@.str.6 = [20 x i8] c"addr1[%d] = 0x%hhX\0A\00"
@.str.7 = [23 x i8] c"YES! binary identical\0A\00"
@.str.8 = [22 x i8] c"NO! binary different\0A\00"
@.str.9 = [21 x i8] c"YES! text identical\0A\00"
@.str.10 = [20 x i8] c"NO! text different\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [23 x i8]
%5 = alloca %struct.in6_addr
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.in6_addr
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 22)
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
store i32 0, i32* %2
br label %14
14: ; preds = %32, %0
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 16
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = call i32 (...) @rand()
%19 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%20 = load i32*, i32** %19
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %18, i32* %23
%24 = load i32, i32* %2
%25 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %30)
br label %32
32: ; preds = %17
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %14
35: ; preds = %14
%36 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%37 = call i8* @encode64_in6_addr(%struct.in6_addr* %5, i8* %36, i32 23)
store i8* %37, i8** %3
%38 = load i8*, i8** %3
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %108
42: ; preds = %35
%43 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @INET6_ADDRSTRLEN
%46 = zext i32 %45 to i64
%47 = call i8* @llvm.stacksave()
store i8* %47, i8** %6
%48 = alloca i8, i64 %46
store i64 %46, i64* %7
%49 = load i32, i32* @AF_INET6
%50 = trunc i64 %46 to i32
%51 = call i32* @inet_ntop(i32 %49, %struct.in6_addr* %5, i8* %48, i32 %50)
%52 = icmp ne i32* null, %51
br i1 %52, label %53, label %56
53: ; preds = %42
%54 = call i32 @strlen(i8* %48)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 %54)
br label %56
56: ; preds = %53, %42
%57 = getelementptr inbounds [23 x i8], [23 x i8]* %4, i64 0, i64 0
%58 = call i8* @decode64_in6_addr(i8* %57, %struct.in6_addr* %8)
store i8* %58, i8** %3
%59 = load i8*, i8** %3
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
store i32 1, i32* %9
br label %106
63: ; preds = %56
store i32 0, i32* %2
br label %64
64: ; preds = %76, %63
%65 = load i32, i32* %2
%66 = icmp slt i32 %65, 16
br i1 %66, label %67, label %79
67: ; preds = %64
%68 = load i32, i32* %2
%69 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %8, i32 0, i32 0
%70 = load i32*, i32** %69
%71 = load i32, i32* %2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %68, i32 %74)
br label %76
76: ; preds = %67
%77 = load i32, i32* %2
%78 = add nsw i32 %77, 1
store i32 %78, i32* %2
br label %64
79: ; preds = %64
%80 = load i32, i32* @INET6_ADDRSTRLEN
%81 = zext i32 %80 to i64
%82 = alloca i8, i64 %81
store i64 %81, i64* %10
%83 = load i32, i32* @AF_INET6
%84 = trunc i64 %81 to i32
%85 = call i32* @inet_ntop(i32 %83, %struct.in6_addr* %8, i8* %82, i32 %84)
%86 = icmp ne i32* null, %85
br i1 %86, label %87, label %90
87: ; preds = %79
%88 = call i32 @strlen(i8* %82)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %82, i32 %88)
br label %90
90: ; preds = %87, %79
%91 = call i64 @memcmp(%struct.in6_addr* %5, %struct.in6_addr* %8, i32 8)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %97
95: ; preds = %90
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %97
97: ; preds = %95, %93
%98 = trunc i64 %46 to i32
%99 = call i64 @strncmp(i8* %48, i8* %82, i32 %98)
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %97
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
br label %105
103: ; preds = %97
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %105
105: ; preds = %103, %101
store i32 0, i32* %1
store i32 1, i32* %9
br label %106
106: ; preds = %105, %61
%107 = load i8*, i8** %6
br label %108
108: ; preds = %106, %40
%109 = load i32, i32* %1
ret i32 %109
}

LLVM IR (-O2):
@.str = [21 x i8] c"encoded_strlen = %d\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 22)
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @rand()
unreachable
}