#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*/ acorn128_enc_onebyte(unsigned char *, unsigned char const,
                                        unsigned char *, unsigned char *,
                                        unsigned char, unsigned char);
int /*<<< orphan*/ acorn128_initialization(unsigned char const *,
                                           unsigned char const *,
                                           unsigned char *);
int /*<<< orphan*/ acorn128_tag_generation(unsigned long long,
                                           unsigned long long, int,
                                           unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, 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 plaintextbyte, ciphertextbyte, ksbyte, mac[16];
  unsigned char state[293];
  unsigned char ca, cb;
  acorn128_initialization(k, npub, state);
  for (i = 0; i < adlen; i++) {
    acorn128_enc_onebyte(state, ad[i], &ciphertextbyte, &ksbyte, 0xff, 0xff);
  }
  for (i = 0; i < 256 / 8; i++) {
    if (i == 0)
      plaintextbyte = 0x1;
    else
      plaintextbyte = 0;
    if (i < 128 / 8)
      ca = 0xff;
    else
      ca = 0;
    cb = 0xff;
    acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca,
                         cb);
  }
  for (i = 0; i < mlen; i++) {
    acorn128_enc_onebyte(state, m[i], &(c[i]), &ksbyte, 0xff, 0);
  }
  for (i = 0; i < 256 / 8; i++) {
    if (i == 0)
      plaintextbyte = 0x1;
    else
      plaintextbyte = 0;
    if (i < 128 / 8)
      ca = 0xff;
    else
      ca = 0;
    cb = 0;
    acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca,
                         cb);
  }
  acorn128_tag_generation(mlen, adlen, 16, mac, state);
  *clen = mlen + 16;
  memcpy(c + mlen, mac, 16);
  return 0;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%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    -0x180(%rbp),%rdx
