#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 */

/* Variables and functions */
int /*<<< orphan*/ TriUnDes(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ XOR(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ desm1(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void CBCDesDecrypt(unsigned char *Key, int KeyLen, unsigned char *s, int slen,
                   unsigned char *o) {
  int i;
  unsigned char S[16];
  unsigned char In[8];
  unsigned char Out[8];
  memset(Out, 0, 8);
  for (i = 0; i < slen / 8; i++) {
    memcpy(S, s + 8 * i, 8);
    XOR(S, Out, In);
    if (KeyLen == 16) {
      TriUnDes(In, Out, Key);
      memcpy(o + 8 * i, Out, 8);
    } else {
      desm1(In, Out, Key);
      memcpy(o + 8 * i, Out, 8);
    }
  }
}


x86 assembly (clang, -O0):
<CBCDesDecrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jge    124b <CBCDesDecrypt+0xfb>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1060 <XOR@plt>
cmpl   $0x10,-0xc(%rbp)
jne    120a <CBCDesDecrypt+0xba>
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <TriUnDes@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
jmp    1238 <CBCDesDecrypt+0xe8>
lea    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1070 <desm1@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
jmp    123d <CBCDesDecrypt+0xed>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1181 <CBCDesDecrypt+0x31>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CBCDesDecrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r15
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,0x4(%rsp)
mov    %rdi,0x8(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
cmp    $0x8,%r14d
jl     1205 <CBCDesDecrypt+0xb5>
shr    $0x3,%r14d
lea    0x20(%rsp),%rbp
lea    0x10(%rsp),%r12
lea    0x18(%rsp),%r13
jmp    11ce <CBCDesDecrypt+0x7e>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    0x8(%rsp),%rdx
call   1070 <desm1@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
add    $0x8,%r15
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
je     1205 <CBCDesDecrypt+0xb5>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <XOR@plt>
cmpl   $0x10,0x4(%rsp)
jne    11a0 <CBCDesDecrypt+0x50>
mov    %r13,%rdi
mov    %r12,%rsi
mov    0x8(%rsp),%rdx
call   1030 <TriUnDes@plt>
jmp    11b0 <CBCDesDecrypt+0x60>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @CBCDesDecrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [16 x i8]
%13 = alloca [8 x i8]
%14 = alloca [8 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 8)
store i32 0, i32* %11
br label %17
17: ; preds = %61, %5
%18 = load i32, i32* %11
%19 = load i32, i32* %9
%20 = sdiv i32 %19, 8
%21 = icmp slt i32 %18, %20
br i1 %21, label %22, label %64
22: ; preds = %17
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%24 = load i8*, i8** %8
%25 = load i32, i32* %11
%26 = mul nsw i32 8, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = call i32 @memcpy(i8* %23, i8* %28, i32 8)
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%33 = call i32 @XOR(i8* %30, i8* %31, i8* %32)
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 16
br i1 %35, label %36, label %48
36: ; preds = %22
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = call i32 @TriUnDes(i8* %37, i8* %38, i8* %39)
%41 = load i8*, i8** %10
%42 = load i32, i32* %11
%43 = mul nsw i32 8, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%47 = call i32 @memcpy(i8* %45, i8* %46, i32 8)
br label %60
48: ; preds = %22
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%51 = load i8*, i8** %6
%52 = call i32 @desm1(i8* %49, i8* %50, i8* %51)
%53 = load i8*, i8** %10
%54 = load i32, i32* %11
%55 = mul nsw i32 8, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%59 = call i32 @memcpy(i8* %57, i8* %58, i32 8)
br label %60
60: ; preds = %48, %36
br label %61
61: ; preds = %60
%62 = load i32, i32* %11
%63 = add nsw i32 %62, 1
store i32 %63, i32* %11
br label %17
64: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @CBCDesDecrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca [16 x i8]
%7 = alloca [8 x i8]
%8 = alloca [8 x i8]
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 8)
%13 = icmp sgt i32 %3, 7
br i1 %13, label %14, label %33
14: ; preds = %5
%15 = lshr i32 %3, 3
%16 = icmp eq i32 %1, 16
%17 = zext i32 %15 to i64
br label %18
18: ; preds = %14, %28
%19 = phi i64 [ 0, %14 ], [ %31, %28 ]
%20 = shl nsw i64 %19, 3
%21 = getelementptr inbounds i8, i8* %2, i64 %20
%22 = call i32 @memcpy(i8* %9, i8* %21, i32 8)
%23 = call i32 @XOR(i8* %9, i8* %11, i8* %10)
br i1 %16, label %24, label %26
24: ; preds = %18
%25 = call i32 @TriUnDes(i8* %10, i8* %11, i8* %0)
br label %28
26: ; preds = %18
%27 = call i32 @desm1(i8* %10, i8* %11, i8* %0)
br label %28
28: ; preds = %24, %26
%29 = getelementptr inbounds i8, i8* %4, i64 %20
%30 = call i32 @memcpy(i8* %29, i8* %11, i32 8)
%31 = add nuw nsw i64 %19, 1
%32 = icmp eq i64 %31, %17
br i1 %32, label %33, label %18
33: ; preds = %28, %5
ret void
}