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

/* Variables and functions */
int /*<<< orphan*/ aegis128L_enc_aut_step(unsigned char const *,
                                          unsigned char *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void aegis128L_enc_partial(__m128i *state, const unsigned char *m,
                           unsigned long long mlen, unsigned char *c) {
  unsigned char plaintextblock[32], ciphertextblock[32];
  unsigned long long i;
  for (i = 0; (i + 32) <= mlen; i += 32)
    aegis128L_enc_aut_step(m + i, c + i, state);
  if ((mlen & 0x1f) != 0) {
    memset(plaintextblock, 0, 32);
    memcpy(plaintextblock, m + i, mlen & 0x1f);
    aegis128L_enc_aut_step(plaintextblock, ciphertextblock, state);
    memcpy(c + i, ciphertextblock, mlen & 0x1f);
  }
}


x86 assembly (clang, -O0):
<aegis128L_enc_partial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x20,%rax
cmp    -0x18(%rbp),%rax
ja     118c <aegis128L_enc_partial+0x5c>
mov    -0x10(%rbp),%rdi
add    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x68(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1050 <aegis128L_enc_aut_step@plt>
mov    -0x68(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x68(%rbp)
jmp    1150 <aegis128L_enc_partial+0x20>
mov    -0x18(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     11f1 <aegis128L_enc_partial+0xc1>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x68(%rbp),%rsi
mov    -0x18(%rbp),%rdx
and    $0x1f,%rdx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1050 <aegis128L_enc_aut_step@plt>
mov    -0x20(%rbp),%rdi
add    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rdx
and    $0x1f,%rdx
call   1040 <memcpy@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aegis128L_enc_partial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
cmp    $0x20,%rdx
jae    1155 <aegis128L_enc_partial+0x25>
xor    %r13d,%r13d
jmp    1180 <aegis128L_enc_partial+0x50>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdi
lea    (%r14,%rbp,1),%rsi
mov    %r15,%rdx
call   1050 <aegis128L_enc_aut_step@plt>
lea    0x20(%rbp),%r13
add    $0x40,%rbp
cmp    %r12,%rbp
mov    %r13,%rbp
jbe    1160 <aegis128L_enc_partial+0x30>
and    $0x1f,%r12
je     11cd <aegis128L_enc_partial+0x9d>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
add    %r13,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %rsp,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <aegis128L_enc_aut_step@plt>
add    %r13,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aegis128L_enc_partial(i32* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca [32 x i8]
%10 = alloca [32 x i8]
%11 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
store i64 0, i64* %11
br label %12
12: ; preds = %26, %4
%13 = load i64, i64* %11
%14 = add i64 %13, 32
%15 = load i64, i64* %7
%16 = icmp ule i64 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = load i64, i64* %11
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8*, i8** %8
%22 = load i64, i64* %11
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i32*, i32** %5
%25 = call i32 @aegis128L_enc_aut_step(i8* %20, i8* %23, i32* %24)
br label %26
26: ; preds = %17
%27 = load i64, i64* %11
%28 = add i64 %27, 32
store i64 %28, i64* %11
br label %12
29: ; preds = %12
%30 = load i64, i64* %7
%31 = and i64 %30, 31
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %29
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 32)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %6
%38 = load i64, i64* %11
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i64, i64* %7
%41 = and i64 %40, 31
%42 = call i32 @memcpy(i8* %36, i8* %39, i64 %41)
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%45 = load i32*, i32** %5
%46 = call i32 @aegis128L_enc_aut_step(i8* %43, i8* %44, i32* %45)
%47 = load i8*, i8** %8
%48 = load i64, i64* %11
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%51 = load i64, i64* %7
%52 = and i64 %51, 31
%53 = call i32 @memcpy(i8* %49, i8* %50, i64 %52)
br label %54
54: ; preds = %33, %29
ret void
}

LLVM IR (-O2):
define void @aegis128L_enc_partial(i32* %0, i8* %1, i64 %2, i8* %3) {
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = icmp ult i64 %2, 32
br i1 %9, label %18, label %10
10: ; preds = %4, %10
%11 = phi i64 [ %16, %10 ], [ 32, %4 ]
%12 = phi i64 [ %11, %10 ], [ 0, %4 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = getelementptr inbounds i8, i8* %3, i64 %12
%15 = tail call i32 @aegis128L_enc_aut_step(i8* %13, i8* %14, i32* %0)
%16 = add i64 %11, 32
%17 = icmp ugt i64 %16, %2
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = phi i64 [ 0, %4 ], [ %11, %10 ]
%20 = and i64 %2, 31
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %18
%23 = call i32 @memset(i8* %7, i32 0, i32 32)
%24 = getelementptr inbounds i8, i8* %1, i64 %19
%25 = call i32 @memcpy(i8* %7, i8* %24, i64 %20)
%26 = call i32 @aegis128L_enc_aut_step(i8* %7, i8* %8, i32* %0)
%27 = getelementptr inbounds i8, i8* %3, i64 %19
%28 = call i32 @memcpy(i8* %27, i8* %8, i64 %20)
br label %29
29: ; preds = %22, %18
ret void
}