#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*/ TDes(int, unsigned char *, unsigned char *, unsigned char *);
unsigned char asc_bcd(unsigned char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int decipher3(const unsigned char *key, unsigned char *plain_text,
              unsigned char *crypted_text, int length) {
  unsigned char t_crypt[1024];
  int i;
  unsigned char usekey[32];
  for (i = 0; i < 32; i++)
    usekey[i] = '\0';
  strncpy((char *)usekey, (char *)key, 16);
  for (i = 0; i < length / 2; i++)
    t_crypt[i] = asc_bcd(crypted_text + i * 2);
  for (i = 0; i < length / 16; i++)
    TDes(1, &t_crypt[8 * i], usekey, &plain_text[8 * i]);
  plain_text[length / 2] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<decipher3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x424(%rbp)
cmpl   $0x20,-0x424(%rbp)
jge    1184 <decipher3+0x54>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1154 <decipher3+0x24>
lea    -0x450(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x454(%rbp),%eax
cmp    %ecx,%eax
jge    1205 <decipher3+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0x424(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
call   1050 <asc_bcd@plt>
mov    %al,%cl
movslq -0x424(%rbp),%rax
mov    %cl,-0x420(%rbp,%rax,1)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11a3 <decipher3+0x73>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    %eax,-0x458(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x458(%rbp),%eax
cmp    %ecx,%eax
jge    1282 <decipher3+0x152>
mov    -0x424(%rbp),%eax
shl    $0x3,%eax
cltq
lea    -0x420(%rbp),%rsi
add    %rax,%rsi
lea    -0x450(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x424(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rcx
mov    $0x1,%edi
call   1040 <TDes@plt>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    120f <decipher3+0xdf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x460(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decipher3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    %r15d,%r14d
shr    $0x1f,%r14d
add    %r15d,%r14d
sar    %r14d
cmp    $0x2,%r15d
jl     11f1 <decipher3+0xc1>
mov    %rbp,%r13
mov    %r14d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <asc_bcd@plt>
mov    %al,0x20(%rsp,%rbp,1)
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %rbp,%r12
jne    1190 <decipher3+0x60>
cmp    $0x10,%r15d
mov    %r13,%rbp
jl     11f1 <decipher3+0xc1>
shr    $0x4,%r15d
lea    0x20(%rsp),%r13
mov    %rsp,%r12
mov    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <TDes@plt>
add    $0x8,%rbx
add    $0x8,%r13
add    $0xffffffffffffffff,%r15
jne    11d0 <decipher3+0xa0>
movslq %r14d,%rax
movb   $0x0,0x0(%rbp,%rax,1)
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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