#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*/ desm1(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
void TriDesDecrypt(unsigned char *Key, int KeyLen, unsigned char *s, int slen,
                   unsigned char *o) {
  int i;
  unsigned char S[16];
  for (i = 0; i < slen / 8; i++) {
    memcpy(S, s + 8 * i, 8);
    if (KeyLen == 16)
      TriUnDes(S, o + 8 * i, Key);
    else
      desm1(S, o + 8 * i, Key);
  }
}


x86 assembly (clang, -O0):
<TriDesDecrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jge    11e6 <TriDesDecrypt+0xb6>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
cmpl   $0x10,-0xc(%rbp)
jne    11b7 <TriDesDecrypt+0x87>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
call   1030 <TriUnDes@plt>
jmp    11d3 <TriDesDecrypt+0xa3>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
call   1050 <desm1@plt>
jmp    11d8 <TriDesDecrypt+0xa8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1151 <TriDesDecrypt+0x21>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TriDesDecrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x8,%ecx
jl     1199 <TriDesDecrypt+0x69>
mov    %r8,%r15
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r13
shr    $0x3,%r14d
mov    %rsp,%rbp
jmp    1173 <TriDesDecrypt+0x43>
nopl   0x0(%rax,%rax,1)
call   1050 <desm1@plt>
add    $0x8,%r15
add    $0x8,%rbx
add    $0xffffffffffffffff,%r14
je     1199 <TriDesDecrypt+0x69>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
cmp    $0x10,%r12d
jne    1160 <TriDesDecrypt+0x30>
call   1030 <TriUnDes@plt>
jmp    1165 <TriDesDecrypt+0x35>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @TriDesDecrypt(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]
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
store i32 0, i32* %11
br label %13
13: ; preds = %47, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %9
%16 = sdiv i32 %15, 8
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %50
18: ; preds = %13
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = load i32, i32* %11
%22 = mul nsw i32 8, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = call i32 @memcpy(i8* %19, i8* %24, i32 8)
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 16
br i1 %27, label %28, label %37
28: ; preds = %18
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%30 = load i8*, i8** %10
%31 = load i32, i32* %11
%32 = mul nsw i32 8, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8*, i8** %6
%36 = call i32 @TriUnDes(i8* %29, i8* %34, i8* %35)
br label %46
37: ; preds = %18
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%39 = load i8*, i8** %10
%40 = load i32, i32* %11
%41 = mul nsw i32 8, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8*, i8** %6
%45 = call i32 @desm1(i8* %38, i8* %43, i8* %44)
br label %46
46: ; preds = %37, %28
br label %47
47: ; preds = %46
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %13
50: ; preds = %13
ret void
}

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