#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 */

/* Variables and functions */
int /*<<< orphan*/ aegis256_enc_aut_step(unsigned char const *, unsigned char *,
                                         unsigned char *);
int /*<<< orphan*/ aegis256_initialization(unsigned char const *,
                                           unsigned char const *,
                                           unsigned char *);
int /*<<< orphan*/ aegis256_tag_generation(unsigned long long,
                                           unsigned long long, int,
                                           unsigned char *, unsigned char *);
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 i;
  unsigned char plaintextblock[16], ciphertextblock[16], mac[16];
  unsigned char aegis256_state[96];
  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    $0xd0,%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    -0xd0(%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    -0xd0(%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    -0xd0(%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    -0xd0(%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    -0xd0(%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    -0xd0(%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    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rcx,0x18(%rsp)
mov    %rdx,%r15
mov    %rsi,0x10(%rsp)
mov    %rdi,(%rsp)
mov    0x100(%rsp),%rdi
mov    0xf8(%rsp),%rsi
lea    0x40(%rsp),%rdx
call   1050 <aegis256_initialization@plt>
cmp    $0x10,%rbx
mov    %rbx,0x8(%rsp)
jae    11a5 <crypto_aead_encrypt+0x55>
mov    %rbx,%rax
xor    %r13d,%r13d
jmp    11e5 <crypto_aead_encrypt+0x95>
xor    %r12d,%r12d
lea    0x20(%rsp),%rbx
lea    0x40(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
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    11c0 <crypto_aead_encrypt+0x70>
mov    %rax,%rbx
and    $0xf,%rbx
je     1224 <crypto_aead_encrypt+0xd4>
lea    0x30(%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    0x20(%rsp),%rsi
lea    0x40(%rsp),%rdx
mov    %r14,%rdi
call   1070 <aegis256_enc_aut_step@plt>
mov    0x18(%rsp),%r12
cmp    $0x10,%r12
jae    1237 <crypto_aead_encrypt+0xe7>
xor    %ebx,%ebx
mov    (%rsp),%r13
jmp    1272 <crypto_aead_encrypt+0x122>
xor    %ebp,%ebp
lea    0x40(%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    1250 <crypto_aead_encrypt+0x100>
mov    %r12,%rbp
and    $0xf,%rbp
je     12c4 <crypto_aead_encrypt+0x174>
lea    0x30(%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    0x20(%rsp),%r15
lea    0x40(%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    0xa0(%rsp),%rbx
lea    0x40(%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    0x10(%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    $0xb8,%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 [96 x i8]
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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%27 = call i32 @aegis256_initialization(i8* %24, i8* %25, i8* %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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%39 = call i32 @aegis256_enc_aut_step(i8* %36, i8* %37, i8* %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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%61 = call i32 @aegis256_enc_aut_step(i8* %58, i8* %59, i8* %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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%76 = call i32 @aegis256_enc_aut_step(i8* %71, i8* %74, i8* %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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%98 = call i32 @aegis256_enc_aut_step(i8* %95, i8* %96, i8* %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 [96 x i8], [96 x i8]* %23, i64 0, i64 0
%112 = call i32 @aegis256_tag_generation(i64 %108, i64 %109, i32 16, i8* %110, i8* %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 [96 x i8]
%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 = getelementptr inbounds [96 x i8], [96 x i8]* %13, i64 0, i64 0
%18 = call i32 @aegis256_initialization(i8* %8, i8* %7, i8* %17)
%19 = icmp ult i64 %5, 16
br i1 %19, label %27, label %20
20: ; preds = %9, %20
%21 = phi i64 [ %25, %20 ], [ 16, %9 ]
%22 = phi i64 [ %21, %20 ], [ 0, %9 ]
%23 = getelementptr inbounds i8, i8* %4, i64 %22
%24 = call i32 @aegis256_enc_aut_step(i8* %23, i8* %15, i8* %17)
%25 = add i64 %21, 16
%26 = icmp ugt i64 %25, %5
br i1 %26, label %27, label %20
27: ; preds = %20, %9
%28 = phi i64 [ 0, %9 ], [ %21, %20 ]
%29 = and i64 %5, 15
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = call i32 @memset(i8* %14, i32 0, i32 16)
%33 = getelementptr inbounds i8, i8* %4, i64 %28
%34 = trunc i64 %29 to i32
%35 = call i32 @memcpy(i8* %14, i8* %33, i32 %34)
%36 = call i32 @aegis256_enc_aut_step(i8* %14, i8* %15, i8* %17)
br label %37
37: ; preds = %31, %27
%38 = icmp ult i64 %3, 16
br i1 %38, label %47, label %39
39: ; preds = %37, %39
%40 = phi i64 [ %45, %39 ], [ 16, %37 ]
%41 = phi i64 [ %40, %39 ], [ 0, %37 ]
%42 = getelementptr inbounds i8, i8* %2, i64 %41
%43 = getelementptr inbounds i8, i8* %0, i64 %41
%44 = call i32 @aegis256_enc_aut_step(i8* %42, i8* %43, i8* %17)
%45 = add i64 %40, 16
%46 = icmp ugt i64 %45, %3
br i1 %46, label %47, label %39
47: ; preds = %39, %37
%48 = phi i64 [ 0, %37 ], [ %40, %39 ]
%49 = and i64 %3, 15
%50 = icmp eq i64 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %47
%52 = call i32 @memset(i8* %14, i32 0, i32 16)
%53 = getelementptr inbounds i8, i8* %2, i64 %48
%54 = trunc i64 %49 to i32
%55 = call i32 @memcpy(i8* %14, i8* %53, i32 %54)
%56 = call i32 @aegis256_enc_aut_step(i8* %14, i8* %15, i8* %17)
%57 = getelementptr inbounds i8, i8* %0, i64 %48
%58 = call i32 @memcpy(i8* %57, i8* %15, i32 %54)
br label %59
59: ; preds = %51, %47
%60 = call i32 @aegis256_tag_generation(i64 %3, i64 %5, i32 16, i8* %16, i8* %17)
%61 = add i64 %3, 16
store i64 %61, i64* %1
%62 = getelementptr inbounds i8, i8* %0, i64 %3
%63 = call i32 @memcpy(i8* %62, i8* %16, i32 16)
ret i32 0
}