#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*/ AESKeySteup(unsigned char const *, unsigned int *);
int /*<<< orphan*/ jambu_aut_ad_full(unsigned int *, unsigned int *,
                                     unsigned int *);
int /*<<< orphan*/ jambu_aut_ad_partial(unsigned int *, unsigned char const *,
                                        unsigned int *, unsigned int *,
                                        unsigned long long);
int /*<<< orphan*/ jambu_aut_ad_step(unsigned int *, unsigned char const *,
                                     unsigned int *, unsigned int *);
int /*<<< orphan*/ jambu_enc_aut_msg_full(unsigned int *, unsigned int *,
                                          unsigned int *);
int /*<<< orphan*/ jambu_enc_aut_msg_partial(unsigned int *,
                                             unsigned char const *,
                                             unsigned char *, unsigned int *,
                                             unsigned int *,
                                             unsigned long long);
int /*<<< orphan*/ jambu_enc_aut_msg_step(unsigned int *, unsigned char const *,
                                          unsigned char *, unsigned int *,
                                          unsigned int *);
int /*<<< orphan*/ jambu_initialization(unsigned int *, unsigned char const *,
                                        unsigned int *, unsigned int *);
int /*<<< orphan*/ jambu_tag_generation(unsigned int *, unsigned long long,
                                        unsigned char *, unsigned int *,
                                        unsigned int *);
