#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*/ _mm_load_si128(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ aegis128L_dec_aut_step(unsigned char *,
                                          unsigned char const *,
                                          int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/,
                          unsigned long long);
void aegis128L_dec_partial(__m128i *state, unsigned char *m,
                           unsigned long long mlen, const unsigned char *c) {
  unsigned char plaintextblock[32], ciphertextblock[32];
  unsigned long long i;
  for (i = 0; (i + 32) <= mlen; i += 32)
    aegis128L_dec_aut_step(m + i, c + i, state);
  if ((mlen & 0x1f) != 0) {
    memset(ciphertextblock, 0, 32);
    memcpy(ciphertextblock, c + i, mlen & 0x1f);
    aegis128L_dec_aut_step(plaintextblock, ciphertextblock, state);
    memcpy(m + i, plaintextblock, mlen & 0x1f);
    memset(plaintextblock, 0, mlen & 0x1f);
    state[0] =
        _mm_xor_si128(state[0], _mm_load_si128((__m128i *)plaintextblock));
    state[4] = _mm_xor_si128(state[4],
                             _mm_load_si128((__m128i *)(plaintextblock + 16)));
  }
}


x86 assembly (clang, -O0):
<aegis128L_dec_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     11ac <aegis128L_dec_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_dec_aut_step@plt>
mov    -0x68(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x68(%rbp)
jmp    1170 <aegis128L_dec_partial+0x20>
mov    -0x18(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
je     1272 <aegis128L_dec_partial+0x122>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    -0x68(%rbp),%rsi
mov    -0x18(%rbp),%rdx
and    $0x1f,%rdx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1050 <aegis128L_dec_aut_step@plt>
mov    -0x10(%rbp),%rdi
add    -0x68(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
and    $0x1f,%rdx
call   1060 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
and    $0x1f,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <_mm_load_si128@plt>
mov    -0x70(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x10,%rdi
call   1030 <_mm_load_si128@plt>
mov    -0x6c(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aegis128L_dec_partial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x20,%rdx
jae    1175 <aegis128L_dec_partial+0x25>
xor    %r13d,%r13d
jmp    11a0 <aegis128L_dec_partial+0x50>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbp,1),%rdi
lea    (%rbx,%rbp,1),%rsi
mov    %r14,%rdx
call   1050 <aegis128L_dec_aut_step@plt>
lea    0x20(%rbp),%r13
add    $0x40,%rbp
cmp    %r12,%rbp
mov    %r13,%rbp
jbe    1180 <aegis128L_dec_partial+0x30>
and    $0x1f,%r12
je     1230 <aegis128L_dec_partial+0xe0>
lea    0x20(%rsp),%rbp
mov    $0x20,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
add    %r13,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <aegis128L_dec_aut_step@plt>
add    %r13,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    (%r14),%ebp
mov    %rbx,%rdi
call   1030 <_mm_load_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,(%r14)
mov    0x10(%r14),%ebx
lea    0x10(%rsp),%rdi
call   1030 <_mm_load_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <_mm_xor_si128@plt>
mov    %eax,0x10(%r14)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aegis128L_dec_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_dec_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 %77
33: ; preds = %29
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i64 32)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%37 = load i8*, i8** %8
%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_dec_aut_step(i8* %43, i8* %44, i32* %45)
%47 = load i8*, i8** %6
%48 = load i64, i64* %11
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%51 = load i64, i64* %7
%52 = and i64 %51, 31
%53 = call i32 @memcpy(i8* %49, i8* %50, i64 %52)
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%55 = load i64, i64* %7
%56 = and i64 %55, 31
%57 = call i32 @memset(i8* %54, i32 0, i64 %56)
%58 = load i32*, i32** %5
%59 = getelementptr inbounds i32, i32* %58, i64 0
%60 = load i32, i32* %59
%61 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%62 = bitcast i8* %61 to i32*
%63 = call i32 @_mm_load_si128(i32* %62)
%64 = call i32 @_mm_xor_si128(i32 %60, i32 %63)
%65 = load i32*, i32** %5
%66 = getelementptr inbounds i32, i32* %65, i64 0
store i32 %64, i32* %66
%67 = load i32*, i32** %5
%68 = getelementptr inbounds i32, i32* %67, i64 4
%69 = load i32, i32* %68
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%71 = getelementptr inbounds i8, i8* %70, i64 16
%72 = bitcast i8* %71 to i32*
%73 = call i32 @_mm_load_si128(i32* %72)
%74 = call i32 @_mm_xor_si128(i32 %69, i32 %73)
%75 = load i32*, i32** %5
%76 = getelementptr inbounds i32, i32* %75, i64 4
store i32 %74, i32* %76
br label %77
77: ; preds = %33, %29
ret void
}

LLVM IR (-O2):
define void @aegis128L_dec_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_dec_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 %40, label %22
22: ; preds = %18
%23 = call i32 @memset(i8* %8, i32 0, i64 32)
%24 = getelementptr inbounds i8, i8* %3, i64 %19
%25 = call i32 @memcpy(i8* %8, i8* %24, i64 %20)
%26 = call i32 @aegis128L_dec_aut_step(i8* %7, i8* %8, i32* %0)
%27 = getelementptr inbounds i8, i8* %1, i64 %19
%28 = call i32 @memcpy(i8* %27, i8* %7, i64 %20)
%29 = call i32 @memset(i8* %7, i32 0, i64 %20)
%30 = load i32, i32* %0
%31 = bitcast [32 x i8]* %5 to i32*
%32 = call i32 @_mm_load_si128(i32* %31)
%33 = call i32 @_mm_xor_si128(i32 %30, i32 %32)
store i32 %33, i32* %0
%34 = getelementptr inbounds i32, i32* %0, i64 4
%35 = load i32, i32* %34
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 16
%37 = bitcast i8* %36 to i32*
%38 = call i32 @_mm_load_si128(i32* %37)
%39 = call i32 @_mm_xor_si128(i32 %35, i32 %38)
store i32 %39, i32* %34
br label %40
40: ; preds = %22, %18
ret void
}