#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*/ aegis256_enc_aut_step(unsigned char const *, unsigned char *,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ aegis256_initialization(unsigned char const *,
                                           unsigned char const *,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ aegis256_tag_generation(unsigned long long,
                                           unsigned long long, int,
                                           unsigned char *,
                                           int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int crypto_aead_encrypt(unsigned char *c, unsigned long long *clen,
                        const unsigned char *m, unsigned long long mlen,
                        const unsigned char *ad, unsigned long long adlen,
                        const unsigned char *nsec, const unsigned char *npub,
                        const unsigned char *k) {
  unsigned long long i;
  unsigned char plaintextblock[16], ciphertextblock[16], mac[16];
  __m128i aegis256_state[6];
  aegis256_initialization(k, npub, aegis256_state);
  for (i = 0; (i + 16) <= adlen; i += 16) {
    aegis256_enc_aut_step(ad + i, ciphertextblock, aegis256_state);
  }
  if ((adlen & 0xf) != 0) {
    memset(plaintextblock, 0, 16);
    memcpy(plaintextblock, ad + i, adlen & 0xf);
    aegis256_enc_aut_step(plaintextblock, ciphertextblock, aegis256_state);
  }
  for (i = 0; (i + 16) <= mlen; i += 16) {
    aegis256_enc_aut_step(m + i, c + i, aegis256_state);
  }
  if ((mlen & 0xf) != 0) {
    memset(plaintextblock, 0, 16);
    memcpy(plaintextblock, m + i, mlen & 0xf);
    aegis256_enc_aut_step(plaintextblock, ciphertextblock, aegis256_state);
    memcpy(c + i, ciphertextblock, mlen & 0xf);
  }
  aegis256_tag_generation(mlen, adlen, 16, mac, aegis256_state);
  *clen = mlen + 16;
  memcpy(c + mlen, mac, 16);
  return 0;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x20(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1050 <aegis256_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x10,%rax
cmp    -0x30(%rbp),%rax
ja     11d6 <crypto_aead_encrypt+0x86>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <aegis256_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
jmp    119b <crypto_aead_encrypt+0x4b>
mov    -0x30(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1227 <crypto_aead_encrypt+0xd7>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rax
and    $0xf,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <aegis256_enc_aut_step@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x10,%rax
cmp    -0x20(%rbp),%rax
ja     126e <crypto_aead_encrypt+0x11e>
mov    -0x18(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x38(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <aegis256_enc_aut_step@plt>
mov    -0x38(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
jmp    122f <crypto_aead_encrypt+0xdf>
mov    -0x20(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     12da <crypto_aead_encrypt+0x18a>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rax
and    $0xf,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1070 <aegis256_enc_aut_step@plt>
mov    -0x8(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x20(%rbp),%rax
and    $0xf,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x70(%rbp),%rcx
lea    -0x90(%rbp),%r8
mov    $0x10,%edx
call   1030 <aegis256_tag_generation@plt>
mov    -0x20(%rbp),%rcx
add    $0x10,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rcx,0x38(%rsp)
mov    %rdx,%r15
mov    %rsi,0x30(%rsp)
mov    %rdi,(%rsp)
mov    0xc0(%rsp),%rdi
mov    0xb8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <aegis256_initialization@plt>
cmp    $0x10,%rbx
mov    %rbx,0x8(%rsp)
jae    11a2 <crypto_aead_encrypt+0x52>
mov    %rbx,%rax
xor    %r13d,%r13d
jmp    11d5 <crypto_aead_encrypt+0x85>
xor    %r12d,%r12d
lea    0x40(%rsp),%rbx
lea    0x10(%rsp),%r14
nop
lea    (%r12,%rbp,1),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <aegis256_enc_aut_step@plt>
mov    0x8(%rsp),%rax
lea    0x10(%r12),%r13
add    $0x20,%r12
cmp    %rax,%r12
mov    %r13,%r12
jbe    11b0 <crypto_aead_encrypt+0x60>
mov    %rax,%rbx
and    $0xf,%rbx
je     1214 <crypto_aead_encrypt+0xc4>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
add    %r13,%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
lea    0x40(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1070 <aegis256_enc_aut_step@plt>
mov    0x38(%rsp),%r12
cmp    $0x10,%r12
jae    1227 <crypto_aead_encrypt+0xd7>
xor    %ebx,%ebx
mov    (%rsp),%r13
jmp    1262 <crypto_aead_encrypt+0x112>
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
mov    (%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r15,%rbp,1),%rdi
mov    %r13,%rsi
add    %rbp,%rsi
mov    %r14,%rdx
call   1070 <aegis256_enc_aut_step@plt>
lea    0x10(%rbp),%rbx
add    $0x20,%rbp
cmp    %r12,%rbp
mov    %rbx,%rbp
jbe    1240 <crypto_aead_encrypt+0xf0>
mov    %r12,%rbp
and    $0xf,%rbp
je     12b4 <crypto_aead_encrypt+0x164>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
add    %rbx,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
lea    0x40(%rsp),%r15
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <aegis256_enc_aut_step@plt>
add    %r13,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
lea    0x60(%rsp),%rbx
lea    0x10(%rsp),%r8
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    $0x10,%edx
mov    %rbx,%rcx
call   1030 <aegis256_tag_generation@plt>
lea    0x10(%r12),%rax
mov    0x30(%rsp),%rcx
mov    %rax,(%rcx)
add    %r12,%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @crypto_aead_encrypt(i8* %0, i64* %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* %6, i8* %7, i8* %8) {
%10 = alloca i8*
%11 = alloca i64*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i64
%20 = alloca [16 x i8]
%21 = alloca [16 x i8]
%22 = alloca [16 x i8]
%23 = alloca [6 x i32]
store i8* %0, i8** %10
store i64* %1, i64** %11
store i8* %2, i8** %12
store i64 %3, i64* %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store i8* %6, i8** %16
store i8* %7, i8** %17
store i8* %8, i8** %18
%24 = load i8*, i8** %18
%25 = load i8*, i8** %17
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%27 = call i32 @aegis256_initialization(i8* %24, i8* %25, i32* %26)
store i64 0, i64* %19
br label %28
28: ; preds = %40, %9
%29 = load i64, i64* %19
%30 = add i64 %29, 16
%31 = load i64, i64* %15
%32 = icmp ule i64 %30, %31
br i1 %32, label %33, label %43
33: ; preds = %28
%34 = load i8*, i8** %14
%35 = load i64, i64* %19
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%38 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%39 = call i32 @aegis256_enc_aut_step(i8* %36, i8* %37, i32* %38)
br label %40
40: ; preds = %33
%41 = load i64, i64* %19
%42 = add i64 %41, 16
store i64 %42, i64* %19
br label %28
43: ; preds = %28
%44 = load i64, i64* %15
%45 = and i64 %44, 15
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%49 = call i32 @memset(i8* %48, i32 0, i32 16)
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%51 = load i8*, i8** %14
%52 = load i64, i64* %19
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i64, i64* %15
%55 = and i64 %54, 15
%56 = trunc i64 %55 to i32
%57 = call i32 @memcpy(i8* %50, i8* %53, i32 %56)
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%60 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%61 = call i32 @aegis256_enc_aut_step(i8* %58, i8* %59, i32* %60)
br label %62
62: ; preds = %47, %43
store i64 0, i64* %19
br label %63
63: ; preds = %77, %62
%64 = load i64, i64* %19
%65 = add i64 %64, 16
%66 = load i64, i64* %13
%67 = icmp ule i64 %65, %66
br i1 %67, label %68, label %80
68: ; preds = %63
%69 = load i8*, i8** %12
%70 = load i64, i64* %19
%71 = getelementptr inbounds i8, i8* %69, i64 %70
%72 = load i8*, i8** %10
%73 = load i64, i64* %19
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%76 = call i32 @aegis256_enc_aut_step(i8* %71, i8* %74, i32* %75)
br label %77
77: ; preds = %68
%78 = load i64, i64* %19
%79 = add i64 %78, 16
store i64 %79, i64* %19
br label %63
80: ; preds = %63
%81 = load i64, i64* %13
%82 = and i64 %81, 15
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %107
84: ; preds = %80
%85 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%86 = call i32 @memset(i8* %85, i32 0, i32 16)
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%88 = load i8*, i8** %12
%89 = load i64, i64* %19
%90 = getelementptr inbounds i8, i8* %88, i64 %89
%91 = load i64, i64* %13
%92 = and i64 %91, 15
%93 = trunc i64 %92 to i32
%94 = call i32 @memcpy(i8* %87, i8* %90, i32 %93)
%95 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%96 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%97 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%98 = call i32 @aegis256_enc_aut_step(i8* %95, i8* %96, i32* %97)
%99 = load i8*, i8** %10
%100 = load i64, i64* %19
%101 = getelementptr inbounds i8, i8* %99, i64 %100
%102 = getelementptr inbounds [16 x i8], [16 x i8]* %21, i64 0, i64 0
%103 = load i64, i64* %13
%104 = and i64 %103, 15
%105 = trunc i64 %104 to i32
%106 = call i32 @memcpy(i8* %101, i8* %102, i32 %105)
br label %107
107: ; preds = %84, %80
%108 = load i64, i64* %13
%109 = load i64, i64* %15
%110 = getelementptr inbounds [16 x i8], [16 x i8]* %22, i64 0, i64 0
%111 = getelementptr inbounds [6 x i32], [6 x i32]* %23, i64 0, i64 0
%112 = call i32 @aegis256_tag_generation(i64 %108, i64 %109, i32 16, i8* %110, i32* %111)
%113 = load i64, i64* %13
%114 = add i64 %113, 16
%115 = load i64*, i64** %11
store i64 %114, i64* %115
%116 = load i8*, i8** %10
%117 = load i64, i64* %13
%118 = getelementptr inbounds i8, i8* %116, i64 %117
%119 = getelementptr inbounds [16 x i8], [16 x i8]* %22, i64 0, i64 0
%120 = call i32 @memcpy(i8* %118, i8* %119, i32 16)
ret i32 0
}

LLVM IR (-O2):
define i32 @crypto_aead_encrypt(i8* %0, i64* nocapture writeonly %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* nocapture readnone %6, i8* %7, i8* %8) {
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
%12 = alloca [16 x i8]
%13 = alloca [6 x i32]
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%17 = bitcast [6 x i32]* %13 to i8*
%18 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 0
%19 = call i32 @aegis256_initialization(i8* %8, i8* %7, i32* %18)
%20 = icmp ult i64 %5, 16
br i1 %20, label %28, label %21
21: ; preds = %9, %21
%22 = phi i64 [ %26, %21 ], [ 16, %9 ]
%23 = phi i64 [ %22, %21 ], [ 0, %9 ]
%24 = getelementptr inbounds i8, i8* %4, i64 %23
%25 = call i32 @aegis256_enc_aut_step(i8* %24, i8* %15, i32* %18)
%26 = add i64 %22, 16
%27 = icmp ugt i64 %26, %5
br i1 %27, label %28, label %21
28: ; preds = %21, %9
%29 = phi i64 [ 0, %9 ], [ %22, %21 ]
%30 = and i64 %5, 15
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %28
%33 = call i32 @memset(i8* %14, i32 0, i32 16)
%34 = getelementptr inbounds i8, i8* %4, i64 %29
%35 = trunc i64 %30 to i32
%36 = call i32 @memcpy(i8* %14, i8* %34, i32 %35)
%37 = call i32 @aegis256_enc_aut_step(i8* %14, i8* %15, i32* %18)
br label %38
38: ; preds = %32, %28
%39 = icmp ult i64 %3, 16
br i1 %39, label %48, label %40
40: ; preds = %38, %40
%41 = phi i64 [ %46, %40 ], [ 16, %38 ]
%42 = phi i64 [ %41, %40 ], [ 0, %38 ]
%43 = getelementptr inbounds i8, i8* %2, i64 %42
%44 = getelementptr inbounds i8, i8* %0, i64 %42
%45 = call i32 @aegis256_enc_aut_step(i8* %43, i8* %44, i32* %18)
%46 = add i64 %41, 16
%47 = icmp ugt i64 %46, %3
br i1 %47, label %48, label %40
48: ; preds = %40, %38
%49 = phi i64 [ 0, %38 ], [ %41, %40 ]
%50 = and i64 %3, 15
%51 = icmp eq i64 %50, 0
br i1 %51, label %60, label %52
52: ; preds = %48
%53 = call i32 @memset(i8* %14, i32 0, i32 16)
%54 = getelementptr inbounds i8, i8* %2, i64 %49
%55 = trunc i64 %50 to i32
%56 = call i32 @memcpy(i8* %14, i8* %54, i32 %55)
%57 = call i32 @aegis256_enc_aut_step(i8* %14, i8* %15, i32* %18)
%58 = getelementptr inbounds i8, i8* %0, i64 %49
%59 = call i32 @memcpy(i8* %58, i8* %15, i32 %55)
br label %60
60: ; preds = %52, %48
%61 = call i32 @aegis256_tag_generation(i64 %3, i64 %5, i32 16, i8* %16, i32* %18)
%62 = add i64 %3, 16
store i64 %62, i64* %1
%63 = getelementptr inbounds i8, i8* %0, i64 %3
%64 = call i32 @memcpy(i8* %63, i8* %16, i32 16)
ret i32 0
}