#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*/ agile_bit_xor(unsigned char const *, unsigned char *,
                                 unsigned char *, int);
int /*<<< orphan*/ agile_des_decipher(unsigned char const *, unsigned char *,
                                      unsigned char const *);
void agile_cbc_decipher(const unsigned char *ciphertext,
                        unsigned char *plaintext, const unsigned char *key,
                        int size) {
  unsigned char temp[8];
  int i;
  agile_des_decipher(&ciphertext[0], &plaintext[0], key);
  i = 8;
  while (i < size) {
    agile_des_decipher(&ciphertext[i], temp, NULL);
    agile_bit_xor(&ciphertext[i - 8], temp, &plaintext[i], 64);
    i += 8;
  }
}


x86 assembly (clang, -O0):
<agile_cbc_decipher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <agile_des_decipher@plt>
movl   $0x8,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a9 <agile_cbc_decipher+0x89>
mov    -0x8(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <agile_des_decipher@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
sub    $0x8,%eax
cltq
add    %rax,%rdi
lea    -0x24(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movslq -0x28(%rbp),%rax
add    %rax,%rdx
mov    $0x40,%ecx
call   1030 <agile_bit_xor@plt>
mov    -0x28(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x28(%rbp)
jmp    114f <agile_cbc_decipher+0x2f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<agile_cbc_decipher>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <agile_des_decipher@plt>
cmp    $0x9,%ebp
jl     1184 <agile_cbc_decipher+0x64>
mov    %ebp,%r12d
add    $0x8,%rbx
mov    $0x8,%ebp
mov    %rsp,%r15
nopl   0x0(%rax)
lea    0x8(%r14),%r13
mov    %r13,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <agile_des_decipher@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x40,%ecx
call   1030 <agile_bit_xor@plt>
add    $0x8,%rbp
add    $0x8,%rbx
mov    %r13,%r14
cmp    %r12,%rbp
jl     1150 <agile_cbc_decipher+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @agile_cbc_decipher(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [8 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8*, i8** %7
%16 = call i32 @agile_des_decipher(i8* %12, i8* %14, i8* %15)
store i32 8, i32* %10
br label %17
17: ; preds = %21, %4
%18 = load i32, i32* %10
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%27 = call i32 @agile_des_decipher(i8* %25, i8* %26, i8* null)
%28 = load i8*, i8** %5
%29 = load i32, i32* %10
%30 = sub nsw i32 %29, 8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = call i32 @agile_bit_xor(i8* %32, i8* %33, i8* %37, i32 64)
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 8
store i32 %40, i32* %10
br label %17
41: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @agile_cbc_decipher(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @agile_des_decipher(i8* %0, i8* %1, i8* %2)
%8 = icmp sgt i32 %3, 8
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 8, %9 ], [ %19, %11 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i32 @agile_des_decipher(i8* %13, i8* %6, i8* null)
%15 = add nsw i64 %12, -8
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = getelementptr inbounds i8, i8* %1, i64 %12
%18 = call i32 @agile_bit_xor(i8* %16, i8* %6, i8* %17, i32 64)
%19 = add nuw i64 %12, 8
%20 = icmp slt i64 %19, %10
br i1 %20, label %11, label %21
21: ; preds = %11, %4
ret void
}