#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*/ HMAC_CTX;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_CIPHER_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int /*<<< orphan*/ EVP_aes_256_cbc();
int /*<<< orphan*/ EVP_sha256();
int /*<<< orphan*/ HMAC_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ HMAC_Init_ex(int /*<<< orphan*/ *, unsigned char *, int,
                                int /*<<< orphan*/, int /*<<< orphan*/ *);
int aes_hmac_init(unsigned char *key, unsigned char *iv, EVP_CIPHER_CTX *e_ctx,
                  EVP_CIPHER_CTX *d_ctx, HMAC_CTX *hmac) {
  EVP_CIPHER_CTX_init(e_ctx);
  EVP_EncryptInit_ex(e_ctx, EVP_aes_256_cbc(), NULL, key, iv);
  EVP_CIPHER_CTX_init(d_ctx);
  EVP_DecryptInit_ex(d_ctx, EVP_aes_256_cbc(), NULL, key, iv);
  HMAC_CTX_init(hmac);
  HMAC_Init_ex(hmac, key, 32, EVP_sha256(), NULL);
}


x86 assembly (clang, -O0):
<aes_hmac_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <EVP_CIPHER_CTX_init@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1030 <EVP_aes_256_cbc@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1070 <EVP_EncryptInit_ex@plt>
mov    -0x28(%rbp),%rdi
call   1050 <EVP_CIPHER_CTX_init@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1030 <EVP_aes_256_cbc@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1060 <EVP_DecryptInit_ex@plt>
mov    -0x30(%rbp),%rdi
call   1040 <HMAC_CTX_init@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1090 <EVP_sha256@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%ecx
mov    $0x20,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <HMAC_Init_ex@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_hmac_init>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r13
mov    %rdx,%rdi
call   1050 <EVP_CIPHER_CTX_init@plt>
xor    %eax,%eax
call   1030 <EVP_aes_256_cbc@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r13,%rcx
mov    %r15,%r8
call   1070 <EVP_EncryptInit_ex@plt>
mov    %r12,%rdi
call   1050 <EVP_CIPHER_CTX_init@plt>
xor    %eax,%eax
call   1030 <EVP_aes_256_cbc@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r13,%rcx
mov    %r15,%r8
call   1060 <EVP_DecryptInit_ex@plt>
mov    %r14,%rdi
call   1040 <HMAC_CTX_init@plt>
xor    %eax,%eax
call   1090 <EVP_sha256@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x20,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <HMAC_Init_ex@plt>

LLVM IR (-O0):
define i32 @aes_hmac_init(i8* %0, i8* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%12 = load i32*, i32** %9
%13 = call i32 @EVP_CIPHER_CTX_init(i32* %12)
%14 = load i32*, i32** %9
%15 = call i32 (...) @EVP_aes_256_cbc()
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = call i32 @EVP_EncryptInit_ex(i32* %14, i32 %15, i32* null, i8* %16, i8* %17)
%19 = load i32*, i32** %10
%20 = call i32 @EVP_CIPHER_CTX_init(i32* %19)
%21 = load i32*, i32** %10
%22 = call i32 (...) @EVP_aes_256_cbc()
%23 = load i8*, i8** %7
%24 = load i8*, i8** %8
%25 = call i32 @EVP_DecryptInit_ex(i32* %21, i32 %22, i32* null, i8* %23, i8* %24)
%26 = load i32*, i32** %11
%27 = call i32 @HMAC_CTX_init(i32* %26)
%28 = load i32*, i32** %11
%29 = load i8*, i8** %7
%30 = call i32 (...) @EVP_sha256()
%31 = call i32 @HMAC_Init_ex(i32* %28, i8* %29, i32 32, i32 %30, i32* null)
%32 = load i32, i32* %6
ret i32 %32
}

LLVM IR (-O2):
define i32 @aes_hmac_init(i8* %0, i8* %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @EVP_CIPHER_CTX_init(i32* %2)
%7 = tail call i32 (...) @EVP_aes_256_cbc()
%8 = tail call i32 @EVP_EncryptInit_ex(i32* %2, i32 %7, i32* null, i8* %0, i8* %1)
%9 = tail call i32 @EVP_CIPHER_CTX_init(i32* %3)
%10 = tail call i32 (...) @EVP_aes_256_cbc()
%11 = tail call i32 @EVP_DecryptInit_ex(i32* %3, i32 %10, i32* null, i8* %0, i8* %1)
%12 = tail call i32 @HMAC_CTX_init(i32* %4)
%13 = tail call i32 (...) @EVP_sha256()
%14 = tail call i32 @HMAC_Init_ex(i32* %4, i8* %0, i32 32, i32 %13, i32* null)
ret i32 undef
}