#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ aeshw_init();
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ encrypt_cfb(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               size_t *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          int);
int /*<<< orphan*/ setkey_enc(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
void AES_CFB_encrypt_buffer(uint8_t *output, uint8_t *input, uint32_t length,
                            const uint8_t *key, const uint8_t *iv) {
  uint8_t iv_tmp[16];
  static uint8_t rk[272];
  assert(iv != NULL);
  aeshw_init();
  memcpy(iv_tmp, iv, 16);
  if (key != NULL)
    setkey_enc(rk, key);
  size_t offset = 0;
  encrypt_cfb(rk, length, &offset, iv_tmp, input, output);
}


x86 assembly (clang, -O0):
<AES_CFB_encrypt_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    $0x0,%al
call   1050 <aeshw_init@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     11b4 <AES_CFB_encrypt_buffer+0x64>
mov    -0x20(%rbp),%rsi
lea    0x2eb1(%rip),%rdi
call   1060 <setkey_enc@plt>
movq   $0x0,-0x78(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x70(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x8(%rbp),%r9
lea    0x2e8e(%rip),%rdi
lea    -0x78(%rbp),%rdx
call   1070 <encrypt_cfb@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AES_CFB_encrypt_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r8,%r8
setne  %dil
call   1030 <assert@plt>
xor    %eax,%eax
call   1050 <aeshw_init@plt>
lea    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
test   %rbx,%rbx
je     11a6 <AES_CFB_encrypt_buffer+0x56>
lea    0x2ec2(%rip),%rdi
mov    %rbx,%rsi
call   1060 <setkey_enc@plt>
movq   $0x0,0x8(%rsp)
lea    0x2eaa(%rip),%rdi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r12d,%esi
mov    %r14,%r8
mov    %r15,%r9
call   1070 <encrypt_cfb@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AES_CFB_encrypt_buffer.rk = internal global [272 x i32] zeroinitializer
define void @AES_CFB_encrypt_buffer(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [16 x i32]
%12 = alloca i64
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i32*, i32** %10
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 (...) @aeshw_init()
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%19 = load i32*, i32** %10
%20 = call i32 @memcpy(i32* %18, i32* %19, i32 16)
%21 = load i32*, i32** %9
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %5
%24 = load i32*, i32** %9
%25 = call i32 @setkey_enc(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CFB_encrypt_buffer.rk, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %23, %5
store i64 0, i64* %12
%27 = load i32, i32* %8
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 0
%29 = load i32*, i32** %7
%30 = load i32*, i32** %6
%31 = call i32 @encrypt_cfb(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CFB_encrypt_buffer.rk, i64 0, i64 0), i32 %27, i64* %12, i32* %28, i32* %29, i32* %30)
ret void
}

LLVM IR (-O2):
@AES_CFB_encrypt_buffer.rk = internal global [272 x i32] zeroinitializer
define void @AES_CFB_encrypt_buffer(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca [16 x i32]
%7 = alloca i64
%8 = bitcast [16 x i32]* %6 to i8*
%9 = icmp ne i32* %4, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 (...) @aeshw_init()
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %6, i64 0, i64 0
%14 = call i32 @memcpy(i32* %13, i32* %4, i32 16)
%15 = icmp eq i32* %3, null
br i1 %15, label %18, label %16
16: ; preds = %5
%17 = call i32 @setkey_enc(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CFB_encrypt_buffer.rk, i64 0, i64 0), i32* %3)
br label %18
18: ; preds = %16, %5
%19 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%20 = call i32 @encrypt_cfb(i32* getelementptr inbounds ([272 x i32], [272 x i32]* @AES_CFB_encrypt_buffer.rk, i64 0, i64 0), i32 %2, i64* %7, i32* %13, i32* %1, i32* %0)
ret void
}