#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 jhae_encryption_authentication(unsigned char *, unsigned long long *,
                                   unsigned char *, unsigned char const *,
                                   unsigned char const *, unsigned char const *,
                                   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) {
  int ret, i;
  unsigned char tag[32];
  ret =
      jhae_encryption_authentication(c, clen, tag, k, npub, m, mlen, ad, adlen);
  if (ret != 0)
    return ret;
  for (i = 0; i < 32; i++)
    c[*clen + i] = tag[i];
  *clen += 32;
  return ret;
}


x86 assembly (clang, -O0):
<crypto_aead_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    0x20(%rbp),%rcx
mov    0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%r11
mov    -0x30(%rbp),%r10
mov    -0x38(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <jhae_encryption_authentication@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     118e <crypto_aead_encrypt+0x7e>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <crypto_aead_encrypt+0xce>
movl   $0x0,-0x40(%rbp)
cmpl   $0x20,-0x40(%rbp)
jge    11ca <crypto_aead_encrypt+0xba>
movslq -0x40(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
movslq -0x40(%rbp),%rsi
add    %rsi,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1195 <crypto_aead_encrypt+0x85>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x20,%rcx
mov    %rcx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aead_encrypt>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rax
mov    %r8,%r10
mov    %rcx,%r11
mov    %rdx,%r9
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x50(%rsp),%rcx
mov    0x48(%rsp),%r8
sub    $0x8,%rsp
lea    0x8(%rsp),%rdx
push   %rax
push   %r10
push   %r11
call   1030 <jhae_encryption_authentication@plt>
add    $0x20,%rsp
test   %eax,%eax
jne    11a0 <crypto_aead_encrypt+0x90>
lea    0x3(%rsp),%rcx
mov    $0x20,%edx
nopl   0x0(%rax,%rax,1)
movzbl -0x3(%rcx),%esi
mov    (%r14),%rdi
mov    %sil,(%rbx,%rdi,1)
movzbl -0x2(%rcx),%esi
mov    (%r14),%rdi
mov    %sil,0x1(%rdi,%rbx,1)
movzbl -0x1(%rcx),%esi
mov    (%r14),%rdi
mov    %sil,0x2(%rdi,%rbx,1)
movzbl (%rcx),%esi
mov    (%r14),%rdi
mov    %sil,0x3(%rdi,%rbx,1)
add    $0x4,%rcx
add    $0x4,%rbx
add    $0xfffffffffffffffc,%rdx
jne    1160 <crypto_aead_encrypt+0x50>
addq   $0x20,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
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 i32
%11 = alloca i8*
%12 = alloca i64*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca [32 x i8]
store i8* %0, i8** %11
store i64* %1, i64** %12
store i8* %2, i8** %13
store i64 %3, i64* %14
store i8* %4, i8** %15
store i64 %5, i64* %16
store i8* %6, i8** %17
store i8* %7, i8** %18
store i8* %8, i8** %19
%23 = load i8*, i8** %11
%24 = load i64*, i64** %12
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %22, i64 0, i64 0
%26 = load i8*, i8** %19
%27 = load i8*, i8** %18
%28 = load i8*, i8** %13
%29 = load i64, i64* %14
%30 = load i8*, i8** %15
%31 = load i64, i64* %16
%32 = call i32 @jhae_encryption_authentication(i8* %23, i64* %24, i8* %25, i8* %26, i8* %27, i8* %28, i64 %29, i8* %30, i64 %31)
store i32 %32, i32* %20
%33 = load i32, i32* %20
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %9
%36 = load i32, i32* %20
store i32 %36, i32* %10
br label %61
37: ; preds = %9
store i32 0, i32* %21
br label %38
38: ; preds = %53, %37
%39 = load i32, i32* %21
%40 = icmp slt i32 %39, 32
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = load i32, i32* %21
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %22, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = load i8*, i8** %11
%47 = load i64*, i64** %12
%48 = load i64, i64* %47
%49 = load i32, i32* %21
%50 = sext i32 %49 to i64
%51 = add i64 %48, %50
%52 = getelementptr inbounds i8, i8* %46, i64 %51
store i8 %45, i8* %52
br label %53
53: ; preds = %41
%54 = load i32, i32* %21
%55 = add nsw i32 %54, 1
store i32 %55, i32* %21
br label %38
56: ; preds = %38
%57 = load i64*, i64** %12
%58 = load i64, i64* %57
%59 = add i64 %58, 32
store i64 %59, i64* %57
%60 = load i32, i32* %20
store i32 %60, i32* %10
br label %61
61: ; preds = %56, %35
%62 = load i32, i32* %10
ret i32 %62
}

LLVM IR (-O2):
define i32 @crypto_aead_encrypt(i8* %0, i64* %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* nocapture readnone %6, i8* %7, i8* %8) {
%10 = alloca [32 x i8]
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%12 = call i32 @jhae_encryption_authentication(i8* %0, i64* %1, i8* %11, i8* %8, i8* %7, i8* %2, i64 %3, i8* %4, i64 %5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %44
14: ; preds = %9, %14
%15 = phi i64 [ %39, %14 ], [ 0, %9 ]
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = load i64, i64* %1
%19 = add i64 %18, %15
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 %17, i8* %20
%21 = or i64 %15, 1
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i64, i64* %1
%25 = add i64 %24, %21
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 %23, i8* %26
%27 = or i64 %15, 2
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i64, i64* %1
%31 = add i64 %30, %27
%32 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 %29, i8* %32
%33 = or i64 %15, 3
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = load i64, i64* %1
%37 = add i64 %36, %33
%38 = getelementptr inbounds i8, i8* %0, i64 %37
store i8 %35, i8* %38
%39 = add nuw nsw i64 %15, 4
%40 = icmp eq i64 %39, 32
br i1 %40, label %41, label %14
41: ; preds = %14
%42 = load i64, i64* %1
%43 = add i64 %42, 32
store i64 %43, i64* %1
br label %44
44: ; preds = %9, %41
ret i32 %12
}