#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 OPENCOMM_DesDecRaw(unsigned char *, int, unsigned char *, int,
                       unsigned char *, unsigned long *);
int OPENCOMM_DesExpandDecKey(unsigned char *, int, unsigned char *,
                             unsigned long *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int myic_DESDecrypt(unsigned char *pDesKey, int nDesKeyLen,
                    unsigned char *pInData, int nInDataLen,
                    unsigned char *pOutData, int *pOutDataLen) {
  unsigned char DesKeyBuf[32];
  unsigned char DesDecKeyBuf[128];
  int DecKeyLen, KeyLen = 0;
  int retval = 0, loops, i;
  if (nInDataLen % 8 != 0)
    return 0xEE20;
  if (nDesKeyLen != 8)
    return 0xEE20;
  KeyLen = nDesKeyLen;
  memcpy(DesKeyBuf, pDesKey, nDesKeyLen);
  retval = OPENCOMM_DesExpandDecKey(DesKeyBuf, KeyLen, DesDecKeyBuf,
                                    (unsigned long *)&DecKeyLen);
  if (retval != 0)
    return retval;
  loops = nInDataLen / 8;
  for (i = 0; i < loops; i++) {
    retval = OPENCOMM_DesDecRaw(DesDecKeyBuf, DecKeyLen, pInData + i * 8, 8,
                                pOutData + i * 8, (unsigned long *)pOutDataLen);
    if (retval != 0)
      return retval;
  }
  *pOutDataLen = nInDataLen;
  return retval;
}


x86 assembly (clang, -O0):
<myic_DESDecrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0xe8(%rbp)
movl   $0x0,-0xec(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1185 <myic_DESDecrypt+0x55>
movl   $0xee20,-0x4(%rbp)
jmp    12aa <myic_DESDecrypt+0x17a>
cmpl   $0x8,-0x14(%rbp)
je     119b <myic_DESDecrypt+0x6b>
movl   $0xee20,-0x4(%rbp)
jmp    12aa <myic_DESDecrypt+0x17a>
mov    -0x14(%rbp),%eax
mov    %eax,-0xe8(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
lea    -0x60(%rbp),%rdi
mov    -0xe8(%rbp),%esi
lea    -0xe0(%rbp),%rdx
lea    -0xe4(%rbp),%rcx
call   1030 <OPENCOMM_DesExpandDecKey@plt>
mov    %eax,-0xec(%rbp)
cmpl   $0x0,-0xec(%rbp)
je     11f2 <myic_DESDecrypt+0xc2>
mov    -0xec(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12aa <myic_DESDecrypt+0x17a>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0xf0(%rbp)
movl   $0x0,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
cmp    -0xf0(%rbp),%eax
jge    1298 <myic_DESDecrypt+0x168>
lea    -0xe0(%rbp),%rdi
mov    -0xe4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0xf4(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdx
mov    -0x30(%rbp),%r8
mov    -0xf4(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%r8
mov    -0x38(%rbp),%r9
mov    $0x8,%ecx
call   1040 <OPENCOMM_DesDecRaw@plt>
mov    %eax,-0xec(%rbp)
cmpl   $0x0,-0xec(%rbp)
je     127f <myic_DESDecrypt+0x14f>
mov    -0xec(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12aa <myic_DESDecrypt+0x17a>
jmp    1284 <myic_DESDecrypt+0x154>
mov    -0xf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4(%rbp)
jmp    120d <myic_DESDecrypt+0xdd>
mov    -0x24(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xec(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myic_DESDecrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    $0xee20,%eax
cmp    $0x8,%esi
jne    11e1 <myic_DESDecrypt+0xb1>
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %ecx,%edx
and    $0x7,%edx
jne    11e1 <myic_DESDecrypt+0xb1>
mov    %r9,%r15
mov    %r8,%r13
mov    %rdi,%rcx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rcx,%rsi
mov    $0x8,%edx
call   1050 <memcpy@plt>
lea    0x30(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r12,%rdi
mov    $0x8,%esi
call   1030 <OPENCOMM_DesExpandDecKey@plt>
test   %eax,%eax
jne    11e1 <myic_DESDecrypt+0xb1>
cmp    $0x8,%r14d
jl     11dc <myic_DESDecrypt+0xac>
mov    %r14d,%ebp
shr    $0x3,%ebp
lea    0x30(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    $0x8,%ecx
mov    %r13,%r8
mov    %r15,%r9
call   1040 <OPENCOMM_DesDecRaw@plt>
test   %eax,%eax
jne    11e1 <myic_DESDecrypt+0xb1>
add    $0x8,%r13
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    11b0 <myic_DESDecrypt+0x80>
mov    %r14d,(%r15)
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @myic_DESDecrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca [32 x i8]
%15 = alloca [128 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32* %5, i32** %13
store i32 0, i32* %17
store i32 0, i32* %18
%21 = load i32, i32* %11
%22 = srem i32 %21, 8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %6
store i32 60960, i32* %7
br label %79
25: ; preds = %6
%26 = load i32, i32* %9
%27 = icmp ne i32 %26, 8
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 60960, i32* %7
br label %79
29: ; preds = %25
%30 = load i32, i32* %9
store i32 %30, i32* %17
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%32 = load i8*, i8** %8
%33 = load i32, i32* %9
%34 = call i32 @memcpy(i8* %31, i8* %32, i32 %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%36 = load i32, i32* %17
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%38 = bitcast i32* %16 to i64*
%39 = call i32 @OPENCOMM_DesExpandDecKey(i8* %35, i32 %36, i8* %37, i64* %38)
store i32 %39, i32* %18
%40 = load i32, i32* %18
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %29
%43 = load i32, i32* %18
store i32 %43, i32* %7
br label %79
44: ; preds = %29
%45 = load i32, i32* %11
%46 = sdiv i32 %45, 8
store i32 %46, i32* %19
store i32 0, i32* %20
br label %47
47: ; preds = %72, %44
%48 = load i32, i32* %20
%49 = load i32, i32* %19
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %75
51: ; preds = %47
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%53 = load i32, i32* %16
%54 = load i8*, i8** %10
%55 = load i32, i32* %20
%56 = mul nsw i32 %55, 8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
%59 = load i8*, i8** %12
%60 = load i32, i32* %20
%61 = mul nsw i32 %60, 8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i32*, i32** %13
%65 = bitcast i32* %64 to i64*
%66 = call i32 @OPENCOMM_DesDecRaw(i8* %52, i32 %53, i8* %58, i32 8, i8* %63, i64* %65)
store i32 %66, i32* %18
%67 = load i32, i32* %18
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %51
%70 = load i32, i32* %18
store i32 %70, i32* %7
br label %79
71: ; preds = %51
br label %72
72: ; preds = %71
%73 = load i32, i32* %20
%74 = add nsw i32 %73, 1
store i32 %74, i32* %20
br label %47
75: ; preds = %47
%76 = load i32, i32* %11
%77 = load i32*, i32** %13
store i32 %76, i32* %77
%78 = load i32, i32* %18
store i32 %78, i32* %7
br label %79
79: ; preds = %75, %69, %42, %28, %24
%80 = load i32, i32* %7
ret i32 %80
}

LLVM IR (-O2):
define i32 @myic_DESDecrypt(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca [32 x i8]
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = bitcast i32* %9 to i8*
%13 = and i32 %3, 7
%14 = icmp eq i32 %13, 0
%15 = icmp eq i32 %1, 8
%16 = and i1 %15, %14
br i1 %16, label %17, label %40
17: ; preds = %6
%18 = call i32 @memcpy(i8* %10, i8* %0, i32 8)
%19 = bitcast i32* %9 to i64*
%20 = call i32 @OPENCOMM_DesExpandDecKey(i8* %10, i32 8, i8* %11, i64* %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %17
%23 = icmp sgt i32 %3, 7
br i1 %23, label %24, label %39
24: ; preds = %22
%25 = lshr i32 %3, 3
%26 = bitcast i32* %5 to i64*
%27 = zext i32 %25 to i64
br label %30
28: ; preds = %30
%29 = icmp eq i64 %38, %27
br i1 %29, label %39, label %30
30: ; preds = %24, %28
%31 = phi i64 [ 0, %24 ], [ %38, %28 ]
%32 = load i32, i32* %9
%33 = shl nsw i64 %31, 3
%34 = getelementptr inbounds i8, i8* %2, i64 %33
%35 = getelementptr inbounds i8, i8* %4, i64 %33
%36 = call i32 @OPENCOMM_DesDecRaw(i8* %11, i32 %32, i8* %34, i32 8, i8* %35, i64* %26)
%37 = icmp eq i32 %36, 0
%38 = add nuw nsw i64 %31, 1
br i1 %37, label %28, label %40
39: ; preds = %28, %22
store i32 %3, i32* %5
br label %40
40: ; preds = %30, %17, %6, %39
%41 = phi i32 [ 0, %39 ], [ 60960, %6 ], [ %20, %17 ], [ %36, %30 ]
ret i32 %41
}