#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_ad_partial(__m128i *state, const unsigned char *ad,
                          unsigned long long adlen) {
  unsigned char plaintextblock[32], ciphertextblock[32];
  unsigned long long i;
  for (i = 0; (i + 32) <= adlen; i += 32)
    aegis128L_enc_aut_step(ad + i, ciphertextblock, state);
  if ((adlen & 0x1f) != 0) {
    memset(plaintextblock, 0, 32);
    memcpy(plaintextblock, ad + i, adlen & 0x1f);
    aegis128L_enc_aut_step(plaintextblock, ciphertextblock, state);
  }
}


x86 assembly (clang, -O0):
<aegis128L_ad_partial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x20,%rax
cmp    -0x18(%rbp),%rax
ja     1184 <aegis128L_ad_partial+0x54>
mov    -0x10(%rbp),%rdi
add    -0x68(%rbp),%rdi
lea    -0x60(%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    114c <aegis128L_ad_partial+0x1c>
mov    -0x18(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     11d0 <aegis128L_ad_partial+0xa0>
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>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aegis128L_ad_partial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x20,%rdx
jae    1151 <aegis128L_ad_partial+0x21>
xor    %ebx,%ebx
jmp    117f <aegis128L_ad_partial+0x4f>
xor    %ebp,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
lea    (%r15,%rbp,1),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <aegis128L_enc_aut_step@plt>
lea    0x20(%rbp),%rbx
add    $0x40,%rbp
cmp    %r13,%rbp
mov    %rbx,%rbp
jbe    1160 <aegis128L_ad_partial+0x30>
and    $0x1f,%r13
je     11b8 <aegis128L_ad_partial+0x88>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
add    %rbx,%r15
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
mov    %r14,%rdx
call   1050 <aegis128L_enc_aut_step@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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