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


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

x86 assembly (clang, -O2):
<agile_cbc_encipher>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <agile_des_encipher@plt>
cmp    $0x9,%ebp
jl     117e <agile_cbc_encipher+0x5e>
mov    %ebp,%r12d
mov    $0x8,%ebp
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    $0x40,%ecx
call   1030 <agile_bit_xor@plt>
add    $0x8,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <agile_des_encipher@plt>
add    $0x8,%rbp
cmp    %r12,%rbp
jl     1150 <agile_cbc_encipher+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @agile_cbc_encipher(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_encipher(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 = load i8*, i8** %6
%27 = load i32, i32* %10
%28 = sub nsw i32 %27, 8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%32 = call i32 @agile_bit_xor(i8* %25, i8* %30, i8* %31, i32 64)
%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_des_encipher(i8* %33, i8* %37, i8* null)
%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_encipher(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_encipher(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 = add nsw i64 %12, -8
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = call i32 @agile_bit_xor(i8* %13, i8* %15, i8* %6, i32 64)
%17 = getelementptr inbounds i8, i8* %1, i64 %12
%18 = call i32 @agile_des_encipher(i8* %6, i8* %17, i8* null)
%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
}