int /*<<< orphan*/ memset(unsigned int *, 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 int i;
  unsigned int jambu_state[4];
  unsigned int stateR[2];
  unsigned int EK[44];
  AESKeySteup(k, EK);
  memset(jambu_state, 0, 16);
  memset(stateR, 0, 8);
  jambu_initialization(EK, npub, jambu_state, stateR);
  for (i = 0; (i + 8) <= adlen; i += 8) {
    jambu_aut_ad_step(EK, ad + i, jambu_state, stateR);
  }
  if ((adlen & 0x7) != 0) {
    jambu_aut_ad_partial(EK, ad + i, jambu_state, stateR, adlen & 0x7);
  } else {
    jambu_aut_ad_full(EK, jambu_state, stateR);
  }
  for (i = 0; (i + 8) <= mlen; i += 8) {
    jambu_enc_aut_msg_step(EK, m + i, c + i, jambu_state, stateR);
  }
  if ((mlen & 0x7) != 0) {
    jambu_enc_aut_msg_partial(EK, m + i, c + i, jambu_state, stateR,
                              mlen & 0x7);
  } else {
    jambu_enc_aut_msg_full(EK, jambu_state, stateR);
  }
  jambu_tag_generation(EK, mlen, c, jambu_state, stateR);
  *clen = mlen + 8;
  return 0;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%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
lea    -0x110(%rbp),%rsi
call   1090 <AESKeySteup@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1030 <jambu_initialization@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x8,%eax
mov    %eax,%eax
cmp    -0x30(%rbp),%rax
ja     125c <crypto_aead_encrypt+0xbc>
lea    -0x110(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1080 <jambu_aut_ad_step@plt>
mov    -0x34(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x34(%rbp)
jmp    121e <crypto_aead_encrypt+0x7e>
mov    -0x30(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     1299 <crypto_aead_encrypt+0xf9>
lea    -0x110(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
mov    -0x30(%rbp),%r8
and    $0x7,%r8
call   10a0 <jambu_aut_ad_partial@plt>
jmp    12ad <crypto_aead_encrypt+0x10d>
lea    -0x110(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1050 <jambu_aut_ad_full@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x8,%eax
mov    %eax,%eax
cmp    -0x20(%rbp),%rax
ja     12fc <crypto_aead_encrypt+0x15c>
lea    -0x110(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
mov    -0x34(%rbp),%eax
add    %rax,%rdx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1040 <jambu_enc_aut_msg_step@plt>
mov    -0x34(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x34(%rbp)
jmp    12b4 <crypto_aead_encrypt+0x114>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     1343 <crypto_aead_encrypt+0x1a3>
lea    -0x110(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
mov    -0x34(%rbp),%eax
add    %rax,%rdx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%r8
mov    -0x20(%rbp),%r9
and    $0x7,%r9
call   1070 <jambu_enc_aut_msg_partial@plt>
jmp    1357 <crypto_aead_encrypt+0x1b7>
lea    -0x110(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   10b0 <jambu_enc_aut_msg_full@plt>
lea    -0x110(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   10c0 <jambu_tag_generation@plt>
mov    -0x20(%rbp),%rcx
add    $0x8,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %r9,%rbx
mov    %r8,%rbp
mov    %rcx,0x30(%rsp)
mov    %rdx,%r14
mov    %rsi,0x38(%rsp)
mov    %rdi,0x28(%rsp)
mov    0x140(%rsp),%rdi
lea    0x40(%rsp),%rsi
call   1090 <AESKeySteup@plt>
lea    0x10(%rsp),%r12
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    0x40(%rsp),%rdi
mov    0x138(%rsp),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1030 <jambu_initialization@plt>
cmp    $0x8,%rbx
jb     1263 <crypto_aead_encrypt+0xc3>
xor    %r13d,%r13d
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13d,%esi
add    %rbp,%rsi
lea    0x40(%rsp),%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <jambu_aut_ad_step@plt>
lea    0x10(%r13),%eax
add    $0x8,%r13d
cmp    %rbx,%rax
jbe    1240 <crypto_aead_encrypt+0xa0>
and    $0x7,%rbx
je     128b <crypto_aead_encrypt+0xeb>
mov    %r13d,%eax
add    %rax,%rbp
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbp,%rsi
mov    %rbx,%r8
call   10a0 <jambu_aut_ad_partial@plt>
jmp    129f <crypto_aead_encrypt+0xff>
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <jambu_aut_ad_full@plt>
mov    0x30(%rsp),%rbx
mov    0x28(%rsp),%r13
xor    %ebp,%ebp
cmp    $0x8,%rbx
mov    %r14,%rsi
jb     12e7 <crypto_aead_encrypt+0x147>
xor    %ebp,%ebp
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %ebp,%edx
lea    (%r14,%rdx,1),%rsi
add    %r13,%rdx
lea    0x40(%rsp),%rdi
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <jambu_enc_aut_msg_step@plt>
mov    %r14,%rsi
lea    0x10(%rbp),%eax
add    $0x8,%ebp
cmp    %rbx,%rax
jbe    12c0 <crypto_aead_encrypt+0x120>
mov    %rbx,%r9
and    $0x7,%r9
je     130e <crypto_aead_encrypt+0x16e>
mov    %ebp,%edx
add    %rdx,%rsi
add    %r13,%rdx
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1070 <jambu_enc_aut_msg_partial@plt>
jmp    1322 <crypto_aead_encrypt+0x182>
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10b0 <jambu_enc_aut_msg_full@plt>
lea    0x40(%rsp),%rdi
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
mov    %r13,%rdx
call   10c0 <jambu_tag_generation@plt>
add    $0x8,%rbx
mov    0x38(%rsp),%rax
mov    %rbx,(%rax)
xor    %eax,%eax
add    $0xf8,%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 i32
%20 = alloca [4 x i32]
%21 = alloca [2 x i32]
%22 = alloca [44 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
%23 = load i8*, i8** %18
%24 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%25 = call i32 @AESKeySteup(i8* %23, i32* %24)
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%27 = call i32 @memset(i32* %26, i32 0, i32 16)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%29 = call i32 @memset(i32* %28, i32 0, i32 8)
%30 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%31 = load i8*, i8** %17
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%34 = call i32 @jambu_initialization(i32* %30, i8* %31, i32* %32, i32* %33)
store i32 0, i32* %19
br label %35
35: ; preds = %50, %9
%36 = load i32, i32* %19
%37 = add i32 %36, 8
%38 = zext i32 %37 to i64
%39 = load i64, i64* %15
%40 = icmp ule i64 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %35
%42 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%43 = load i8*, i8** %14
%44 = load i32, i32* %19
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%49 = call i32 @jambu_aut_ad_step(i32* %42, i8* %46, i32* %47, i32* %48)
br label %50
50: ; preds = %41
%51 = load i32, i32* %19
%52 = add i32 %51, 8
store i32 %52, i32* %19
br label %35
53: ; preds = %35
%54 = load i64, i64* %15
%55 = and i64 %54, 7
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%59 = load i8*, i8** %14
%60 = load i32, i32* %19
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%65 = load i64, i64* %15
%66 = and i64 %65, 7
%67 = call i32 @jambu_aut_ad_partial(i32* %58, i8* %62, i32* %63, i32* %64, i64 %66)
br label %73
68: ; preds = %53
%69 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%70 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%72 = call i32 @jambu_aut_ad_full(i32* %69, i32* %70, i32* %71)
br label %73
73: ; preds = %68, %57
store i32 0, i32* %19
br label %74
74: ; preds = %93, %73
%75 = load i32, i32* %19
%76 = add i32 %75, 8
%77 = zext i32 %76 to i64
%78 = load i64, i64* %13
%79 = icmp ule i64 %77, %78
br i1 %79, label %80, label %96
80: ; preds = %74
%81 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%82 = load i8*, i8** %12
%83 = load i32, i32* %19
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8*, i8** %10
%87 = load i32, i32* %19
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%92 = call i32 @jambu_enc_aut_msg_step(i32* %81, i8* %85, i8* %89, i32* %90, i32* %91)
br label %93
93: ; preds = %80
%94 = load i32, i32* %19
%95 = add i32 %94, 8
store i32 %95, i32* %19
br label %74
96: ; preds = %74
%97 = load i64, i64* %13
%98 = and i64 %97, 7
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %115
100: ; preds = %96
%101 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%102 = load i8*, i8** %12
%103 = load i32, i32* %19
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %102, i64 %104
%106 = load i8*, i8** %10
%107 = load i32, i32* %19
%108 = zext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %106, i64 %108
%110 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%112 = load i64, i64* %13
%113 = and i64 %112, 7
%114 = call i32 @jambu_enc_aut_msg_partial(i32* %101, i8* %105, i8* %109, i32* %110, i32* %111, i64 %113)
br label %120
115: ; preds = %96
%116 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%117 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%119 = call i32 @jambu_enc_aut_msg_full(i32* %116, i32* %117, i32* %118)
br label %120
120: ; preds = %115, %100
%121 = getelementptr inbounds [44 x i32], [44 x i32]* %22, i64 0, i64 0
%122 = load i64, i64* %13
%123 = load i8*, i8** %10
%124 = getelementptr inbounds [4 x i32], [4 x i32]* %20, i64 0, i64 0
%125 = getelementptr inbounds [2 x i32], [2 x i32]* %21, i64 0, i64 0
%126 = call i32 @jambu_tag_generation(i32* %121, i64 %122, i8* %123, i32* %124, i32* %125)
%127 = load i64, i64* %13
%128 = add i64 %127, 8
%129 = load i64*, i64** %11
store i64 %128, i64* %129
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 [4 x i32]
%11 = alloca [2 x i32]
%12 = alloca [44 x i32]
%13 = bitcast [4 x i32]* %10 to i8*
%14 = bitcast [2 x i32]* %11 to i8*
%15 = bitcast [44 x i32]* %12 to i8*
%16 = getelementptr inbounds [44 x i32], [44 x i32]* %12, i64 0, i64 0
%17 = call i32 @AESKeySteup(i8* %8, i32* %16)
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%19 = call i32 @memset(i32* %18, i32 0, i32 16)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%21 = call i32 @memset(i32* %20, i32 0, i32 8)
%22 = call i32 @jambu_initialization(i32* %16, i8* %7, i32* %18, i32* %20)
%23 = icmp ult i64 %5, 8
br i1 %23, label %33, label %24
24: ; preds = %9, %24
%25 = phi i32 [ %30, %24 ], [ 8, %9 ]
%26 = phi i32 [ %25, %24 ], [ 0, %9 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %4, i64 %27
%29 = call i32 @jambu_aut_ad_step(i32* %16, i8* %28, i32* %18, i32* %20)
%30 = add i32 %25, 8
%31 = zext i32 %30 to i64
%32 = icmp ugt i64 %31, %5
br i1 %32, label %33, label %24
33: ; preds = %24, %9
%34 = phi i32 [ 0, %9 ], [ %25, %24 ]
%35 = and i64 %5, 7
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = zext i32 %34 to i64
%39 = getelementptr inbounds i8, i8* %4, i64 %38
%40 = call i32 @jambu_aut_ad_partial(i32* %16, i8* %39, i32* %18, i32* %20, i64 %35)
br label %43
41: ; preds = %33
%42 = call i32 @jambu_aut_ad_full(i32* %16, i32* %18, i32* %20)
br label %43
43: ; preds = %41, %37
%44 = icmp ult i64 %3, 8
br i1 %44, label %55, label %45
45: ; preds = %43, %45
%46 = phi i32 [ %52, %45 ], [ 8, %43 ]
%47 = phi i32 [ %46, %45 ], [ 0, %43 ]
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %2, i64 %48
%50 = getelementptr inbounds i8, i8* %0, i64 %48
%51 = call i32 @jambu_enc_aut_msg_step(i32* %16, i8* %49, i8* %50, i32* %18, i32* %20)
%52 = add i32 %46, 8
%53 = zext i32 %52 to i64
%54 = icmp ugt i64 %53, %3
br i1 %54, label %55, label %45
55: ; preds = %45, %43
%56 = phi i32 [ 0, %43 ], [ %46, %45 ]
%57 = and i64 %3, 7
%58 = icmp eq i64 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %55
%60 = zext i32 %56 to i64
%61 = getelementptr inbounds i8, i8* %2, i64 %60
%62 = getelementptr inbounds i8, i8* %0, i64 %60
%63 = call i32 @jambu_enc_aut_msg_partial(i32* %16, i8* %61, i8* %62, i32* %18, i32* %20, i64 %57)
br label %66
64: ; preds = %55
%65 = call i32 @jambu_enc_aut_msg_full(i32* %16, i32* %18, i32* %20)
br label %66
66: ; preds = %64, %59
%67 = call i32 @jambu_tag_generation(i32* %16, i64 %3, i8* %0, i32* %18, i32* %20)
%68 = add i64 %3, 8
store i64 %68, i64* %1
ret i32 0
}