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


x86 assembly (clang, -O0):
<cipher3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x838(%rbp)
movl   $0x0,-0x83c(%rbp)
cmpl   $0x20,-0x83c(%rbp)
jge    118e <cipher3+0x5e>
movslq -0x83c(%rbp),%rax
movb   $0x0,-0x860(%rbp,%rax,1)
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    115e <cipher3+0x2e>
lea    -0x860(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
cmpl   $0x400,-0x24(%rbp)
jle    11bc <cipher3+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    132b <cipher3+0x1fb>
movl   $0x0,-0x83c(%rbp)
mov    -0x83c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1205 <cipher3+0xd5>
mov    -0x18(%rbp),%rax
movslq -0x83c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x83c(%rbp),%rax
mov    %cl,-0x430(%rbp,%rax,1)
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    11c6 <cipher3+0x96>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122f <cipher3+0xff>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x834(%rbp)
jmp    12a3 <cipher3+0x173>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%eax
sub    %edx,%eax
mov    %eax,-0x838(%rbp)
movl   $0x0,-0x83c(%rbp)
mov    -0x83c(%rbp),%eax
cmp    -0x838(%rbp),%eax
jge    129e <cipher3+0x16e>
mov    -0x24(%rbp),%eax
add    -0x83c(%rbp),%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    1265 <cipher3+0x135>
jmp    12a3 <cipher3+0x173>
movl   $0x0,-0x83c(%rbp)
mov    -0x83c(%rbp),%eax
cmp    -0x834(%rbp),%eax
jge    130b <cipher3+0x1db>
mov    -0x83c(%rbp),%eax
shl    $0x3,%eax
cltq
lea    -0x430(%rbp),%rsi
add    %rax,%rsi
lea    -0x860(%rbp),%rdx
mov    -0x83c(%rbp),%eax
shl    $0x3,%eax
cltq
lea    -0x830(%rbp),%rcx
add    %rax,%rcx
xor    %edi,%edi
call   1040 <TDes@plt>
mov    -0x83c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x83c(%rbp)
jmp    12ad <cipher3+0x17d>
lea    -0x830(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x834(%rbp),%edx
shl    $0x3,%edx
call   1050 <tohex@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cipher3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
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    $0xffffffff,%eax
cmp    $0x400,%ebx
jg     1247 <cipher3+0xf7>
test   %ebx,%ebx
jle    11a9 <cipher3+0x59>
mov    %ebx,%edx
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
call   1060 <memcpy@plt>
lea    0x7(%rbx),%r15d
test   %ebx,%ebx
mov    %ebx,%ebp
cmovs  %r15d,%ebp
mov    %ebp,%ecx
and    $0xfffffff8,%ecx
mov    %ebx,%eax
sub    %ecx,%eax
je     11e9 <cipher3+0x99>
sar    $0x3,%ebp
mov    $0x8,%edx
sub    %eax,%edx
add    $0x1,%ebp
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %ebp,%r15d
test   %r15d,%r15d
jg     11f8 <cipher3+0xa8>
jmp    122e <cipher3+0xde>
test   %ebx,%ebx
cmovns %ebx,%r15d
sar    $0x3,%r15d
test   %r15d,%r15d
jle    122e <cipher3+0xde>
mov    %r15d,%r13d
lea    0x420(%rsp),%rbx
lea    0x20(%rsp),%rbp
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <TDes@plt>
add    $0x8,%rbx
add    $0x8,%rbp
add    $0xffffffffffffffff,%r13
jne    1210 <cipher3+0xc0>
shl    $0x3,%r15d
lea    0x420(%rsp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1070 <tohex@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cipher3(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [32 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %13
store i32 0, i32* %14
br label %16
16: ; preds = %23, %4
%17 = load i32, i32* %14
%18 = icmp slt i32 %17, 32
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %14
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %19
%24 = load i32, i32* %14
%25 = add nsw i32 %24, 1
store i32 %25, i32* %14
br label %16
26: ; preds = %16
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 16)
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 1024
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 -1, i32* %5
br label %103
33: ; preds = %26
store i32 0, i32* %14
br label %34
34: ; preds = %47, %33
%35 = load i32, i32* %14
%36 = load i32, i32* %9
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = load i8*, i8** %7
%40 = load i32, i32* %14
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %45
store i8 %43, i8* %46
br label %47
47: ; preds = %38
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %34
50: ; preds = %34
%51 = load i32, i32* %9
%52 = srem i32 %51, 8
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* %9
%56 = sdiv i32 %55, 8
store i32 %56, i32* %12
br label %78
57: ; preds = %50
%58 = load i32, i32* %9
%59 = sdiv i32 %58, 8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %12
%61 = load i32, i32* %9
%62 = srem i32 %61, 8
%63 = sub nsw i32 8, %62
store i32 %63, i32* %13
store i32 0, i32* %14
br label %64
64: ; preds = %74, %57
%65 = load i32, i32* %14
%66 = load i32, i32* %13
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %77
68: ; preds = %64
%69 = load i32, i32* %9
%70 = load i32, i32* %14
%71 = add nsw i32 %69, %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %72
store i8 0, i8* %73
br label %74
74: ; preds = %68
%75 = load i32, i32* %14
%76 = add nsw i32 %75, 1
store i32 %76, i32* %14
br label %64
77: ; preds = %64
br label %78
78: ; preds = %77, %54
store i32 0, i32* %14
br label %79
79: ; preds = %94, %78
%80 = load i32, i32* %14
%81 = load i32, i32* %12
%82 = icmp slt i32 %80, %81
br i1 %82, label %83, label %97
83: ; preds = %79
%84 = load i32, i32* %14
%85 = mul nsw i32 8, %84
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %86
%88 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%89 = load i32, i32* %14
%90 = mul nsw i32 8, %89
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %91
%93 = call i32 @TDes(i32 0, i8* %87, i8* %88, i8* %92)
br label %94
94: ; preds = %83
%95 = load i32, i32* %14
%96 = add nsw i32 %95, 1
store i32 %96, i32* %14
br label %79
97: ; preds = %79
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%99 = load i8*, i8** %8
%100 = load i32, i32* %12
%101 = mul nsw i32 8, %100
%102 = call i32 @tohex(i8* %98, i8* %99, i32 %101)
store i32 0, i32* %5
br label %103
103: ; preds = %97, %32
%104 = load i32, i32* %5
ret i32 %104
}

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