call   1060 <acorn128_initialization@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11d3 <crypto_aead_encrypt+0x93>
lea    -0x180(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rsi
lea    -0x3a(%rbp),%rdx
lea    -0x3b(%rbp),%rcx
mov    $0xff,%r9d
movzbl (%rax,%rsi,1),%esi
mov    %r9d,%r8d
call   1040 <acorn128_enc_onebyte@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    118b <crypto_aead_encrypt+0x4b>
movq   $0x0,-0x38(%rbp)
cmpq   $0x20,-0x38(%rbp)
jae    1262 <crypto_aead_encrypt+0x122>
cmpq   $0x0,-0x38(%rbp)
jne    11fa <crypto_aead_encrypt+0xba>
movb   $0x1,-0x39(%rbp)
jmp    11fe <crypto_aead_encrypt+0xbe>
movb   $0x0,-0x39(%rbp)
cmpq   $0x10,-0x38(%rbp)
jae    1215 <crypto_aead_encrypt+0xd5>
movb   $0xff,-0x181(%rbp)
jmp    121c <crypto_aead_encrypt+0xdc>
movb   $0x0,-0x181(%rbp)
movb   $0xff,-0x182(%rbp)
lea    -0x180(%rbp),%rdi
mov    -0x39(%rbp),%sil
mov    -0x181(%rbp),%al
lea    -0x3a(%rbp),%rdx
lea    -0x3b(%rbp),%rcx
movzbl %sil,%esi
movzbl %al,%r8d
movzbl -0x182(%rbp),%r9d
ff
call   1040 <acorn128_enc_onebyte@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11db <crypto_aead_encrypt+0x9b>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    12b8 <crypto_aead_encrypt+0x178>
lea    -0x180(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rdx
add    -0x38(%rbp),%rdx
lea    -0x3b(%rbp),%rcx
mov    $0xff,%r8d
xor    %r9d,%r9d
movzbl %al,%esi
call   1040 <acorn128_enc_onebyte@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    126a <crypto_aead_encrypt+0x12a>
movq   $0x0,-0x38(%rbp)
cmpq   $0x20,-0x38(%rbp)
jae    1347 <crypto_aead_encrypt+0x207>
cmpq   $0x0,-0x38(%rbp)
jne    12df <crypto_aead_encrypt+0x19f>
movb   $0x1,-0x39(%rbp)
jmp    12e3 <crypto_aead_encrypt+0x1a3>
movb   $0x0,-0x39(%rbp)
cmpq   $0x10,-0x38(%rbp)
jae    12fa <crypto_aead_encrypt+0x1ba>
movb   $0xff,-0x181(%rbp)
jmp    1301 <crypto_aead_encrypt+0x1c1>
movb   $0x0,-0x181(%rbp)
movb   $0x0,-0x182(%rbp)
lea    -0x180(%rbp),%rdi
mov    -0x39(%rbp),%sil
mov    -0x181(%rbp),%al
lea    -0x3a(%rbp),%rdx
lea    -0x3b(%rbp),%rcx
movzbl %sil,%esi
movzbl %al,%r8d
movzbl -0x182(%rbp),%r9d
ff
call   1040 <acorn128_enc_onebyte@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12c0 <crypto_aead_encrypt+0x180>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rcx
lea    -0x180(%rbp),%r8
mov    $0x10,%edx
call   1050 <acorn128_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    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
mov    %r9,%r14
mov    %r8,%rbp
mov    %rcx,0x28(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,0x20(%rsp)
mov    0x1b0(%rsp),%rdi
mov    0x1a8(%rsp),%rsi
lea    0x40(%rsp),%rdx
call   1060 <acorn128_initialization@plt>
test   %r14,%r14
je     11c9 <crypto_aead_encrypt+0x89>
xor    %r13d,%r13d
lea    0x40(%rsp),%r15
lea    0x7(%rsp),%r12
lea    0x6(%rsp),%rbx
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r13,1),%esi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    $0xff,%r8d
mov    $0xff,%r9d
call   1040 <acorn128_enc_onebyte@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11a0 <crypto_aead_encrypt+0x60>
mov    %r14,0x10(%rsp)
xor    %ebx,%ebx
lea    0x40(%rsp),%rbp
lea    0x7(%rsp),%r15
lea    0x6(%rsp),%r12
nop
xor    %esi,%esi
test   %rbx,%rbx
sete   %sil
cmp    $0x10,%rbx
sbb    %eax,%eax
movzbl %al,%r8d
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    $0xff,%r9d
call   1040 <acorn128_enc_onebyte@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    11e0 <crypto_aead_encrypt+0xa0>
mov    0x28(%rsp),%r12
test   %r12,%r12
mov    0x20(%rsp),%r13
mov    0x8(%rsp),%rbp
je     1266 <crypto_aead_encrypt+0x126>
xor    %ebx,%ebx
lea    0x40(%rsp),%r15
lea    0x6(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rbx,1),%esi
lea    (%rbx,%r13,1),%rdx
mov    %r15,%rdi
mov    %r14,%rcx
mov    $0xff,%r8d
xor    %r9d,%r9d
call   1040 <acorn128_enc_onebyte@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1240 <crypto_aead_encrypt+0x100>
xor    %ebp,%ebp
lea    0x40(%rsp),%r15
lea    0x7(%rsp),%r14
lea    0x6(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
test   %rbp,%rbp
sete   %sil
cmp    $0x10,%rbp
sbb    %eax,%eax
movzbl %al,%r8d
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %r9d,%r9d
call   1040 <acorn128_enc_onebyte@plt>
add    $0x1,%rbp
cmp    $0x20,%rbp
jne    1280 <crypto_aead_encrypt+0x140>
lea    0x30(%rsp),%rbx
lea    0x40(%rsp),%r8
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    $0x10,%edx
mov    %rbx,%rcx
call   1050 <acorn128_tag_generation@plt>
lea    0x10(%r12),%rax
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
add    %r12,%r13
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
add    $0x168,%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 i8
%21 = alloca i8
%22 = alloca i8
%23 = alloca [16 x i8]
%24 = alloca [293 x i8]
%25 = alloca i8
%26 = alloca 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
%27 = load i8*, i8** %18
%28 = load i8*, i8** %17
%29 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%30 = call i32 @acorn128_initialization(i8* %27, i8* %28, i8* %29)
store i64 0, i64* %19
br label %31
31: ; preds = %42, %9
%32 = load i64, i64* %19
%33 = load i64, i64* %15
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%37 = load i8*, i8** %14
%38 = load i64, i64* %19
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @acorn128_enc_onebyte(i8* %36, i8 zeroext %40, i8* %21, i8* %22, i8 zeroext -1, i8 zeroext -1)
br label %42
42: ; preds = %35
%43 = load i64, i64* %19
%44 = add i64 %43, 1
store i64 %44, i64* %19
br label %31
45: ; preds = %31
store i64 0, i64* %19
br label %46
46: ; preds = %65, %45
%47 = load i64, i64* %19
%48 = icmp ult i64 %47, 32
br i1 %48, label %49, label %68
49: ; preds = %46
%50 = load i64, i64* %19
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
store i8 1, i8* %20
br label %54
53: ; preds = %49
store i8 0, i8* %20
br label %54
54: ; preds = %53, %52
%55 = load i64, i64* %19
%56 = icmp ult i64 %55, 16
br i1 %56, label %57, label %58
57: ; preds = %54
store i8 -1, i8* %25
br label %59
58: ; preds = %54
store i8 0, i8* %25
br label %59
59: ; preds = %58, %57
store i8 -1, i8* %26
%60 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%61 = load i8, i8* %20
%62 = load i8, i8* %25
%63 = load i8, i8* %26
%64 = call i32 @acorn128_enc_onebyte(i8* %60, i8 zeroext %61, i8* %21, i8* %22, i8 zeroext %62, i8 zeroext %63)
br label %65
65: ; preds = %59
%66 = load i64, i64* %19
%67 = add i64 %66, 1
store i64 %67, i64* %19
br label %46
68: ; preds = %46
store i64 0, i64* %19
br label %69
69: ; preds = %83, %68
%70 = load i64, i64* %19
%71 = load i64, i64* %13
%72 = icmp ult i64 %70, %71
br i1 %72, label %73, label %86
73: ; preds = %69
%74 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%75 = load i8*, i8** %12
%76 = load i64, i64* %19
%77 = getelementptr inbounds i8, i8* %75, i64 %76
%78 = load i8, i8* %77
%79 = load i8*, i8** %10
%80 = load i64, i64* %19
%81 = getelementptr inbounds i8, i8* %79, i64 %80
%82 = call i32 @acorn128_enc_onebyte(i8* %74, i8 zeroext %78, i8* %81, i8* %22, i8 zeroext -1, i8 zeroext 0)
br label %83
83: ; preds = %73
%84 = load i64, i64* %19
%85 = add i64 %84, 1
store i64 %85, i64* %19
br label %69
86: ; preds = %69
store i64 0, i64* %19
br label %87
87: ; preds = %106, %86
%88 = load i64, i64* %19
%89 = icmp ult i64 %88, 32
br i1 %89, label %90, label %109
90: ; preds = %87
%91 = load i64, i64* %19
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %90
store i8 1, i8* %20
br label %95
94: ; preds = %90
store i8 0, i8* %20
br label %95
95: ; preds = %94, %93
%96 = load i64, i64* %19
%97 = icmp ult i64 %96, 16
br i1 %97, label %98, label %99
98: ; preds = %95
store i8 -1, i8* %25
br label %100
99: ; preds = %95
store i8 0, i8* %25
br label %100
100: ; preds = %99, %98
store i8 0, i8* %26
%101 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%102 = load i8, i8* %20
%103 = load i8, i8* %25
%104 = load i8, i8* %26
%105 = call i32 @acorn128_enc_onebyte(i8* %101, i8 zeroext %102, i8* %21, i8* %22, i8 zeroext %103, i8 zeroext %104)
br label %106
106: ; preds = %100
%107 = load i64, i64* %19
%108 = add i64 %107, 1
store i64 %108, i64* %19
br label %87
109: ; preds = %87
%110 = load i64, i64* %13
%111 = load i64, i64* %15
%112 = getelementptr inbounds [16 x i8], [16 x i8]* %23, i64 0, i64 0
%113 = getelementptr inbounds [293 x i8], [293 x i8]* %24, i64 0, i64 0
%114 = call i32 @acorn128_tag_generation(i64 %110, i64 %111, i32 16, i8* %112, i8* %113)
%115 = load i64, i64* %13
%116 = add i64 %115, 16
%117 = load i64*, i64** %11
store i64 %116, i64* %117
%118 = load i8*, i8** %10
%119 = load i64, i64* %13
%120 = getelementptr inbounds i8, i8* %118, i64 %119
%121 = getelementptr inbounds [16 x i8], [16 x i8]* %23, i64 0, i64 0
%122 = call i32 @memcpy(i8* %120, i8* %121, i32 16)
ret i32 0
}

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