#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 */
typedef int /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ ivec;
typedef int /*<<< orphan*/ DES_key_schedule;
typedef int /*<<< orphan*/ DES_cblock;

/* Variables and functions */
int DES_ENCRYPT;
int /*<<< orphan*/ DES_ncbc_encrypt(unsigned char *, unsigned char *, int,
                                    int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int);
int /*<<< orphan*/ DES_set_key_unchecked(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void xvp_password_crypt_xen(char *src, char *dst, int direction) {
  static char key[] = {0xcc, 0x10, 0x10, 0x58, 0xbe, 0x03, 0x07, 0x66};
  char ivec[8];
  static char tmp[16];
  DES_key_schedule schedule;
  if (direction == DES_ENCRYPT)
    strncpy(tmp, src, sizeof(tmp));
  else
    memcpy(tmp, src, sizeof(tmp));
  DES_set_key_unchecked((DES_cblock *)key, &schedule);
  memset(ivec, 0, sizeof(ivec));
  DES_ncbc_encrypt((unsigned char *)tmp + 8, (unsigned char *)dst + 8, 8,
                   &schedule, (DES_cblock *)ivec, direction);
  memcpy(ivec, direction == DES_ENCRYPT ? dst + 8 : tmp + 8, 8);
  DES_ncbc_encrypt((unsigned char *)tmp, (unsigned char *)dst, 8, &schedule,
                   (DES_cblock *)ivec, direction);
}


x86 assembly (clang, -O0):
<xvp_password_crypt_xen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
jne    118f <xvp_password_crypt_xen+0x3f>
mov    -0x8(%rbp),%rsi
lea    0x2ee0(%rip),%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
jmp    11a4 <xvp_password_crypt_xen+0x54>
mov    -0x8(%rbp),%rsi
lea    0x2ec6(%rip),%rdi
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    0x2e9d(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <DES_set_key_unchecked@plt>
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    -0x1c(%rbp),%r8
mov    -0x14(%rbp),%r9d
lea    0x2e85(%rip),%rdi
add    $0x8,%rdi
mov    $0x8,%edx
lea    -0x20(%rbp),%rcx
call   1050 <DES_ncbc_encrypt@plt>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%eax
jne    1218 <xvp_password_crypt_xen+0xc8>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    122c <xvp_password_crypt_xen+0xdc>
lea    0x2e41(%rip),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
jmp    122c <xvp_password_crypt_xen+0xdc>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%r8
mov    -0x14(%rbp),%r9d
lea    0x2e0f(%rip),%rdi
mov    $0x8,%edx
lea    -0x20(%rbp),%rcx
call   1050 <DES_ncbc_encrypt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xvp_password_crypt_xen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%rsi
mov    0x2e72(%rip),%rax
cmp    %edx,(%rax)
jne    1185 <xvp_password_crypt_xen+0x35>
lea    0x2ee7(%rip),%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
jmp    1196 <xvp_password_crypt_xen+0x46>
lea    0x2ed4(%rip),%rdi
mov    $0x10,%edx
call   1060 <memcpy@plt>
lea    0x2eab(%rip),%rdi
lea    0xc(%rsp),%r15
mov    %r15,%rsi
call   1070 <DES_set_key_unchecked@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0x8(%r14),%rbx
lea    0x2e9f(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13d,%r9d
call   1050 <DES_ncbc_encrypt@plt>
mov    0x2df7(%rip),%rax
cmp    %r13d,(%rax)
cmove  %rbx,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
lea    0x2e59(%rip),%rdi
mov    %r14,%rsi
mov    $0x8,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13d,%r9d
call   1050 <DES_ncbc_encrypt@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@xvp_password_crypt_xen.key = internal global [8 x i8] c"\CC\10\10X\BE\03\07f"
@xvp_password_crypt_xen.tmp = internal global [16 x i8] zeroinitializer
@DES_ENCRYPT = global i32 0
define void @xvp_password_crypt_xen(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [8 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = load i32, i32* @DES_ENCRYPT
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = call i32 @strncpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %13, i32 16)
br label %18
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %16, i32 16)
br label %18
18: ; preds = %15, %12
%19 = call i32 @DES_set_key_unchecked(i32* bitcast ([8 x i8]* @xvp_password_crypt_xen.key to i32*), i32* %8)
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 8)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%25 = bitcast i8* %24 to i32*
%26 = load i32, i32* %6
%27 = call i32 @DES_ncbc_encrypt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 8), i8* %23, i32 8, i32* %8, i32* %25, i32 %26)
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* %6
%30 = load i32, i32* @DES_ENCRYPT
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %18
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 8
br label %36
35: ; preds = %18
br label %36
36: ; preds = %35, %32
%37 = phi i8* [ %34, %32 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 8), %35 ]
%38 = call i32 @memcpy(i8* %28, i8* %37, i32 8)
%39 = load i8*, i8** %5
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%41 = bitcast i8* %40 to i32*
%42 = load i32, i32* %6
%43 = call i32 @DES_ncbc_encrypt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %39, i32 8, i32* %8, i32* %41, i32 %42)
ret void
}

LLVM IR (-O2):
@xvp_password_crypt_xen.key = internal global [8 x i8] c"\CC\10\10X\BE\03\07f"
@xvp_password_crypt_xen.tmp = internal global [16 x i8] zeroinitializer
@DES_ENCRYPT = global i32 0
define void @xvp_password_crypt_xen(i8* %0, i8* %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* @DES_ENCRYPT
%9 = icmp eq i32 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @strncpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %0, i32 16)
br label %14
12: ; preds = %3
%13 = tail call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %0, i32 16)
br label %14
14: ; preds = %12, %10
%15 = call i32 @DES_set_key_unchecked(i32* bitcast ([8 x i8]* @xvp_password_crypt_xen.key to i32*), i32* %5)
%16 = call i32 @memset(i8* %6, i32 0, i32 8)
%17 = getelementptr inbounds i8, i8* %1, i64 8
%18 = bitcast [8 x i8]* %4 to i32*
%19 = call i32 @DES_ncbc_encrypt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 8), i8* %17, i32 8, i32* %5, i32* %18, i32 %2)
%20 = load i32, i32* @DES_ENCRYPT
%21 = icmp eq i32 %20, %2
%22 = select i1 %21, i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 8)
%23 = call i32 @memcpy(i8* %6, i8* %22, i32 8)
%24 = call i32 @DES_ncbc_encrypt(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @xvp_password_crypt_xen.tmp, i64 0, i64 0), i8* %1, i32 8, i32* %5, i32* %18, i32 %2)
ret void
}