#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 */
unsigned long AES_BLOCK_SIZE;
int /*<<< orphan*/ AES_encrypt(unsigned char *, unsigned char *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ AES_set_encrypt_key(unsigned char const *, int,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long);
int aes_128_cbc_mac0(const unsigned long length, const unsigned char key[16],
                     const unsigned char iv[AES_BLOCK_SIZE],
                     unsigned char out[AES_BLOCK_SIZE]) {
  AES_KEY akey;
  unsigned long len = length;
  AES_set_encrypt_key(&key[0], 128, &akey);
  memcpy(&out[0], &iv[0], AES_BLOCK_SIZE);
  while (len >= AES_BLOCK_SIZE) {
    AES_encrypt(out, out, &akey);
    len -= AES_BLOCK_SIZE;
  }
  if (len != 0)
    AES_encrypt(out, out, &akey);
  return 0;
}


x86 assembly (clang, -O0):
<aes_128_cbc_mac0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x80,%esi
lea    -0x24(%rbp),%rdx
call   1030 <AES_set_encrypt_key@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e77(%rip),%rax
mov    (%rax),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jb     11b8 <aes_128_cbc_mac0+0x88>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <AES_encrypt@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1179 <aes_128_cbc_mac0+0x49>
cmpq   $0x0,-0x30(%rbp)
je     11d4 <aes_128_cbc_mac0+0xa4>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <AES_encrypt@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_128_cbc_mac0>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
lea    0x4(%rsp),%rdx
mov    %rsi,%rdi
mov    $0x80,%esi
call   1030 <AES_set_encrypt_key@plt>
mov    0x2e8e(%rip),%r12
mov    (%r12),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
cmp    %rbx,(%r12)
ja     119a <aes_128_cbc_mac0+0x6a>
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <AES_encrypt@plt>
mov    (%r12),%rax
sub    %rax,%rbx
cmp    %rax,%rbx
jae    1180 <aes_128_cbc_mac0+0x50>
test   %rbx,%rbx
je     11af <aes_128_cbc_mac0+0x7f>
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %r14,%rsi
call   1050 <AES_encrypt@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AES_BLOCK_SIZE = global i64 0
define i32 @aes_128_cbc_mac0(i64 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
store i64 %0, i64* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i64, i64* @AES_BLOCK_SIZE
%12 = load i64, i64* @AES_BLOCK_SIZE
%13 = load i64, i64* %5
store i64 %13, i64* %10
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = call i32 @AES_set_encrypt_key(i8* %15, i32 128, i32* %9)
%17 = load i8*, i8** %8
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i64, i64* @AES_BLOCK_SIZE
%22 = call i32 @memcpy(i8* %18, i8* %20, i64 %21)
br label %23
23: ; preds = %27, %4
%24 = load i64, i64* %10
%25 = load i64, i64* @AES_BLOCK_SIZE
%26 = icmp uge i64 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i8*, i8** %8
%29 = load i8*, i8** %8
%30 = call i32 @AES_encrypt(i8* %28, i8* %29, i32* %9)
%31 = load i64, i64* @AES_BLOCK_SIZE
%32 = load i64, i64* %10
%33 = sub i64 %32, %31
store i64 %33, i64* %10
br label %23
34: ; preds = %23
%35 = load i64, i64* %10
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i8*, i8** %8
%39 = load i8*, i8** %8
%40 = call i32 @AES_encrypt(i8* %38, i8* %39, i32* %9)
br label %41
41: ; preds = %37, %34
ret i32 0
}

LLVM IR (-O2):
@AES_BLOCK_SIZE = global i64 0
define i32 @aes_128_cbc_mac0(i64 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @AES_set_encrypt_key(i8* %1, i32 128, i32* %5)
%8 = load i64, i64* @AES_BLOCK_SIZE
%9 = call i32 @memcpy(i8* %3, i8* %2, i64 %8)
%10 = load i64, i64* @AES_BLOCK_SIZE
%11 = icmp ugt i64 %10, %0
br i1 %11, label %18, label %12
12: ; preds = %4, %12
%13 = phi i64 [ %16, %12 ], [ %0, %4 ]
%14 = call i32 @AES_encrypt(i8* %3, i8* %3, i32* %5)
%15 = load i64, i64* @AES_BLOCK_SIZE
%16 = sub i64 %13, %15
%17 = icmp ult i64 %16, %15
br i1 %17, label %18, label %12
18: ; preds = %12, %4
%19 = phi i64 [ %0, %4 ], [ %16, %12 ]
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @AES_encrypt(i8* %3, i8* %3, i32* %5)
br label %23
23: ; preds = %21, %18
ret i32 0
}