#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*/ AES_KEY;

/* Variables and functions */
int /*<<< orphan*/ AES_DECRYPT;
int /*<<< orphan*/ AES_ecb_encrypt(unsigned char *, unsigned char *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ AES_set_decrypt_key(unsigned char *, int,
                                       int /*<<< orphan*/ *);
int decrypt(unsigned char *ciphertext, unsigned int ciphertext_len,
            unsigned char *key, unsigned char *plaintext) {
  AES_KEY enc_key;
  AES_set_decrypt_key(key, 128, &enc_key);
  for (unsigned int i = 0; i < ciphertext_len; i += 16) {
    AES_ecb_encrypt(ciphertext + i, plaintext + i, &enc_key, AES_DECRYPT);
  }
  return 0;
}


x86 assembly (clang, -O0):
<decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x80,%esi
lea    -0x24(%rbp),%rdx
call   1040 <AES_set_decrypt_key@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1190 <decrypt+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%eax
add    %rax,%rsi
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
lea    -0x24(%rbp),%rdx
call   1030 <AES_ecb_encrypt@plt>
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    1150 <decrypt+0x30>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rax
mov    %esi,%ebp
mov    %rdi,%r12
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
mov    $0x80,%esi
call   1040 <AES_set_decrypt_key@plt>
test   %ebp,%ebp
je     117c <decrypt+0x5c>
xor    %ebx,%ebx
mov    0x2e93(%rip),%r13
lea    0x4(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%esi
lea    (%r12,%rsi,1),%rdi
add    %r14,%rsi
mov    0x0(%r13),%ecx
mov    %r15,%rdx
call   1030 <AES_ecb_encrypt@plt>
add    $0x10,%ebx
cmp    %ebp,%ebx
jb     1160 <decrypt+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_DECRYPT = global i32 0
define i32 @decrypt(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %7
%12 = call i32 @AES_set_decrypt_key(i8* %11, i32 128, i32* %9)
store i32 0, i32* %10
br label %13
13: ; preds = %28, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %6
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = load i32, i32* %10
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8*, i8** %8
%23 = load i32, i32* %10
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* @AES_DECRYPT
%27 = call i32 @AES_ecb_encrypt(i8* %21, i8* %25, i32* %9, i32 %26)
br label %28
28: ; preds = %17
%29 = load i32, i32* %10
%30 = add i32 %29, 16
store i32 %30, i32* %10
br label %13
31: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@AES_DECRYPT = global i32 0
define i32 @decrypt(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @AES_set_decrypt_key(i8* %2, i32 128, i32* %5)
%8 = icmp eq i32 %1, 0
br i1 %8, label %9, label %10
9: ; preds = %10, %4
ret i32 0
10: ; preds = %4, %10
%11 = phi i32 [ %17, %10 ], [ 0, %4 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = getelementptr inbounds i8, i8* %3, i64 %12
%15 = load i32, i32* @AES_DECRYPT
%16 = call i32 @AES_ecb_encrypt(i8* %13, i8* %14, i32* %5, i32 %15)
%17 = add i32 %11, 16
%18 = icmp ult i32 %17, %1
br i1 %18, label %10, label %9
}