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

/* Variables and functions */
int /*<<< orphan*/ aes_cipher(int const, char const *, char const *, char *);
short aes_pkcs7padding(char const *, size_t const, char *);
void aes_ecbenc(const int bits, const char *in, const size_t length,
                const char *key, char *out) {
  char blk[16];
  for (size_t d = 0; d + 15 < length; d += 16) {
    aes_cipher(bits, in + d, key, out + d);
  }
  short quot = aes_pkcs7padding(in, length, blk);
  aes_cipher(bits, blk, key, out + length - quot);
}


x86 assembly (clang, -O0):
<aes_ecbenc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0xf,%rax
cmp    -0x18(%rbp),%rax
jae    1182 <aes_ecbenc+0x62>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    -0x48(%rbp),%rcx
call   1040 <aes_cipher@plt>
mov    -0x48(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x48(%rbp)
jmp    1143 <aes_ecbenc+0x23>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <aes_pkcs7padding@plt>
mov    %ax,-0x4a(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    -0x18(%rbp),%rcx
movswl -0x4a(%rbp),%eax
movslq %eax,%r8
xor    %eax,%eax
sub    %r8,%rax
add    %rax,%rcx
call   1040 <aes_cipher@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_ecbenc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x8(%rsp)
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,(%rsp)
mov    %edi,%r13d
cmp    $0x10,%rdx
jb     1182 <aes_ecbenc+0x62>
mov    $0xf,%r14d
mov    0x8(%rsp),%rbp
mov    (%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1040 <aes_cipher@plt>
add    $0x10,%r12
add    $0x10,%rbp
add    $0x10,%r14
cmp    %rbx,%r14
jb     1160 <aes_ecbenc+0x40>
lea    0x10(%rsp),%rbp
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <aes_pkcs7padding@plt>
mov    0x8(%rsp),%rcx
add    %rbx,%rcx
movswq %ax,%rax
sub    %rax,%rcx
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <aes_cipher@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aes_ecbenc(i32 %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [16 x i8]
%12 = alloca i64
%13 = alloca i16
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i64 0, i64* %12
br label %14
14: ; preds = %29, %5
%15 = load i64, i64* %12
%16 = add i64 %15, 15
%17 = load i64, i64* %8
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %12
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8*, i8** %9
%25 = load i8*, i8** %10
%26 = load i64, i64* %12
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = call i32 @aes_cipher(i32 %20, i8* %23, i8* %24, i8* %27)
br label %29
29: ; preds = %19
%30 = load i64, i64* %12
%31 = add i64 %30, 16
store i64 %31, i64* %12
br label %14
32: ; preds = %14
%33 = load i8*, i8** %7
%34 = load i64, i64* %8
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%36 = call signext i16 @aes_pkcs7padding(i8* %33, i64 %34, i8* %35)
store i16 %36, i16* %13
%37 = load i32, i32* %6
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%39 = load i8*, i8** %9
%40 = load i8*, i8** %10
%41 = load i64, i64* %8
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i16, i16* %13
%44 = sext i16 %43 to i32
%45 = sext i32 %44 to i64
%46 = sub i64 0, %45
%47 = getelementptr inbounds i8, i8* %42, i64 %46
%48 = call i32 @aes_cipher(i32 %37, i8* %38, i8* %39, i8* %47)
ret void
}

LLVM IR (-O2):
define void @aes_ecbenc(i32 %0, i8* %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = icmp ugt i64 %2, 15
br i1 %8, label %16, label %9
9: ; preds = %16, %5
%10 = call signext i16 @aes_pkcs7padding(i8* %1, i64 %2, i8* %7)
%11 = getelementptr inbounds i8, i8* %4, i64 %2
%12 = sext i16 %10 to i64
%13 = sub nsw i64 0, %12
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i32 @aes_cipher(i32 %0, i8* %7, i8* %3, i8* %14)
ret void
16: ; preds = %5, %16
%17 = phi i64 [ %21, %16 ], [ 0, %5 ]
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = getelementptr inbounds i8, i8* %4, i64 %17
%20 = tail call i32 @aes_cipher(i32 %0, i8* %18, i8* %3, i8* %19)
%21 = add i64 %17, 16
%22 = or i64 %21, 15
%23 = icmp ult i64 %22, %2
br i1 %23, label %16, label %9
}