#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ INET6_ADDRSTRLEN;
int /*<<< orphan*/ decrypt_tdes(unsigned char *, unsigned char *);
int /*<<< orphan*/ encrypt_tdes(unsigned char *, unsigned char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                             int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
char *encrypt_ipv6(char *in_string, char *out_string, int encrypt) {
  unsigned char in[64];
  struct in6_addr in_in6, out_in6;
  inet_pton(AF_INET6, in_string, &in_in6);
  unsigned char *buf3 = (unsigned char *)&out_in6;
  memcpy(buf3, (unsigned char *)&in_in6, 8);
  memcpy(in, (unsigned char *)&in_in6 + 8, 8);
  if (encrypt)
    encrypt_tdes(in, buf3 + 8);
  else
    decrypt_tdes(in, buf3 + 8);
  inet_ntop(AF_INET6, &out_in6, out_string, INET6_ADDRSTRLEN);
  return out_string;
}


x86 assembly (clang, -O0):
<encrypt_ipv6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x68(%rbp),%rdx
call   1050 <inet_pton@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
lea    -0x68(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    -0x68(%rbp),%rsi
add    $0x8,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x14(%rbp)
je     11cc <encrypt_ipv6+0x7c>
lea    -0x60(%rbp),%rdi
mov    -0x78(%rbp),%rsi
add    $0x8,%rsi
call   1060 <encrypt_tdes@plt>
jmp    11dd <encrypt_ipv6+0x8d>
lea    -0x60(%rbp),%rdi
mov    -0x78(%rbp),%rsi
add    $0x8,%rsi
call   1070 <decrypt_tdes@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%rsi
call   1030 <inet_ntop@plt>
mov    -0x10(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_ipv6>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e77(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1050 <inet_pton@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
lea    0x10(%rsp),%rsi
lea    0x10(%rsp),%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdi
test   %ebp,%ebp
je     11b2 <encrypt_ipv6+0x62>
call   1060 <encrypt_tdes@plt>
jmp    11b7 <encrypt_ipv6+0x67>
call   1070 <decrypt_tdes@plt>
mov    (%r15),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
mov    %r14,%rdx
call   1030 <inet_ntop@plt>
mov    %r14,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i32 0
@INET6_ADDRSTRLEN = global i32 0
define i8* @encrypt_ipv6(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca %struct.in6_addr
%9 = alloca %struct.in6_addr
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* @AF_INET6
%12 = load i8*, i8** %4
%13 = call i32 @inet_pton(i32 %11, i8* %12, %struct.in6_addr* %8)
%14 = bitcast %struct.in6_addr* %9 to i8*
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = bitcast %struct.in6_addr* %8 to i8*
%17 = call i32 @memcpy(i8* %15, i8* %16, i32 8)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%19 = bitcast %struct.in6_addr* %8 to i8*
%20 = getelementptr inbounds i8, i8* %19, i64 8
%21 = call i32 @memcpy(i8* %18, i8* %20, i32 8)
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = call i32 @encrypt_tdes(i8* %25, i8* %27)
br label %34
29: ; preds = %3
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i64 8
%33 = call i32 @decrypt_tdes(i8* %30, i8* %32)
br label %34
34: ; preds = %29, %24
%35 = load i32, i32* @AF_INET6
%36 = load i8*, i8** %5
%37 = load i32, i32* @INET6_ADDRSTRLEN
%38 = call i32 @inet_ntop(i32 %35, %struct.in6_addr* %9, i8* %36, i32 %37)
%39 = load i8*, i8** %5
ret i8* %39
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i32 0
@INET6_ADDRSTRLEN = global i32 0
define i8* @encrypt_ipv6(i8* %0, i8* returned %1, i32 %2) {
%4 = alloca [64 x i8]
%5 = alloca %struct.in6_addr
%6 = alloca %struct.in6_addr
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.in6_addr* %5 to i8*
%9 = bitcast %struct.in6_addr* %6 to i8*
%10 = load i32, i32* @AF_INET6
%11 = call i32 @inet_pton(i32 %10, i8* %0, %struct.in6_addr* %5)
%12 = call i32 @memcpy(i8* %9, i8* %8, i32 8)
%13 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %5, i64 2
%14 = bitcast %struct.in6_addr* %13 to i8*
%15 = call i32 @memcpy(i8* %7, i8* %14, i32 8)
%16 = icmp eq i32 %2, 0
%17 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %6, i64 2
%18 = bitcast %struct.in6_addr* %17 to i8*
br i1 %16, label %21, label %19
19: ; preds = %3
%20 = call i32 @encrypt_tdes(i8* %7, i8* %18)
br label %23
21: ; preds = %3
%22 = call i32 @decrypt_tdes(i8* %7, i8* %18)
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* @AF_INET6
%25 = load i32, i32* @INET6_ADDRSTRLEN
%26 = call i32 @inet_ntop(i32 %24, %struct.in6_addr* %6, i8* %1, i32 %25)
ret i8* %1
}