#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_enc_aut_partialblock(const unsigned char *plaintext,
                                unsigned char *ciphertext, unsigned long len,
                                __m128i *state) {
  unsigned char plaintextblock[16], ciphertextblock[16];
  __m128i keystream;
  __m128i msgblk;
  memset(plaintextblock, 0, 16);
  memcpy(plaintextblock, plaintext, len);
  msgblk = _mm_load_si128((__m128i *)plaintextblock);
  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]))));
  _mm_store_si128((__m128i *)ciphertextblock,
                  _mm_xor_si128((keystream), (msgblk)));
  memcpy(ciphertext, ciphertextblock, len);
  morus_stateupdate(msgblk, state);
}


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

x86 assembly (clang, -O2):
<morus_enc_aut_partialblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <memcpy@plt>
mov    %r12,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,%r12d
mov    (%rbx),%r13d
mov    0x4(%rbx),%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    %r13d,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%edi
mov    0xc(%rbx),%esi
call   10b0 <_mm_and_si128@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1090 <_mm_xor_si128@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   1090 <_mm_xor_si128@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1060 <_mm_store_si128@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <memcpy@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   10a0 <morus_stateupdate@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @morus_enc_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]* %9, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 16)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = load i64, i64* %7
%18 = call i32 @memcpy(i8* %15, i8* %16, i64 %17)
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %9, 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 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%41 = bitcast i8* %40 to i32*
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = call i32 @_mm_xor_si128(i32 %42, i32 %43)
%45 = call i32 @_mm_store_si128(i32* %41, i32 %44)
%46 = load i8*, i8** %6
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%48 = load i64, i64* %7
%49 = call i32 @memcpy(i8* %46, i8* %47, i64 %48)
%50 = load i32, i32* %12
%51 = load i32*, i32** %8
%52 = call i32 @morus_stateupdate(i32 %50, i32* %51)
ret void
}

LLVM IR (-O2):
define void @morus_enc_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* %7, i32 0, i32 16)
%10 = call i32 @memcpy(i8* %7, i8* %0, i64 %2)
%11 = bitcast [16 x i8]* %5 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 = bitcast [16 x i8]* %6 to i32*
%26 = call i32 @_mm_xor_si128(i32 %24, i32 %12)
%27 = call i32 @_mm_store_si128(i32* %25, i32 %26)
%28 = call i32 @memcpy(i8* %1, i8* %8, i64 %2)
%29 = call i32 @morus_stateupdate(i32 %12, i32* %3)
ret void
}