#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 */
typedef int /*<<< orphan*/ DES_key_schedule;
typedef int /*<<< orphan*/ DES_cblock;

/* Variables and functions */
int /*<<< orphan*/ DES_ENCRYPT;
int /*<<< orphan*/ DES_ecb2_encrypt(unsigned char *, unsigned char *,
                                    int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ DES_ede2_cbc_encrypt(unsigned char *, unsigned char *,
                                        unsigned int, int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/);
int /*<<< orphan*/ DES_set_key_checked(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
int bencrypt(unsigned char *input, unsigned char *output, unsigned int len,
             DES_cblock *k1, DES_cblock *k2, DES_cblock *iv) {
  DES_key_schedule s1, s2;
  int i;
  if (len % 8 != 0) {
    return -1;
  }
  DES_set_key_checked(k1, &s1);
  DES_set_key_checked(k2, &s2);
  if (iv == NULL) {
    for (i = 0; i < len; i += 8) {
      DES_ecb2_encrypt(input + i, output + i, &s1, &s2, DES_ENCRYPT);
    }
  } else {
    DES_ede2_cbc_encrypt(input, output, len, &s1, &s2, iv, DES_ENCRYPT);
  }
  return 0;
}


x86 assembly (clang, -O0):
<bencrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
je     116a <bencrypt+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <bencrypt+0xe1>
mov    -0x28(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1030 <DES_set_key_checked@plt>
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <DES_set_key_checked@plt>
cmpq   $0x0,-0x38(%rbp)
jne    11e2 <bencrypt+0xb2>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11dd <bencrypt+0xad>
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    0x2e21(%rip),%rax
mov    (%rax),%r8d
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1050 <DES_ecb2_encrypt@plt>
mov    -0x44(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x44(%rbp)
jmp    1196 <bencrypt+0x66>
jmp    120a <bencrypt+0xda>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%r9
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
lea    -0x3c(%rbp),%rcx
lea    -0x40(%rbp),%r8
mov    %eax,(%rsp)
call   1040 <DES_ede2_cbc_encrypt@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bencrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    $0xffffffff,%r12d
test   $0x7,%bpl
jne    11e8 <bencrypt+0xb8>
mov    %r9,%r15
mov    %r8,%r13
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x14(%rsp),%rsi
mov    %rcx,%rdi
call   1030 <DES_set_key_checked@plt>
lea    0x10(%rsp),%rsi
mov    %r13,%rdi
call   1030 <DES_set_key_checked@plt>
test   %r15,%r15
je     11a6 <bencrypt+0x76>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %r15,%r9
call   1040 <DES_ede2_cbc_encrypt@plt>
xor    %r12d,%r12d
jmp    11e8 <bencrypt+0xb8>
test   %ebp,%ebp
je     11a1 <bencrypt+0x71>
mov    %ebp,%ebp
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%r15,1),%rdi
lea    (%r14,%r15,1),%rsi
mov    0x2e11(%rip),%rax
mov    (%rax),%r8d
lea    0x14(%rsp),%rdx
mov    %r13,%rcx
call   1050 <DES_ecb2_encrypt@plt>
add    $0x8,%r15
cmp    %rbp,%r15
jb     11c0 <bencrypt+0x90>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DES_ENCRYPT = global i32 0
define i32 @bencrypt(i8* %0, i8* %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%17 = load i32, i32* %10
%18 = urem i32 %17, 8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %6
store i32 -1, i32* %7
br label %56
21: ; preds = %6
%22 = load i32*, i32** %11
%23 = call i32 @DES_set_key_checked(i32* %22, i32* %14)
%24 = load i32*, i32** %12
%25 = call i32 @DES_set_key_checked(i32* %24, i32* %15)
%26 = load i32*, i32** %13
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %48
28: ; preds = %21
store i32 0, i32* %16
br label %29
29: ; preds = %44, %28
%30 = load i32, i32* %16
%31 = load i32, i32* %10
%32 = icmp ult i32 %30, %31
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = load i8*, i8** %8
%35 = load i32, i32* %16
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %9
%39 = load i32, i32* %16
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i32, i32* @DES_ENCRYPT
%43 = call i32 @DES_ecb2_encrypt(i8* %37, i8* %41, i32* %14, i32* %15, i32 %42)
br label %44
44: ; preds = %33
%45 = load i32, i32* %16
%46 = add nsw i32 %45, 8
store i32 %46, i32* %16
br label %29
47: ; preds = %29
br label %55
48: ; preds = %21
%49 = load i8*, i8** %8
%50 = load i8*, i8** %9
%51 = load i32, i32* %10
%52 = load i32*, i32** %13
%53 = load i32, i32* @DES_ENCRYPT
%54 = call i32 @DES_ede2_cbc_encrypt(i8* %49, i8* %50, i32 %51, i32* %14, i32* %15, i32* %52, i32 %53)
br label %55
55: ; preds = %48, %47
store i32 0, i32* %7
br label %56
56: ; preds = %55, %20
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
@DES_ENCRYPT = global i32 0
define i32 @bencrypt(i8* %0, i8* %1, i32 %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %7 to i8*
%10 = bitcast i32* %8 to i8*
%11 = and i32 %2, 7
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %6
%14 = call i32 @DES_set_key_checked(i32* %3, i32* %7)
%15 = call i32 @DES_set_key_checked(i32* %4, i32* %8)
%16 = icmp eq i32* %5, null
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = icmp eq i32 %2, 0
br i1 %18, label %32, label %19
19: ; preds = %17
%20 = zext i32 %2 to i64
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %27, %21 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = getelementptr inbounds i8, i8* %1, i64 %22
%25 = load i32, i32* @DES_ENCRYPT
%26 = call i32 @DES_ecb2_encrypt(i8* %23, i8* %24, i32* %7, i32* %8, i32 %25)
%27 = add nuw nsw i64 %22, 8
%28 = icmp ult i64 %27, %20
br i1 %28, label %21, label %32
29: ; preds = %13
%30 = load i32, i32* @DES_ENCRYPT
%31 = call i32 @DES_ede2_cbc_encrypt(i8* %0, i8* %1, i32 %2, i32* %7, i32* %8, i32* %5, i32 %30)
br label %32
32: ; preds = %21, %17, %29, %6
%33 = phi i32 [ -1, %6 ], [ 0, %29 ], [ 0, %17 ], [ 0, %21 ]
ret i32 %33
}