#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*/ chacha(unsigned char const *, unsigned char const *,
                          unsigned char const *, unsigned long long,
                          unsigned char *);
int /*<<< orphan*/ siphash24_mac(unsigned char *, unsigned char const *,
                                 unsigned char const *, unsigned char *,
                                 unsigned long long, unsigned char const *,
                                 unsigned long long);
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) {
  chacha(k, npub, m, mlen, c);
  siphash24_mac(c + mlen, k + 32, npub, c, mlen, ad, adlen);
  *clen = mlen + 8;
  return 0;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%r8
call   1040 <chacha@plt>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    0x20(%rbp),%rsi
add    $0x20,%rsi
mov    0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <siphash24_mac@plt>
mov    -0x20(%rbp),%rcx
add    $0x8,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x50(%rsp),%rbp
mov    0x48(%rsp),%rsi
mov    %rbp,%rdi
mov    %r13,%r8
call   1040 <chacha@plt>
lea    (%rbx,%r13,1),%rdi
add    $0x20,%rbp
mov    %r15,(%rsp)
mov    %rbp,%rsi
mov    0x48(%rsp),%rdx
mov    %r13,%rcx
mov    %rbx,%r8
mov    %r14,%r9
call   1030 <siphash24_mac@plt>
add    $0x8,%rbx
mov    %rbx,(%r12)
xor    %eax,%eax
add    $0x8,%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*
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
%19 = load i8*, i8** %18
%20 = load i8*, i8** %17
%21 = load i8*, i8** %12
%22 = load i64, i64* %13
%23 = load i8*, i8** %10
%24 = call i32 @chacha(i8* %19, i8* %20, i8* %21, i64 %22, i8* %23)
%25 = load i8*, i8** %10
%26 = load i64, i64* %13
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8*, i8** %18
%29 = getelementptr inbounds i8, i8* %28, i64 32
%30 = load i8*, i8** %17
%31 = load i8*, i8** %10
%32 = load i64, i64* %13
%33 = load i8*, i8** %14
%34 = load i64, i64* %15
%35 = call i32 @siphash24_mac(i8* %27, i8* %29, i8* %30, i8* %31, i64 %32, i8* %33, i64 %34)
%36 = load i64, i64* %13
%37 = add i64 %36, 8
%38 = load i64*, i64** %11
store i64 %37, i64* %38
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 = tail call i32 @chacha(i8* %8, i8* %7, i8* %2, i64 %3, i8* %0)
%11 = getelementptr inbounds i8, i8* %0, i64 %3
%12 = getelementptr inbounds i8, i8* %8, i64 32
%13 = tail call i32 @siphash24_mac(i8* %11, i8* %12, i8* %7, i8* %0, i64 %3, i8* %4, i64 %5)
%14 = add i64 %3, 8
store i64 %14, i64* %1
ret i32 0
}