#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 */
struct ossl_aes_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int ossl_aes_encrypt(struct ossl_aes_ctx *, unsigned char *, size_t,
                     unsigned char *);
int ossl_aes_mangle(struct ossl_aes_ctx *ctx, unsigned char *data,
                    size_t size) {
  int ciphertext_len;
  unsigned char ciphertext[size + 16];
  ciphertext_len = ossl_aes_encrypt(ctx, data, size, ciphertext);
  if (!ciphertext_len)
    return -1;
  memcpy(data, ciphertext, size);
  return ciphertext_len;
}


x86 assembly (clang, -O0):
<ossl_aes_mangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    %rdx,%rax
add    $0x10,%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
add    $0x1f,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <ossl_aes_encrypt@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1190 <ossl_aes_mangle+0x70>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    11ae <ossl_aes_mangle+0x8e>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ossl_aes_mangle>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rsp,%rbx
lea    0x1f(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rcx
call   1030 <ossl_aes_encrypt@plt>
test   %eax,%eax
je     1161 <ossl_aes_mangle+0x41>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
jmp    1167 <ossl_aes_mangle+0x47>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ossl_aes_ctx = type { i32 }
define i32 @ossl_aes_mangle(%struct.ossl_aes_ctx* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.ossl_aes_ctx*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store %struct.ossl_aes_ctx* %0, %struct.ossl_aes_ctx** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i64, i64* %7
%13 = add i64 %12, 16
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = load %struct.ossl_aes_ctx*, %struct.ossl_aes_ctx** %5
%17 = load i8*, i8** %6
%18 = load i64, i64* %7
%19 = call i32 @ossl_aes_encrypt(%struct.ossl_aes_ctx* %16, i8* %17, i64 %18, i8* %15)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %11
br label %28
23: ; preds = %3
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = call i32 @memcpy(i8* %24, i8* %15, i64 %25)
%27 = load i32, i32* %8
store i32 %27, i32* %4
store i32 1, i32* %11
br label %28
28: ; preds = %23, %22
%29 = load i8*, i8** %9
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.ossl_aes_ctx = type { i32 }
define i32 @ossl_aes_mangle(%struct.ossl_aes_ctx* %0, i8* %1, i64 %2) {
%4 = add i64 %2, 16
%5 = alloca i8, i64 %4
%6 = call i32 @ossl_aes_encrypt(%struct.ossl_aes_ctx* %0, i8* %1, i64 %2, i8* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 @memcpy(i8* %1, i8* %5, i64 %2)
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %6, %8 ], [ -1, %3 ]
ret i32 %11
}