#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_SHUFFLE(int /*<<< orphan*/, int, int, int);
int /*<<< orphan*/ _mm_and_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_si128(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_shuffle_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_store_si128(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_xor_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ morus_stateupdate(int /*<<< orphan*/, int /*<<< orphan*/ *);
void morus_dec_aut_partialblock(unsigned char *plaintext,
                                const unsigned char *ciphertext,
                                unsigned long len, __m128i *state) {
  unsigned char plaintextblock[16], ciphertextblock[16];
  __m128i keystream;
  __m128i msgblk;
  memset(ciphertextblock, 0, 16);
  memcpy(ciphertextblock, ciphertext, len);
  msgblk = _mm_load_si128((__m128i *)ciphertextblock);
  keystream = _mm_xor_si128(
      (state[0]), (_mm_shuffle_epi32((state[1]), _MM_SHUFFLE(0, 3, 2, 1))));
  keystream =
      _mm_xor_si128((keystream), (_mm_and_si128((state[2]), (state[3]))));
  msgblk = _mm_xor_si128((keystream), (msgblk));
  _mm_store_si128((__m128i *)plaintextblock, msgblk);
  memset(plaintextblock + len, 0, 16 - len);
  memcpy(plaintext, plaintextblock, len);
  msgblk = _mm_load_si128((__m128i *)plaintextblock);
  morus_stateupdate(msgblk, state);
}


x86 assembly (clang, -O0):
<morus_dec_aut_partialblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <memcpy@plt>
lea    -0x40(%rbp),%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x54(%rbp)
xor    %edi,%edi
mov    $0x3,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    -0x54(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_shuffle_epi32@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%esi
call   10b0 <_mm_and_si128@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   1060 <_mm_store_si128@plt>
lea    -0x30(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    $0x10,%eax
sub    -0x18(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <memcpy@plt>
lea    -0x30(%rbp),%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10a0 <morus_stateupdate@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morus_dec_aut_partialblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,0x8(%rsp)
lea    0x20(%rsp),%rbx
mov    $0x10,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,%r12d
mov    (%r15),%ebx
mov    0x4(%r15),%ebp
xor    %edi,%edi
mov    $0x3,%esi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1030 <_MM_SHUFFLE@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1070 <_mm_shuffle_epi32@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%ebx
mov    0x8(%r15),%edi
mov    0xc(%r15),%esi
call   10b0 <_mm_and_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   1090 <_mm_xor_si128@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <_mm_store_si128@plt>
lea    (%rsp,%r14,1),%rdi
add    $0x10,%rdi
sub    %r14d,%r13d
xor    %esi,%esi
mov    %r13d,%edx
call   1050 <memset@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   10a0 <morus_stateupdate@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @morus_dec_aut_partialblock(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 16)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = call i32 @memcpy(i8* %15, i8* %16, i64 %17)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%20 = bitcast i8* %19 to i32*
%21 = call i32 @_mm_load_si128(i32* %20)
store i32 %21, i32* %12
%22 = load i32*, i32** %8
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = load i32*, i32** %8
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = call i32 @_MM_SHUFFLE(i32 0, i32 3, i32 2, i32 1)
%29 = call i32 @_mm_shuffle_epi32(i32 %27, i32 %28)
%30 = call i32 @_mm_xor_si128(i32 %24, i32 %29)
store i32 %30, i32* %11
%31 = load i32, i32* %11
%32 = load i32*, i32** %8
%33 = getelementptr inbounds i32, i32* %32, i64 2
%34 = load i32, i32* %33
%35 = load i32*, i32** %8
%36 = getelementptr inbounds i32, i32* %35, i64 3
%37 = load i32, i32* %36
%38 = call i32 @_mm_and_si128(i32 %34, i32 %37)
%39 = call i32 @_mm_xor_si128(i32 %31, i32 %38)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = load i32, i32* %12
%42 = call i32 @_mm_xor_si128(i32 %40, i32 %41)
store i32 %42, i32* %12
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %12
%46 = call i32 @_mm_store_si128(i32* %44, i32 %45)
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%48 = load i64, i64* %7
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i64, i64* %7
%51 = sub i64 16, %50
%52 = trunc i64 %51 to i32
%53 = call i32 @memset(i8* %49, i32 0, i32 %52)
%54 = load i8*, i8** %5
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%56 = load i64, i64* %7
%57 = call i32 @memcpy(i8* %54, i8* %55, i64 %56)
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%59 = bitcast i8* %58 to i32*
%60 = call i32 @_mm_load_si128(i32* %59)
store i32 %60, i32* %12
%61 = load i32, i32* %12
%62 = load i32*, i32** %8
%63 = call i32 @morus_stateupdate(i32 %61, i32* %62)
ret void
}

LLVM IR (-O2):
define void @morus_dec_aut_partialblock(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 16)
%10 = call i32 @memcpy(i8* %8, i8* %1, i64 %2)
%11 = bitcast [16 x i8]* %6 to i32*
%12 = call i32 @_mm_load_si128(i32* %11)
%13 = load i32, i32* %3
%14 = getelementptr inbounds i32, i32* %3, i64 1
%15 = load i32, i32* %14
%16 = call i32 @_MM_SHUFFLE(i32 0, i32 3, i32 2, i32 1)
%17 = call i32 @_mm_shuffle_epi32(i32 %15, i32 %16)
%18 = call i32 @_mm_xor_si128(i32 %13, i32 %17)
%19 = getelementptr inbounds i32, i32* %3, i64 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds i32, i32* %3, i64 3
%22 = load i32, i32* %21
%23 = call i32 @_mm_and_si128(i32 %20, i32 %22)
%24 = call i32 @_mm_xor_si128(i32 %18, i32 %23)
%25 = call i32 @_mm_xor_si128(i32 %24, i32 %12)
%26 = bitcast [16 x i8]* %5 to i32*
%27 = call i32 @_mm_store_si128(i32* %26, i32 %25)
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %2
%29 = trunc i64 %2 to i32
%30 = sub i32 16, %29
%31 = call i32 @memset(i8* %28, i32 0, i32 %30)
%32 = call i32 @memcpy(i8* %0, i8* %7, i64 %2)
%33 = call i32 @_mm_load_si128(i32* %26)
%34 = call i32 @morus_stateupdate(i32 %33, i32* %3)
ret void
}